summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury German <blueknight@gentoo.org>2017-01-24 23:51:34 -0500
committerYury German <blueknight@gentoo.org>2017-01-24 23:51:34 -0500
commit3c539a4713a80181af84c1fedc742436f75c92c4 (patch)
treee1896c286f3fb98337a6297465974c65f1fe8f26 /plugins/jetpack/class.jetpack-autoupdate.php
parentUpdate theme twentyfifteen to 1.7 (diff)
downloadblogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.gz
blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.tar.bz2
blogs-gentoo-3c539a4713a80181af84c1fedc742436f75c92c4.zip
updating jetpack plugin
Diffstat (limited to 'plugins/jetpack/class.jetpack-autoupdate.php')
-rw-r--r--plugins/jetpack/class.jetpack-autoupdate.php121
1 files changed, 98 insertions, 23 deletions
diff --git a/plugins/jetpack/class.jetpack-autoupdate.php b/plugins/jetpack/class.jetpack-autoupdate.php
index 0041726c..c118dd5b 100644
--- a/plugins/jetpack/class.jetpack-autoupdate.php
+++ b/plugins/jetpack/class.jetpack-autoupdate.php
@@ -12,12 +12,12 @@ class Jetpack_Autoupdate {
private $success = array(
'plugin' => array(),
- 'theme' => array(),
+ 'theme' => array(),
);
private $failed = array(
'plugin' => array(),
- 'theme' => array(),
+ 'theme' => array(),
);
private static $instance = null;
@@ -26,14 +26,16 @@ class Jetpack_Autoupdate {
if ( is_null( self::$instance ) ) {
self::$instance = new Jetpack_Autoupdate;
}
+
return self::$instance;
}
private function __construct() {
if ( Jetpack::is_module_active( 'manage' ) ) {
- add_filter( 'auto_update_plugin', array( $this, 'autoupdate_plugin' ), 10, 2 );
- add_filter( 'auto_update_theme', array( $this, 'autoupdate_theme' ), 10, 2 );
- add_filter( 'auto_update_core', array( $this, 'autoupdate_core' ), 10, 2 );
+ add_filter( 'auto_update_plugin', array( $this, 'autoupdate_plugin' ), 10, 2 );
+ add_filter( 'auto_update_theme', array( $this, 'autoupdate_theme' ), 10, 2 );
+ add_filter( 'auto_update_core', array( $this, 'autoupdate_core' ), 10, 2 );
+ add_filter( 'auto_update_translation', array( $this, 'autoupdate_translation' ), 10, 2 );
add_action( 'automatic_updates_complete', array( $this, 'automatic_updates_complete' ), 999, 1 );
}
}
@@ -42,17 +44,61 @@ class Jetpack_Autoupdate {
$autoupdate_plugin_list = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
if ( in_array( $item->plugin, $autoupdate_plugin_list ) ) {
$this->expect( $item->plugin, 'plugin' );
- return true;
+
+ return true;
+ }
+
+ return $update;
+ }
+
+ public function autoupdate_translation( $update, $item ) {
+ // Themes
+ $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() );
+ $autoupdate_theme_list = Jetpack_Options::get_option( 'autoupdate_themes', array() );
+
+ /*
+ $item = {
+ "type":"theme",
+ "slug":"twentyfourteen",
+ "language":"en_CA",
+ "version":"1.8",
+ "updated":"2015-07-18 11:27:20",
+ "package":"https:\/\/downloads.wordpress.org\/translation\/theme\/twentyfourteen\/1.8\/en_CA.zip",
+ "autoupdate":true
}
+ */
+ if ( ( in_array( $item->slug, $autoupdate_themes_translations )
+ || in_array( $item->slug, $autoupdate_theme_list ) )
+ && 'theme' === $item->type
+ ) {
+ $this->expect( $item->type + ':' + $item->slug, 'translation' );
+
+ return true;
+ }
+
+ // Plugins
+ $autoupdate_plugin_translations = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() );
+ $autoupdate_plugin_list = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
+ $plugin_files = array_unique( array_merge( $autoupdate_plugin_list, $autoupdate_plugin_translations ) );
+ $plugin_slugs = array_map( array( __CLASS__, 'get_plugin_slug' ), $plugin_files );
+
+ if ( in_array( $item->slug, $plugin_slugs )
+ && 'plugin' === $item->type
+ ) {
+ $this->expect( $item->type + ':' + $item->slug, 'translation' );
+ return true;
+ }
+
return $update;
}
public function autoupdate_theme( $update, $item ) {
$autoupdate_theme_list = Jetpack_Options::get_option( 'autoupdate_themes', array() );
- if ( in_array( $item->theme , $autoupdate_theme_list) ) {
+ if ( in_array( $item->theme, $autoupdate_theme_list ) ) {
$this->expect( $item->theme, 'theme' );
return true;
}
+
return $update;
}
@@ -61,13 +107,14 @@ class Jetpack_Autoupdate {
if ( $autoupdate_core ) {
return $autoupdate_core;
}
+
return $update;
}
/**
* Stores the an item identifier to the expected array.
*
- * @param string $item Example: 'jetpack/jetpack.php' for type 'plugin' or 'twentyfifteen' for type 'theme'
+ * @param string $item Example: 'jetpack/jetpack.php' for type 'plugin' or 'twentyfifteen' for type 'theme'
* @param string $type 'plugin' or 'theme'
*/
private function expect( $item, $type ) {
@@ -92,8 +139,8 @@ class Jetpack_Autoupdate {
Jetpack::init();
- $items_to_log = array( 'plugin', 'theme' );
- foreach( $items_to_log as $items ) {
+ $items_to_log = array( 'plugin', 'theme', 'translation' );
+ foreach ( $items_to_log as $items ) {
$this->log_items( $items );
}
@@ -102,9 +149,9 @@ class Jetpack_Autoupdate {
public function get_log() {
return array(
- 'results' => $this->results,
- 'failed' => $this->failed,
- 'success' => $this->success
+ 'results' => $this->results,
+ 'failed' => $this->failed,
+ 'success' => $this->success
);
}
@@ -114,7 +161,6 @@ class Jetpack_Autoupdate {
* @param $items 'plugin' or 'theme'
*/
private function log_items( $items ) {
-
if ( ! isset( $this->expected[ $items ] ) ) {
return;
}
@@ -122,11 +168,11 @@ class Jetpack_Autoupdate {
$item_results = $this->get_successful_updates( $items );
if ( is_array( $this->expected[ $items ] ) ) {
- foreach( $this->expected[ $items ] as $item ) {
+ foreach ( $this->expected[ $items ] as $item ) {
if ( in_array( $item, $item_results ) ) {
- $this->success[ $items ][] = $item;
+ $this->success[ $items ][] = $item;
} else {
- $this->failed[ $items ][] = $item;
+ $this->failed[ $items ][] = $item;
}
}
}
@@ -134,7 +180,7 @@ class Jetpack_Autoupdate {
public function bump_stats() {
$instance = Jetpack::init();
- $log = array();
+ $log = array();
// Bump numbers
if ( ! empty( $this->success['plugin'] ) ) {
$instance->stat( 'autoupdates/plugin-success', count( $this->success['plugin'] ) );
@@ -161,7 +207,7 @@ class Jetpack_Autoupdate {
// Send a more detailed log to logstash
if ( ! empty( $log ) ) {
Jetpack::load_xml_rpc_client();
- $xml = new Jetpack_IXR_Client( array(
+ $xml = new Jetpack_IXR_Client( array(
'user_id' => get_current_user_id()
) );
$log['blog_id'] = Jetpack_Options::get_option( 'id' );
@@ -183,14 +229,18 @@ class Jetpack_Autoupdate {
return $successful_updates;
}
- foreach( $this->results[ $type ] as $result ) {
+ foreach ( $this->results[ $type ] as $result ) {
if ( $result->result ) {
- switch( $type ) {
+ switch ( $type ) {
case 'theme':
$successful_updates[] = $result->item->theme;
break;
case 'plugin':
$successful_updates[] = $result->item->plugin;
+ break;
+ case 'translation':
+ $successful_updates[] = $result->item->type + ':' + $result->item->slug;
+ break;
}
}
}
@@ -233,14 +283,39 @@ class Jetpack_Autoupdate {
if ( ! $skin->request_filesystem_credentials( false, ABSPATH, false ) ) {
$result[] = 'no-system-write-access';
}
- if ( ! $skin->request_filesystem_credentials( false, WP_PLUGIN_DIR, false ) ) {
+ if ( ! $skin->request_filesystem_credentials( false, WP_PLUGIN_DIR, false ) ) {
$result[] = 'no-plugin-directory-write-access';
}
- if ( ! $skin->request_filesystem_credentials( false, WP_CONTENT_DIR, false ) ) {
+ if ( ! $skin->request_filesystem_credentials( false, WP_CONTENT_DIR, false ) ) {
$result[] = 'no-wp-content-directory-write-access';
}
+
return $result;
}
+ static function get_plugin_slug( $plugin_file ) {
+ $update_plugins = get_site_transient( 'update_plugins' );
+ if ( isset( $update_plugins->no_update ) ) {
+ if ( isset( $update_plugins->no_update[ $plugin_file ] ) ) {
+ $slug = $update_plugins->no_update[ $plugin_file ]->slug;
+ }
+ }
+ if ( empty( $slug ) && isset( $update_plugins->response ) ) {
+ if ( isset( $update_plugins->response[ $plugin_file ] ) ) {
+ $slug = $update_plugins->response[ $plugin_file ]->slug;
+ }
+ }
+
+ // Try to infer from the plugin file if not cached
+ if ( empty( $slug) ) {
+ $slug = dirname( $plugin_file );
+ if ( '.' === $slug ) {
+ $slug = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
+ }
+ }
+ return $slug;
+ }
+
}
+
Jetpack_Autoupdate::init();