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/json-endpoints
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/json-endpoints')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php39
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-get-term-endpoint.php6
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php6
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php8
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-list-terms-endpoint.php6
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php13
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php11
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-update-term-endpoint.php6
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php46
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php94
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php24
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php25
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php11
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php61
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php65
15 files changed, 295 insertions, 126 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
index 84757d4f..75ad1f3b 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php
@@ -92,7 +92,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
Jetpack_SEO_Titles::TITLE_FORMATS_OPTION,
);
- protected static $jetpack_response_field_additions = array(
+ protected static $jetpack_response_field_additions = array(
'subscribers_count',
);
@@ -101,7 +101,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
'plan',
);
- protected static $jetpack_response_option_additions = array(
+ protected static $jetpack_response_option_additions = array(
'publicize_permanently_disabled',
'ak_vp_bundle_enabled'
);
@@ -128,7 +128,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
return $blog_id;
}
- // TODO: enable this when we can do so without being interfered with by
+ // TODO: enable this when we can do so without being interfered with by
// other endpoints that might be wrapping this one.
// Uncomment and see failing test: test_jetpack_site_should_have_true_jetpack_property_via_site_meta
// $this->filter_fields_and_options();
@@ -243,7 +243,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
$response[ $key ] = $this->site->is_following();
break;
case 'options':
- // small optimisation - don't recalculate
+ // small optimisation - don't recalculate
$all_options = apply_filters( 'sites_site_options_format', self::$site_options_format );
$options_response_keys = is_array( $this->options_to_include ) ?
@@ -268,16 +268,16 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
case 'jetpack' :
$response[ $key ] = $this->site->is_jetpack();
break;
- case 'single_user_site' :
+ case 'single_user_site' :
$response[ $key ] = $this->site->is_single_user_site();
break;
- case 'is_vip' :
+ case 'is_vip' :
$response[ $key ] = $this->site->is_vip();
break;
case 'is_multisite' :
$response[ $key ] = $this->site->is_multisite();
break;
- case 'capabilities' :
+ case 'capabilities' :
$response[ $key ] = $this->site->get_capabilities();
break;
case 'jetpack_modules':
@@ -303,7 +303,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
$site = $this->site;
$custom_front_page = $site->is_custom_front_page();
-
+
foreach ( $options_response_keys as $key ) {
switch ( $key ) {
@@ -368,7 +368,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
$options[ $key ] = $site->get_image_large_width();
break;
case 'image_large_height' :
- $options[ $key ] = $site->get_image_large_height();
+ $options[ $key ] = $site->get_image_large_height();
break;
case 'permalink_structure' :
$options[ $key ] = $site->get_permalink_structure();
@@ -448,14 +448,21 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint {
}
protected function build_meta_response( &$response ) {
+ $links = array(
+ 'self' => (string) $this->links->get_site_link( $this->site->blog_id ),
+ 'help' => (string) $this->links->get_site_link( $this->site->blog_id, 'help' ),
+ 'posts' => (string) $this->links->get_site_link( $this->site->blog_id, 'posts/' ),
+ 'comments' => (string) $this->links->get_site_link( $this->site->blog_id, 'comments/' ),
+ 'xmlrpc' => (string) $this->site->get_xmlrpc_url(),
+ );
+
+ $icon = $this->site->get_icon();
+ if ( ! empty( $icon ) && ! empty( $icon['media_id'] ) ) {
+ $links['site_icon'] = (string) $this->links->get_site_link( $this->site->blog_id, 'media/' . $icon['media_id'] );
+ }
+
$response['meta'] = (object) array(
- 'links' => (object) array(
- 'self' => (string) $this->links->get_site_link( $this->site->blog_id ),
- 'help' => (string) $this->links->get_site_link( $this->site->blog_id, 'help' ),
- 'posts' => (string) $this->links->get_site_link( $this->site->blog_id, 'posts/' ),
- 'comments' => (string) $this->links->get_site_link( $this->site->blog_id, 'comments/' ),
- 'xmlrpc' => (string) $this->site->get_xmlrpc_url(),
- ),
+ 'links' => (object) $links
);
}
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-term-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-term-endpoint.php
index fcb9a6f7..989a1459 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-term-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-term-endpoint.php
@@ -1,10 +1,4 @@
<?php
-/*
- * WARNING: This file is distributed verbatim in Jetpack.
- * There should be nothing WordPress.com specific in this file.
- *
- * @hide-in-jetpack
- */
class WPCOM_JSON_API_Get_Term_Endpoint extends WPCOM_JSON_API_Endpoint {
// /sites/%s/taxonomies/%s/terms/slug:%s -> $blog_id, $taxonomy, $slug
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
index be037134..73218abd 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
@@ -1,10 +1,4 @@
<?php
-/*
- * WARNING: This file is distributed verbatim in Jetpack.
- * There should be nothing WordPress.com specific in this file.
- *
- * @hide-in-jetpack
- */
class WPCOM_JSON_API_List_Post_Type_Taxonomies_Endpoint extends WPCOM_JSON_API_Endpoint {
static $taxonomy_keys_to_include = array(
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php
index c18719f0..e2cf4623 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-post-types-endpoint.php
@@ -9,6 +9,8 @@ class WPCOM_JSON_API_List_Post_Types_Endpoint extends WPCOM_JSON_API_Endpoint {
'map_meta_cap' => 'map_meta_cap',
'cap' => 'capabilities',
'hierarchical' => 'hierarchical',
+ 'show_ui' => 'show_ui',
+ 'publicly_queryable' => 'publicly_queryable',
);
// /sites/%s/post-types -> $blog_id
@@ -36,17 +38,15 @@ class WPCOM_JSON_API_List_Post_Types_Endpoint extends WPCOM_JSON_API_Endpoint {
create_initial_post_types();
}
- $queryable_only = isset( $args['api_queryable'] ) && $args['api_queryable'];
-
// Get a list of available post types
- $post_types = get_post_types( array( 'public' => true ) );
+ $post_types = get_post_types();
$formatted_post_type_objects = array();
// Retrieve post type object for each post type
foreach ( $post_types as $post_type ) {
// Skip non-queryable if filtering on queryable only
$is_queryable = $this->is_post_type_allowed( $post_type );
- if ( $queryable_only && ! $is_queryable ) {
+ if ( ! $is_queryable ) {
continue;
}
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-terms-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-terms-endpoint.php
index c015e34a..5ffc432a 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-terms-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-terms-endpoint.php
@@ -1,10 +1,4 @@
<?php
-/*
- * WARNING: This file is distributed verbatim in Jetpack.
- * There should be nothing WordPress.com specific in this file.
- *
- * @hide-in-jetpack
- */
class WPCOM_JSON_API_List_Terms_Endpoint extends WPCOM_JSON_API_Endpoint {
// /sites/%s/taxonomies/%s/terms -> $blog_id, $taxonomy
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
index d99351a8..66cea4c4 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php
@@ -158,6 +158,8 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint {
$holiday_snow = (bool) get_option( jetpack_holiday_snow_option_name() );
}
+ $api_cache = $is_jetpack ? (bool) get_option( 'jetpack_api_cache_enabled' ) : true;
+
$response[ $key ] = array(
// also exists as "options"
@@ -214,6 +216,7 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint {
'site_icon' => $this->get_cast_option_value_or_null( 'site_icon', 'intval' ),
Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION => get_option( Jetpack_SEO_Utils::FRONT_PAGE_META_OPTION, '' ),
Jetpack_SEO_Titles::TITLE_FORMATS_OPTION => get_option( Jetpack_SEO_Titles::TITLE_FORMATS_OPTION, array() ),
+ 'api_cache' => $api_cache,
);
//allow future versions of this endpoint to support additional settings keys
@@ -420,6 +423,16 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint {
}
break;
+ case 'api_cache':
+ if ( empty( $value ) || WPCOM_JSON_API::is_falsy( $value ) ) {
+ if ( delete_option( 'jetpack_api_cache_enabled' ) ) {
+ $updated[ $key ] = false;
+ }
+ } else if ( update_option( 'jetpack_api_cache_enabled', true ) ) {
+ $updated[ $key ] = true;
+ }
+ break;
+
case 'timezone_string':
// Map UTC+- timezones to gmt_offsets and set timezone_string to empty
// https://github.com/WordPress/WordPress/blob/4.4.2/wp-admin/options.php#L175
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php
index eac28c00..d682094d 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php
@@ -1,13 +1,6 @@
<?php
-/**
- * WARNING: This file is distributed verbatim in Jetpack.
- * There should be nothing WordPress.com specific in this file.
- *
- * @hide-in-jetpack
- * @autounit api site-settings
- */
-
-class WPCOM_JSON_API_Site_Settings_V1_2_endpoint extends WPCOM_JSON_API_Site_Settings_Endpoint {
+
+class WPCOM_JSON_API_Site_Settings_V1_2_Endpoint extends WPCOM_JSON_API_Site_Settings_Endpoint {
public static $site_format = array(
'ID' => '(int) Site ID',
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-term-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-term-endpoint.php
index cddee7d9..cb7bc02b 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-term-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-term-endpoint.php
@@ -1,10 +1,4 @@
<?php
-/*
- * WARNING: This file is distributed verbatim in Jetpack.
- * There should be nothing WordPress.com specific in this file.
- *
- * @hide-in-jetpack
- */
class WPCOM_JSON_API_Update_Term_Endpoint extends WPCOM_JSON_API_Taxonomy_Endpoint {
// /sites/%s/taxonomies/%s/terms/new -> $blog_id, $taxonomy
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
index 659ab23b..c440a3fa 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php
@@ -25,6 +25,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
'author_url' => '(url) The authors web site address',
'network' => '(boolean) Whether the plugin can only be activated network wide.',
'autoupdate' => '(boolean) Whether the plugin is automatically updated',
+ 'autoupdate_translation' => '(boolean) Whether the plugin is automatically updating translations',
'next_autoupdate' => '(string) Y-m-d H:i:s for next scheduled update event',
'log' => '(array:safehtml) An array of update log strings.',
'uninstallable' => '(boolean) Whether the plugin is unistallable.',
@@ -68,7 +69,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$this->bulk = false;
$this->plugins[] = urldecode( $plugin );
}
-
+
if ( is_wp_error( $error = $this->validate_plugins() ) ) {
return $error;
};
@@ -89,17 +90,19 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$plugin = $plugin . '.php';
$this->plugins[ $index ] = $plugin;
}
- if ( is_wp_error( $error = $this->validate_plugin( $plugin ) ) ) {
- return $error;
+ $valid = $this->validate_plugin( urldecode( $plugin ) ) ;
+ if ( is_wp_error( $valid ) ) {
+ return $valid;
}
}
+
return true;
}
protected function format_plugin( $plugin_file, $plugin_data ) {
$plugin = array();
$plugin['id'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
- $plugin['slug'] = $this->get_plugin_slug( $plugin_file );
+ $plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug( $plugin_file );
$plugin['active'] = Jetpack::is_plugin_active( $plugin_file );
$plugin['name'] = $plugin_data['Name'];
$plugin['plugin_url'] = $plugin_data['PluginURI'];
@@ -110,8 +113,15 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$plugin['network'] = $plugin_data['Network'];
$plugin['update'] = $this->get_plugin_updates( $plugin_file );
$plugin['next_autoupdate'] = date( 'Y-m-d H:i:s', wp_next_scheduled( 'wp_maybe_auto_update' ) );
- $plugin['autoupdate'] = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) );
+
+ $autoupdate = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) );
+ $plugin['autoupdate'] = $autoupdate;
+
+ $autoupdate_translation = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ) );
+ $plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation;
+
$plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
+
if ( ! empty ( $this->log[ $plugin_file ] ) ) {
$plugin['log'] = $this->log[ $plugin_file ];
}
@@ -159,7 +169,7 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return new WP_Error( 'missing_plugin', __( 'You are required to specify a plugin to activate.', 'jetpack' ), 400 );
}
- if ( is_wp_error( $error = validate_plugin( urldecode( $plugin ) ) ) ) {
+ if ( is_wp_error( $error = validate_plugin( $plugin ) ) ) {
return new WP_Error( 'unknown_plugin', $error->get_error_messages() , 404 );
}
@@ -173,28 +183,4 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
}
return null;
}
-
- protected 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;
- }
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
index fca8173e..2e675f7f 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php
@@ -3,14 +3,17 @@
class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
// POST /sites/%s/plugins/%s
// POST /sites/%s/plugins
-
+ protected $slug = null;
protected $needed_capabilities = 'activate_plugins';
protected $action = 'default_action';
- protected $expected_actions = array( 'update', 'install', 'delete' );
+ protected $expected_actions = array( 'update', 'install', 'delete', 'update_translations' );
public function callback( $path = '', $blog_id = 0, $object = null ) {
Jetpack_JSON_API_Endpoint::validate_input( $object );
switch ( $this->action ) {
+ case 'delete':
+ $this->needed_capabilities = 'delete_plugins';
+ case 'update_translations':
case 'update' :
$this->needed_capabilities = 'update_plugins';
break;
@@ -18,7 +21,8 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
$this->needed_capabilities = 'install_plugins';
break;
}
- if ( isset( $args['autoupdate'] ) ) {
+
+ if ( isset( $args['autoupdate'] ) || isset( $args['autoupdate_translations'] ) ) {
$this->needed_capabilities = 'update_plugins';
}
@@ -44,6 +48,14 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
}
}
+ if ( isset( $args['autoupdate_translations'] ) && is_bool( $args['autoupdate_translations'] ) ) {
+ if ( $args['autoupdate_translations'] ) {
+ $this->autoupdate_translations_on();
+ } else {
+ $this->autoupdate_translations_off();
+ }
+ }
+
return true;
}
@@ -59,6 +71,18 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
Jetpack_Options::update_option( 'autoupdate_plugins', $autoupdate_plugins );
}
+ protected function autoupdate_translations_on() {
+ $autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() );
+ $autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) );
+ Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins );
+ }
+
+ protected function autoupdate_translations_off() {
+ $autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() );
+ $autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins );
+ Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins );
+ }
+
protected function activate() {
foreach ( $this->plugins as $plugin ) {
if ( ( ! $this->network_wide && Jetpack::is_plugin_active( $plugin ) ) || is_plugin_active_for_network( $plugin ) ) {
@@ -151,7 +175,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
$result = false;
foreach ( $this->plugins as $plugin ) {
-
+
if ( ! in_array( $plugin, $plugin_updates_needed ) ) {
$this->log[ $plugin ][] = __( 'No update needed', 'jetpack' );
continue;
@@ -166,7 +190,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
* @param array $plugin Array of plugin objects
* @param bool $updated_attempted false for the first update, true subsequently
*/
- do_action('jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted);
+ do_action( 'jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted );
$update_attempted = true;
@@ -179,7 +203,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
defined( 'DOING_CRON' ) or define( 'DOING_CRON', true );
$result = $upgrader->upgrade( $plugin );
- $this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages();
+ $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages();
}
if ( ! $this->bulk && ! $result && $update_attempted ) {
@@ -188,4 +212,62 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return $this->default_action();
}
+
+ function update_translations() {
+ include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+
+ // Clear the cache.
+ wp_clean_plugins_cache();
+ ob_start();
+ wp_update_plugins(); // Check for Plugin updates
+ ob_end_clean();
+
+ $available_updates = get_site_transient( 'update_plugins' );
+ if ( ! isset( $available_updates->translations ) || empty( $available_updates->translations ) ) {
+ return new WP_Error( 'nothing_to_translate' );
+ }
+
+ $update_attempted = false;
+ $result = false;
+ foreach( $this->plugins as $plugin ) {
+ $this->slug = Jetpack_Autoupdate::get_plugin_slug( $plugin );
+ $translation = array_filter( $available_updates->translations, array( $this, 'get_translation' ) );
+
+ if ( empty( $translation ) ) {
+ $this->log[ $plugin ][] = __( 'No update needed', 'jetpack' );
+ continue;
+ }
+
+ /**
+ * Pre-upgrade action
+ *
+ * @since 4.4
+ *
+ * @param array $plugin Plugin data
+ * @param array $plugin Array of plugin objects
+ * @param bool $updated_attempted false for the first update, true subsequently
+ */
+ do_action( 'jetpack_pre_plugin_upgrade_translations', $plugin, $this->plugins, $update_attempted );
+
+ $update_attempted = true;
+
+ $skin = new Automatic_Upgrader_Skin();
+ $upgrader = new Language_Pack_Upgrader( $skin );
+ $upgrader->init();
+
+ $result = $upgrader->upgrade( (object) $translation[0] );
+
+ $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages();
+ }
+
+ if ( ! $this->bulk && ! $result ) {
+ return new WP_Error( 'update_fail', __( 'There was an error updating your plugin', 'jetpack' ), 400 );
+ }
+
+ return true;
+ }
+
+ protected function get_translation( $translation ) {
+ return ( $translation['slug'] === $this->slug );
+ }
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
index b562d949..2c694896 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php
@@ -52,29 +52,7 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
// GET /sites/%s/sync/status
class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
protected function result() {
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-modules.php';
- require_once JETPACK__PLUGIN_DIR . 'sync/class.jetpack-sync-sender.php';
-
- $sync_module = Jetpack_Sync_Modules::get_module( 'full-sync' );
- $sender = Jetpack_Sync_Sender::get_instance();
- $queue = $sender->get_sync_queue();
- $full_queue = $sender->get_full_sync_queue();
- $cron_timestamps = array_keys( _get_cron_array() );
- $next_cron = $cron_timestamps[0] - time();
-
- return array_merge(
- $sync_module->get_status(),
- array(
- 'cron_size' => count( $cron_timestamps ),
- 'next_cron' => $next_cron,
- 'queue_size' => $queue->size(),
- 'queue_lag' => $queue->lag(),
- 'queue_next_sync' => ( $sender->get_next_sync_time( 'sync' ) - microtime( true ) ),
- 'full_queue_size' => $full_queue->size(),
- 'full_queue_lag' => $full_queue->lag(),
- 'full_queue_next_sync' => ( $sender->get_next_sync_time( 'full_sync' ) - microtime( true ) ),
- )
- );
+ return Jetpack_Sync_Actions::get_sync_status();
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php
index ff567113..97bcc58d 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php
@@ -21,14 +21,33 @@ class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_En
continue;
}
- $result = delete_theme( $theme );
+ /**
+ * Filters whether to use an alternative process for deleting a WordPress.com theme.
+ * The alternative process can be executed during the filter.
+ *
+ * The filter can also return an instance of WP_Error; in which case the endpoint response will
+ * contain this error.
+ *
+ * @module json-api
+ *
+ * @since 4.4.2
+ *
+ * @param bool $use_alternative_delete_method Whether to use the alternative method of deleting
+ * a WPCom theme.
+ * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
+ * it should be suffixed with `-wpcom`.
+ */
+ $result = apply_filters( 'jetpack_wpcom_theme_delete', false, $theme );
+
+ if ( ! $result ) {
+ $result = delete_theme( $theme );
+ }
if ( is_wp_error( $result ) ) {
- $error = $this->log[ $theme ]['error'] = $result->get_error_messages;
+ $error = $this->log[ $theme ]['error'] = $result->get_error_messages();
} else {
$this->log[ $theme ][] = 'Theme deleted';
}
-
}
if( ! $this->bulk && isset( $error ) ) {
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php
index 37a20800..d77d3ca4 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php
@@ -25,6 +25,7 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
'tags' => '(array) Tags indicating styles and features of the theme.',
'log' => '(array) An array of log strings',
'autoupdate' => '(bool) Whether the theme is automatically updated',
+ 'autoupdate_translation' => '(bool) Whether the theme is automatically updating translations',
);
protected function result() {
@@ -118,13 +119,13 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
$update_themes = get_site_transient( 'update_themes' );
$formatted_theme['update'] = ( isset( $update_themes->response[ $id ] ) ) ? $update_themes->response[ $id ] : null;
- $autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() );
+ $autoupdate = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes', array() ) );
+ $formatted_theme['autoupdate'] = $autoupdate;
- $autoupdate = in_array( $id, $autoupdate_themes );
+ $autoupdate_translation = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ) );
+ $formatted_theme['autoupdate_translation'] = $autoupdate || $autoupdate_translation;
- $formatted_theme['autoupdate'] = $autoupdate;
-
- if( isset( $this->log[ $id ] ) ) {
+ if ( isset( $this->log[ $id ] ) ) {
$formatted_theme['log'] = $this->log[ $id ];
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
index 1ac99e6f..3061a6f5 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php
@@ -14,11 +14,36 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
foreach ( $this->themes as $theme ) {
- $skin = new Jetpack_Automatic_Install_Skin();
- $upgrader = new Theme_Upgrader( $skin );
+ /**
+ * Filters whether to use an alternative process for installing a WordPress.com theme.
+ * The alternative process can be executed during the filter.
+ *
+ * The filter can also return an instance of WP_Error; in which case the endpoint response will
+ * contain this error.
+ *
+ * @module json-api
+ *
+ * @since 4.4.2
+ *
+ * @param bool $use_alternative_install_method Whether to use the alternative method of installing
+ * a WPCom theme.
+ * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
+ * it should be suffixed with `-wpcom`.
+ */
+ $result = apply_filters( 'jetpack_wpcom_theme_install', false, $theme );
+
+ $skin = null;
+ $upgrader = null;
+ $link = null;
+
+ // If the alternative install method was not used, use the standard method.
+ if ( ! $result ) {
+ $skin = new Jetpack_Automatic_Install_Skin();
+ $upgrader = new Theme_Upgrader( $skin );
- $link = $this->download_links[ $theme ];
- $result = $upgrader->install( $link );
+ $link = $this->download_links[ $theme ];
+ $result = $upgrader->install( $link );
+ }
if ( file_exists( $link ) ) {
// Delete if link was tmp local file
@@ -37,7 +62,7 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
$error = $this->log[ $theme ]['error'] = __( 'There was an error installing your theme', 'jetpack' );
}
- else {
+ elseif ( $upgrader ) {
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages();
}
}
@@ -59,8 +84,34 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
return new WP_Error( 'theme_already_installed', __( 'The theme is already installed', 'jetpack' ) );
}
+ /**
+ * Filters whether to skip the standard method of downloading and validating a WordPress.com
+ * theme. An alternative method of WPCom theme download and validation can be
+ * executed during the filter.
+ *
+ * The filter can also return an instance of WP_Error; in which case the endpoint response will
+ * contain this error.
+ *
+ * @module json-api
+ *
+ * @since 4.4.2
+ *
+ * @param bool $skip_download_filter_result Whether to skip the standard method of downloading
+ * and validating a WPCom theme.
+ * @param string $theme_slug Theme name (slug). If it is a WPCom theme,
+ * it should be suffixed with `-wpcom`.
+ */
+ $skip_download_filter_result = apply_filters( 'jetpack_wpcom_theme_skip_download', false, $theme );
+
+ if ( is_wp_error( $skip_download_filter_result ) ) {
+ return $skip_download_filter_result;
+ } elseif ( $skip_download_filter_result ) {
+ continue;
+ }
+
if ( wp_endswith( $theme, '-wpcom' ) ) {
$file = self::download_wpcom_theme_to_file( $theme );
+
if ( is_wp_error( $file ) ) {
return $file;
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php
index cbf361ba..c041158b 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php
@@ -6,7 +6,7 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
protected $needed_capabilities = 'update_themes';
protected $action = 'default_action';
- protected $expected_actions = array( 'update' );
+ protected $expected_actions = array( 'update', 'update_translations' );
public function default_action() {
$args = $this->input();
@@ -17,6 +17,13 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
$this->autoupdate_off();
}
}
+ if ( isset( $args['autoupdate_translations'] ) && is_bool( $args['autoupdate_translations'] ) ) {
+ if ( $args['autoupdate_translations'] ) {
+ $this->autoupdate_translations_on();
+ } else {
+ $this->autoupdate_translations_off();
+ }
+ }
return true;
}
@@ -33,6 +40,18 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes );
}
+ function autoupdate_translations_on() {
+ $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() );
+ $autoupdate_themes_translations = array_unique( array_merge( $autoupdate_themes_translations, $this->themes ) );
+ Jetpack_Options::update_option( 'autoupdate_themes_translations', $autoupdate_themes_translations );
+ }
+
+ function autoupdate_translations_off() {
+ $autoupdate_themes_translations = Jetpack_Options::get_option( 'autoupdate_themes_translations', array() );
+ $autoupdate_themes_translations = array_diff( $autoupdate_themes_translations, $this->themes );
+ Jetpack_Options::update_option( 'autoupdate_themes_translations', $autoupdate_themes_translations );
+ }
+
function update() {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@@ -64,4 +83,48 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
return true;
}
+ function update_translations() {
+ include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+
+ // Clear the cache.
+ wp_update_themes();
+
+ $available_themes_updates = get_site_transient( 'update_themes' );
+
+ if ( ! isset( $available_themes_updates->translations ) || empty( $available_themes_updates->translations ) ) {
+ return new WP_Error( 'nothing_to_translate' );
+ }
+
+ foreach( $available_themes_updates->translations as $translation ) {
+ $theme = $translation['slug'] ;
+ if ( ! in_array( $translation['slug'], $this->themes ) ) {
+ $this->log[ $theme ][] = __( 'No update needed', 'jetpack' );
+ continue;
+ }
+
+ /**
+ * Pre-upgrade action
+ *
+ * @since 4.4
+ *
+ * @param object $theme WP_Theme object
+ * @param array $themes Array of theme objects
+ */
+ do_action( 'jetpack_pre_theme_upgrade_translations', $theme, $this->themes );
+ // Objects created inside the for loop to clean the messages for each theme
+ $skin = new Automatic_Upgrader_Skin();
+ $upgrader = new Language_Pack_Upgrader( $skin );
+ $upgrader->init();
+
+ $result = $upgrader->upgrade( (object) $translation );
+ $this->log[ $theme ] = $upgrader->skin->get_upgrade_messages();
+ }
+
+ if ( ! $this->bulk && ! $result ) {
+ return new WP_Error( 'update_fail', __( 'There was an error updating your theme', 'jetpack' ), 400 );
+ }
+
+ return true;
+ }
+
}