31 if ( is_null( self::$_instance ) ) {
32 self::$_instance =
new self();
35 return self::$_instance;
46 add_filter(
'pre_set_site_transient_update_plugins', [ $this,
'check_for_product_updates' ] );
47 add_filter(
'plugins_api', [ $this,
'display_product_information' ], 10, 3 );
48 add_filter(
'admin_init', [ $this,
'disable_legacy_edd_updater' ], 999 );
61 $filters_to_remove = [
'pre_set_site_transient_update_plugins',
'plugins_api',
'after_plugin_row',
'admin_init' ];
63 $legacy_edd_check =
function () {
64 return isset( $this->api_url ) && preg_match(
'/gravity(view|kit)\.com?/', $this->api_url );
67 $remove_filter =
function ( $filter ) use ( $wp_filter, $legacy_edd_check ) {
68 if ( empty( $wp_filter[ $filter ]->callbacks ) ) {
72 foreach ( $wp_filter[ $filter ]->callbacks as &$callback ) {
73 foreach ( $callback as $key => &$hook ) {
74 if ( ! is_array( $hook[
'function'] ) || ! is_object( $hook[
'function'][0] ) ) {
79 $is_legacy_edd = $legacy_edd_check->bindTo( $hook[
'function'][0], get_class( $hook[
'function'][0] ) );
81 if ( ! $is_legacy_edd() ) {
85 unset( $callback[ $key ] );
90 foreach ( array_keys( $wp_filter ) as $filter ) {
91 foreach ( $filters_to_remove as $filter_to_remove ) {
93 if ( strpos( $filter, $filter_to_remove ) !==
false ) {
94 $remove_filter( $filter );
113 if ( ! is_object( $transient_data ) ) {
114 $transient_data = new \stdClass();
117 if ( ! $checked && ! $skip_cache &&
Arr::get( $_GET,
'force-check',
false ) ) {
124 LoggerFramework::get_instance()->error(
"Can't get products data when checking for updated versions: " . $e->getMessage() );
126 return $transient_data;
129 foreach ( $products_data as $path => $product ) {
130 if ( !
Arr::get( $product,
'installed' ) ) {
136 if ( $product[
'update_available'] ) {
137 $transient_data->response[ $path ] = $wp_product_data;
139 $transient_data->no_update[ $path ] = $wp_product_data;
142 $transient_data->checked[ $path ] =
Arr::get( $product,
'installed_version' );
145 $transient_data->last_checked = time();
149 return $transient_data;
167 $license =
Arr::get( $product,
'licenses.0' );
169 $download_link =
Arr::get( $licenses_data,
"{$license}.products.{$product['id']}.download" );
172 'plugin' =>
Arr::get( $product,
'path' ),
173 'name' =>
Arr::get( $product,
'title' ),
175 'slug' =>
Arr::get( $product,
'slug' ),
176 'version' =>
Arr::get( $product,
'server_version' ),
177 'new_version' =>
Arr::get( $product,
'server_version' ),
178 'url' =>
Arr::get( $product,
'link' ),
179 'homepage' =>
Arr::get( $product,
'link' ),
181 '1x' =>
Arr::get( $product,
'icons.1x' ),
182 '2x' =>
Arr::get( $product,
'icons.2x' ),
185 'low' =>
Arr::get( $product,
'banners.low' ),
186 'high' =>
Arr::get( $product,
'banners.high' ),
189 'description' =>
Arr::get( $product,
'sections.description' ),
190 'changelog' =>
Arr::get( $product,
'sections.changelog' ),
192 'requires' =>
Arr::get( $product,
'system_requirements.wp.version' ),
193 'tested' =>
Arr::get( $product,
'system_requirements.wp.tested' ),
194 'requires_php' =>
Arr::get( $product,
'system_requirements.php.version' ),
197 if ( $download_link ) {
198 $formatted_data[
'package'] = $download_link;
199 $formatted_data[
'download_link'] = $download_link;
202 return (
object) $formatted_data;
222 LoggerFramework::get_instance()->error(
"Can't get products data when displaying the changelog: " . $e->getMessage() );
227 if (
'plugin_information' !== $action ) {
format_product_data( $product)
Returns a product object formatted according to what WP expects in order to display changelog/store p...
static get_instance()
Returns class instance.
static get( $array, $key, $default=null)
{}
init()
Initializes the class.
check_for_product_updates( $transient_data, $skip_cache=false)
Checks for product updates and modifies the 'update_plugins' transient.
disable_legacy_edd_updater()
Disables EDD updater that's included with GravityKit products.
static get_instance()
Returns class instance.
static get_instance()
Returns class instance.
display_product_information( $result, $action, $args)
Returns product information for display on the Plugins page.
Logging framework for GravityKit.