Skip to content

Commit

Permalink
Add defaults to site kit plugin update data.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmymadon committed Oct 18, 2023
1 parent 8897c2b commit ccf20bd
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion includes/Core/Util/Auto_Updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace Google\Site_Kit\Core\Util;

use stdClass;

/**
* Utility class for auto-updates settings.
*
Expand Down Expand Up @@ -101,8 +103,10 @@ public static function sitekit_forced_autoupdates_status() {
}

$sitekit_plugin_data = get_plugin_data( GOOGLESITEKIT_PLUGIN_MAIN_FILE );
$sitekit_update_data = self::get_sitekit_update_data();
$item = (object) array_merge( $sitekit_plugin_data, $sitekit_update_data );

$is_auto_update_forced_for_sitekit = wp_is_auto_update_forced_for_item( 'plugin', null, (object) $sitekit_plugin_data );
$is_auto_update_forced_for_sitekit = wp_is_auto_update_forced_for_item( 'plugin', null, $item );

if ( true === $is_auto_update_forced_for_sitekit ) {
return self::AUTO_UPDATE_FORCED_ENABLED;
Expand All @@ -114,4 +118,33 @@ public static function sitekit_forced_autoupdates_status() {

return self::AUTO_UPDATE_NOT_FORCED;
}

/**
* Merges plugin update data in the site transient with some default plugin data.
*
* @since n.e.x.t
*
* @return array Site Kit plugin update data.
*/
protected static function get_sitekit_update_data() {
$sitekit_update_data = array(
'id' => 'w.org/plugins/' . dirname( GOOGLESITEKIT_PLUGIN_BASENAME ),
'slug' => dirname( GOOGLESITEKIT_PLUGIN_BASENAME ),
'plugin' => GOOGLESITEKIT_PLUGIN_BASENAME,
'new_version' => '',
'url' => '',
'package' => '',
'icons' => array(),
'banners' => array(),
'banners_rtl' => array(),
'tested' => '',
'requires_php' => GOOGLESITEKIT_PHP_MINIMUM,
'compatibility' => new stdClass(),
);

$plugin_updates = get_site_transient( 'update_plugins' );
$transient_data = isset( $plugin_updates->response[ GOOGLESITEKIT_PLUGIN_BASENAME ] ) ? $plugin_updates->response[ GOOGLESITEKIT_PLUGIN_BASENAME ] : $plugin_updates->no_update[ GOOGLESITEKIT_PLUGIN_BASENAME ];
return array_merge( $sitekit_update_data, (array) $transient_data );
}

}

0 comments on commit ccf20bd

Please sign in to comment.