summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury German <blueknight@gentoo.org>2022-06-15 12:08:35 -0400
committerYury German <blueknight@gentoo.org>2022-06-15 12:08:35 -0400
commit36d7691c33cb64ece817246e47a779ec648d10b0 (patch)
tree08f2fb95303a1d8eeba2c8629a24b35a91fb1cac /plugins/jetpack/json-endpoints/jetpack
parenttwentyfourteen upg 2.7 to 3.2 and twentysixteen from 2.0 to 2.5 (diff)
downloadblogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.tar.gz
blogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.tar.bz2
blogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.zip
Openid-3.6.1 and jetpack-11.0 upgrade
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/jetpack/json-endpoints/jetpack')
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php23
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-endpoint.php33
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php78
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php152
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-endpoint.php80
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-comment-backup-endpoint.php35
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-database-object-backup-endpoint.php67
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-option-backup-endpoint.php39
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php44
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-term-backup-endpoint.php33
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php33
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php26
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php26
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-maybe-auto-update-endpoint.php31
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php60
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-get-endpoint.php13
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-list-endpoint.php22
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php51
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php31
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-endpoint.php266
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-get-endpoint.php20
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php46
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-list-endpoint.php27
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php157
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php7
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php54
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php227
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php38
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-delete-endpoint.php44
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-endpoint.php112
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-get-endpoint.php13
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php115
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-list-endpoint.php23
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-modify-endpoint.php93
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-new-endpoint.php67
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php43
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php41
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-updates-status-endpoint.php24
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php39
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php65
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php36
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php28
-rw-r--r--plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php1338
43 files changed, 2635 insertions, 1165 deletions
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php
index c86cddec..ac2fc496 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-check-capabilities-endpoint.php
@@ -1,11 +1,24 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Check capabilities endpoint class.
+ *
+ * GET /sites/%s/me/capability
+ */
class Jetpack_JSON_API_Check_Capabilities_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
- // GET /sites/%s/me/capability
- // The unused $object parameter is for making the method signature compatible with its parent class method.
- public function callback( $path = '', $_blog_id = 0, $object = null ) {
+ /**
+ *
+ * API callback.
+ *
+ * @param string $path - the path.
+ * @param int $_blog_id - the blog ID.
+ * @param obj $object - parameter is for making the method signature compatible with its parent class method.
+ * @return bool|bool[]|WP_Error
+ */
+ public function callback( $path = '', $_blog_id = 0, $object = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Check minimum capability and blog membership first
- if ( is_wp_error( $error = $this->validate_call( $_blog_id, 'read', false ) ) ) {
+ $error = $this->validate_call( $_blog_id, 'read', false );
+ if ( is_wp_error( $error ) ) {
return $error;
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-endpoint.php
index f63a6cd7..e0c94592 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-endpoint.php
@@ -1,12 +1,39 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Core endpoint class.
+ *
+ * POST /sites/%s/core
+ * POST /sites/%s/core/update
+ */
class Jetpack_JSON_API_Core_Endpoint extends Jetpack_JSON_API_Endpoint {
- // POST /sites/%s/core
- // POST /sites/%s/core/update
+
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'manage_options';
+
+ /**
+ * New version.
+ *
+ * @var string
+ */
protected $new_version;
+
+ /**
+ * An array of log strings.
+ *
+ * @var array
+ */
protected $log;
+ /**
+ * Return the result of the wp_version.
+ *
+ * @return array
+ */
public function result() {
global $wp_version;
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php
index 8f707ad4..5d899d26 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php
@@ -1,13 +1,46 @@
-<?php
-
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+
+/**
+ * Core modify endpoint class.
+ *
+ * POST /sites/%s/core
+ * POST /sites/%s/core/update
+ */
class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoint {
- // POST /sites/%s/core
- // POST /sites/%s/core/update
+
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'update_core';
- protected $action = 'default_action';
+
+ /**
+ * Action.
+ *
+ * @var string
+ */
+ protected $action = 'default_action';
+
+ /**
+ * New version.
+ *
+ * @var string
+ */
protected $new_version;
+
+ /**
+ * An array of log strings.
+ *
+ * @var array
+ */
protected $log;
+ /**
+ * The default action.
+ *
+ * @return bool
+ */
public function default_action() {
$args = $this->input();
@@ -18,10 +51,15 @@ class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoi
return true;
}
+ /**
+ * Update the version.
+ *
+ * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
+ */
protected function update() {
- $args = $this->input();
- $version = isset( $args['version'] ) ? $args['version'] : false;
- $locale = isset( $args['locale'] ) ? $args['locale'] : get_locale();
+ $args = $this->input();
+ $version = isset( $args['version'] ) ? $args['version'] : false;
+ $locale = isset( $args['locale'] ) ? $args['locale'] : get_locale();
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@@ -36,12 +74,12 @@ class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoi
/**
* Pre-upgrade action
- *
+ *
* @since 3.9.3
- *
+ *
* @param object|array $update as returned by find_core_update() or find_core_auto_update()
*/
- do_action('jetpack_pre_core_upgrade', $update);
+ do_action( 'jetpack_pre_core_upgrade', $update );
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Core_Upgrader( $skin );
@@ -57,17 +95,23 @@ class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoi
return $this->new_version;
}
+ /**
+ * Select the latest update.
+ * Remove filters to bypass automattic updates.
+ *
+ * @return object|false The core update offering on success, false on failure.
+ */
protected function find_latest_update_offer() {
// Select the latest update.
// Remove filters to bypass automattic updates.
- add_filter( 'request_filesystem_credentials', '__return_true' );
- add_filter( 'automatic_updates_is_vcs_checkout', '__return_false' );
- add_filter( 'allow_major_auto_core_updates', '__return_true' );
+ add_filter( 'request_filesystem_credentials', '__return_true' );
+ add_filter( 'automatic_updates_is_vcs_checkout', '__return_false' );
+ add_filter( 'allow_major_auto_core_updates', '__return_true' );
add_filter( 'send_core_update_notification_email', '__return_false' );
$update = find_core_auto_update();
- remove_filter( 'request_filesystem_credentials', '__return_true' );
- remove_filter( 'automatic_updates_is_vcs_checkout', '__return_false' );
- remove_filter( 'allow_major_auto_core_updates', '__return_true' );
+ remove_filter( 'request_filesystem_credentials', '__return_true' );
+ remove_filter( 'automatic_updates_is_vcs_checkout', '__return_false' );
+ remove_filter( 'allow_major_auto_core_updates', '__return_true' );
remove_filter( 'send_core_update_notification_email', '__return_false' );
return $update;
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php
index c1ca60a7..e7aecd3b 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php
@@ -1,59 +1,118 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-// GET /sites/%s/cron
+/**
+ * Cron endpoint class.
+ *
+ * GET /sites/%s/cron
+ */
class Jetpack_JSON_API_Cron_Endpoint extends Jetpack_JSON_API_Endpoint {
+
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'manage_options';
- protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) {
+ /**
+ * Validate the call.
+ *
+ * @param int $_blog_id - the blog ID.
+ * @param array $capability - the capabilities of the user.
+ * @param bool $check_manage_active - parameter is for making the method signature compatible with its parent class method.
+ */
+ protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return parent::validate_call( $_blog_id, $capability, false );
}
+ /**
+ * Return the result of current timestamp.
+ */
protected function result() {
return array(
- 'cron_array' => _get_cron_array(),
- 'current_timestamp' => time()
+ 'cron_array' => _get_cron_array(),
+ 'current_timestamp' => time(),
);
}
+ /**
+ * Sanitize the hook.
+ *
+ * @param string $hook - the hook.
+ *
+ * @return string
+ */
protected function sanitize_hook( $hook ) {
return preg_replace( '/[^A-Za-z0-9-_]/', '', $hook );
}
+ /**
+ * Resolve arguments.
+ *
+ * @return array
+ */
protected function resolve_arguments() {
$args = $this->input();
- return isset( $args['arguments'] ) ? json_decode( $args['arguments'] ) : array();
+ return isset( $args['arguments'] ) ? json_decode( $args['arguments'] ) : array();
}
+ /**
+ * Check the cron lock.
+ *
+ * @param float $gmt_time - the time in GMT.
+ *
+ * @return string|int|WP_Error WP_Error if cron was locked in the `WP_CRON_LOCK_TIMEOUT` seconds before `gmt_time`, int or string otherwise.
+ */
protected function is_cron_locked( $gmt_time ) {
// The cron lock: a unix timestamp from when the cron was spawned.
$doing_cron_transient = $this->get_cron_lock();
- if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) {
+ if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) {
return new WP_Error( 'cron-is-locked', 'Current there is a cron already happening.', 403 );
}
return $doing_cron_transient;
}
+ /**
+ * Check if we can unlock the cron transient.
+ *
+ * @param string $doing_wp_cron - if we're doing the wp_cron.
+ */
protected function maybe_unlock_cron( $doing_wp_cron ) {
- if ( $this->get_cron_lock() == $doing_wp_cron ) {
+ if ( $this->get_cron_lock() === $doing_wp_cron ) {
delete_transient( 'doing_cron' );
}
}
+ /**
+ * Set the cron lock.
+ *
+ * @return string
+ */
protected function lock_cron() {
$lock = sprintf( '%.22F', microtime( true ) );
set_transient( 'doing_cron', $lock );
return $lock;
}
+ /**
+ * Get scheduled.
+ *
+ * @param string $hook - the hook.
+ * @param array $args - the arguments.
+ *
+ * @return array
+ */
protected function get_schedules( $hook, $args ) {
$crons = _get_cron_array();
- $key = md5(serialize($args));
- if ( empty( $crons ) )
+ $key = md5( serialize( $args ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
+ if ( empty( $crons ) ) {
return array();
+ }
$found = array();
foreach ( $crons as $timestamp => $cron ) {
- if ( isset( $cron[$hook][$key] ) )
+ if ( isset( $cron[ $hook ][ $key ] ) ) {
$found[] = $timestamp;
+ }
}
return $found;
@@ -61,6 +120,7 @@ class Jetpack_JSON_API_Cron_Endpoint extends Jetpack_JSON_API_Endpoint {
/**
* This function is based on the one found in wp-cron.php with a similar name
+ *
* @return int
*/
protected function get_cron_lock() {
@@ -83,20 +143,29 @@ class Jetpack_JSON_API_Cron_Endpoint extends Jetpack_JSON_API_Endpoint {
}
}
-// POST /sites/%s/cron
-class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint {
+/**
+ * Cron post endpoint class.
+ *
+ * POST /sites/%s/cron
+ */
+class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
define( 'DOING_CRON', true );
set_time_limit( 0 );
- $args = $this->input();
-
- if ( false === $crons = _get_cron_array() ) {
+ $args = $this->input();
+ $crons = _get_cron_array();
+ if ( false === $crons ) {
return new WP_Error( 'no-cron-event', 'Currently there are no cron events', 400 );
}
$timestamps_to_run = array_keys( $crons );
- $gmt_time = microtime( true );
+ $gmt_time = microtime( true );
if ( isset( $timestamps_to_run[0] ) && $timestamps_to_run[0] > $gmt_time ) {
return new WP_Error( 'no-cron-event', 'Currently there are no cron events ready to be run', 400 );
@@ -107,25 +176,25 @@ class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint
return $locked;
}
- $lock = $this->lock_cron();
+ $lock = $this->lock_cron();
$processed_events = array();
foreach ( $crons as $timestamp => $cronhooks ) {
- if ( $timestamp > $gmt_time && ! isset( $args[ 'hook' ] ) ) {
+ if ( $timestamp > $gmt_time && ! isset( $args['hook'] ) ) {
break;
}
foreach ( $cronhooks as $hook => $hook_data ) {
- if ( isset( $args[ 'hook' ] ) && ! in_array( $hook, $args['hook'] ) ) {
+ if ( isset( $args['hook'] ) && ! in_array( $hook, $args['hook'], true ) ) {
continue;
}
- foreach ( $hook_data as $hash => $hook_item ) {
+ foreach ( $hook_data as $hook_item ) {
- $schedule = $hook_item['schedule'];
+ $schedule = $hook_item['schedule'];
$arguments = $hook_item['args'];
- if ( $schedule != false ) {
+ if ( ! $schedule ) {
wp_reschedule_event( $timestamp, $schedule, $hook, $arguments );
}
@@ -136,11 +205,10 @@ class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint
// If the hook ran too long and another cron process stole the lock,
// or if we things are taking longer then 20 seconds then quit.
- if ( ( $this->get_cron_lock() != $lock ) || ( $gmt_time + 20 > microtime( true ) ) ) {
+ if ( ( $this->get_cron_lock() !== $lock ) || ( $gmt_time + 20 > microtime( true ) ) ) {
$this->maybe_unlock_cron( $lock );
return array( 'success' => $processed_events );
}
-
}
}
}
@@ -150,9 +218,18 @@ class Jetpack_JSON_API_Cron_Post_Endpoint extends Jetpack_JSON_API_Cron_Endpoint
}
}
-// POST /sites/%s/cron/schedule
-class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint {
+/**
+ * Schedule endpoint class.
+ *
+ * POST /sites/%s/cron/schedule
+ */
+class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->input();
if ( ! isset( $args['timestamp'] ) ) {
@@ -174,7 +251,7 @@ class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endp
return $locked;
}
- $arguments = $this->resolve_arguments();
+ $arguments = $this->resolve_arguments();
$next_scheduled = $this->get_schedules( $hook, $arguments );
if ( isset( $args['recurrence'] ) ) {
@@ -192,7 +269,7 @@ class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endp
return array( 'success' => true );
}
- foreach( $next_scheduled as $scheduled_time ) {
+ foreach ( $next_scheduled as $scheduled_time ) {
if ( abs( $scheduled_time - $args['timestamp'] ) <= 10 * MINUTE_IN_SECONDS ) {
return new WP_Error( 'event-already-scheduled', 'This event is ready scheduled', 400 );
}
@@ -204,13 +281,22 @@ class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endp
}
}
-// POST /sites/%s/cron/unschedule
-class Jetpack_JSON_API_Cron_Unschedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint {
+/**
+ * The cron unschedule ednpoint class.
+ *
+ * POST /sites/%s/cron/unschedule
+ */
+class Jetpack_JSON_API_Cron_Unschedule_Endpoint extends Jetpack_JSON_API_Cron_Endpoint { // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->input();
- if ( !isset( $args['hook'] ) ) {
+ if ( ! isset( $args['hook'] ) ) {
return new WP_Error( 'missing_argument', 'Please provide the hook argument', 400 );
}
@@ -230,7 +316,7 @@ class Jetpack_JSON_API_Cron_Unschedule_Endpoint extends Jetpack_JSON_API_Cron_En
if ( isset( $args['timestamp'] ) ) {
$next_schedulded = $this->get_schedules( $hook, $arguments );
- if ( in_array( $args['timestamp'], $next_schedulded ) ) {
+ if ( in_array( $args['timestamp'], $next_schedulded, true ) ) {
return new WP_Error( 'event-not-present', 'Unable to unschedule the event, the event doesn\'t exist', 400 );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-endpoint.php
index 07457d7d..ce53e85d 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-endpoint.php
@@ -1,28 +1,54 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-include JETPACK__PLUGIN_DIR . '/modules/module-info.php';
+require JETPACK__PLUGIN_DIR . '/modules/module-info.php';
/**
* Base class for Jetpack Endpoints, has the validate_call helper function.
*/
abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities;
+
+ /**
+ * Expected actions.
+ *
+ * @var array
+ */
protected $expected_actions = array();
- protected $action;
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action;
+ /**
+ * Callback function.
+ *
+ * @param string $path - the path.
+ * @param int $blog_id - the blog ID.
+ * @param object $object - parameter is for making the method signature compatible with its parent class method.
+ */
public function callback( $path = '', $blog_id = 0, $object = null ) {
- if ( is_wp_error( $error = $this->validate_call( $blog_id, $this->needed_capabilities ) ) ) {
+ $error = $this->validate_call( $blog_id, $this->needed_capabilities );
+ if ( is_wp_error( $error ) ) {
return $error;
}
- if ( is_wp_error( $error = $this->validate_input( $object ) ) ) {
+ $error = $this->validate_input( $object );
+ if ( is_wp_error( $error ) ) {
return $error;
}
if ( ! empty( $this->action ) ) {
- if( is_wp_error( $error = call_user_func( array( $this, $this->action ) ) ) ) {
+ $error = call_user_func( array( $this, $this->action ) );
+ if ( is_wp_error( $error ) ) {
return $error;
}
}
@@ -30,32 +56,47 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
return $this->result();
}
+ /**
+ * The result function.
+ */
abstract protected function result();
- protected function validate_input( $object ) {
+ /**
+ * Validate input.
+ *
+ * @param object $object - unused, for parent class compatability.
+ *
+ * @return bool
+ */
+ protected function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$args = $this->input();
- if( isset( $args['action'] ) && $args['action'] == 'update' ) {
+ if ( isset( $args['action'] ) && $args['action'] === 'update' ) {
$this->action = 'update';
}
- if ( preg_match( "/\/update\/?$/", $this->path ) ) {
+ if ( preg_match( '!/update/?$!', $this->path ) ) {
$this->action = 'update';
- } elseif( preg_match( "/\/install\/?$/", $this->path ) ) {
+ } elseif ( preg_match( '/\/install\/?$/', $this->path ) ) {
$this->action = 'install';
- } elseif( ! empty( $args['action'] ) ) {
- if( ! in_array( $args['action'], $this->expected_actions ) ) {
+ } elseif ( ! empty( $args['action'] ) ) {
+ if ( ! in_array( $args['action'], $this->expected_actions, true ) ) {
return new WP_Error( 'invalid_action', __( 'You must specify a valid action', 'jetpack' ) );
}
- $this->action = $args['action'];
+ $this->action = $args['action'];
}
return true;
}
/**
* Switches to the blog and checks current user capabilities.
+ *
+ * @param int $_blog_id - the blog ID.
+ * @param array $capability - the capabilities of the user.
+ * @param bool $check_validation - if we're checking the validation.
+ *
* @return bool|WP_Error a WP_Error object or true if things are good.
*/
protected function validate_call( $_blog_id, $capability, $check_validation = true ) {
@@ -64,7 +105,8 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
return $blog_id;
}
- if ( is_wp_error( $error = $this->check_capability( $capability ) ) ) {
+ $error = $this->check_capability( $capability );
+ if ( is_wp_error( $error ) ) {
return $error;
}
@@ -89,7 +131,9 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
}
/**
- * @param $capability
+ * Check capability.
+ *
+ * @param array $capability - the compatability.
*
* @return bool|WP_Error
*/
@@ -106,8 +150,7 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
$must_pass = ( isset( $capability['must_pass'] ) && is_int( $capability['must_pass'] ) ? $capability['must_pass'] : count( $capabilities ) );
$failed = array(); // store the failed capabilities
- $passed = 0; //
-
+ $passed = 0;
foreach ( $capabilities as $cap ) {
if ( current_user_can( $cap ) ) {
$passed ++;
@@ -125,7 +168,8 @@ abstract class Jetpack_JSON_API_Endpoint extends WPCOM_JSON_API_Endpoint {
);
}
} else {
- if ( !current_user_can( $capability ) ) {
+ if ( ! current_user_can( $capability ) ) {
+ // Translators: the capability that the user is not authorized for.
return new WP_Error( 'unauthorized', sprintf( __( 'This user is not authorized to %s on this blog.', 'jetpack' ), $capability ), 403 );
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-comment-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-comment-backup-endpoint.php
index e526902b..d03518ac 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-comment-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-comment-backup-endpoint.php
@@ -1,12 +1,34 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * The Get comment backup endpoint class.
+ *
+ * /sites/%s/comments/%d/backup -> $blog_id, $comment_id
+ */
class Jetpack_JSON_API_Get_Comment_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/comments/%d/backup -> $blog_id, $comment_id
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * The comment ID.
+ *
+ * @var int
+ */
protected $comment_id;
- function validate_input( $comment_id ) {
+ /**
+ * Validate input
+ *
+ * @param int $comment_id - the comment ID.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $comment_id ) {
if ( empty( $comment_id ) || ! is_numeric( $comment_id ) ) {
return new WP_Error( 'comment_id_not_specified', __( 'You must specify a Comment ID', 'jetpack' ), 400 );
}
@@ -16,6 +38,11 @@ class Jetpack_JSON_API_Get_Comment_Backup_Endpoint extends Jetpack_JSON_API_Endp
return true;
}
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
// Disable Sync as this is a read-only operation and triggered by sync activity.
\Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
@@ -43,7 +70,7 @@ class Jetpack_JSON_API_Get_Comment_Backup_Endpoint extends Jetpack_JSON_API_Endp
'user_id',
);
- $comment = array_intersect_key( $comment->to_array(), array_flip( $allowed_keys ) );
+ $comment = array_intersect_key( $comment->to_array(), array_flip( $allowed_keys ) );
$comment_meta = get_comment_meta( $comment['comment_ID'] );
return array(
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-database-object-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-database-object-backup-endpoint.php
index 05a5c7f8..cea6b6ad 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-database-object-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-database-object-backup-endpoint.php
@@ -1,17 +1,42 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Get Database object backup endpoint class.
+ *
+ * /sites/%s/database-object/backup -> $blog_id
+ */
class Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/database-object/backup -> $blog_id
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * Object type.
+ *
+ * @var string
+ */
protected $object_type;
+
+ /**
+ * Object ID.
+ *
+ * @var int
+ */
protected $object_id;
- // Full list of database objects that can be retrieved via this endpoint.
+ /**
+ * Full list of database objects that can be retrieved via this endpoint.
+ *
+ * @var array
+ */
protected $object_types = array(
- 'woocommerce_attribute' => array(
- 'table' => 'woocommerce_attribute_taxonomies',
- 'id_field' => 'attribute_id',
+ 'woocommerce_attribute' => array(
+ 'table' => 'woocommerce_attribute_taxonomies',
+ 'id_field' => 'attribute_id',
),
'woocommerce_downloadable_product_permission' => array(
@@ -19,32 +44,39 @@ class Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint extends Jetpack_JSON_
'id_field' => 'permission_id',
),
- 'woocommerce_order_item' => array(
+ 'woocommerce_order_item' => array(
'table' => 'woocommerce_order_items',
'id_field' => 'order_item_id',
'meta_type' => 'order_item',
),
- 'woocommerce_payment_token' => array(
+ 'woocommerce_payment_token' => array(
'table' => 'woocommerce_payment_tokens',
'id_field' => 'token_id',
'meta_type' => 'payment_token',
),
- 'woocommerce_tax_rate' => array(
+ 'woocommerce_tax_rate' => array(
'table' => 'woocommerce_tax_rates',
'id_field' => 'tax_rate_id',
'child_table' => 'woocommerce_tax_rate_locations',
'child_id_field' => 'tax_rate_id',
),
- 'woocommerce_webhook' => array(
+ 'woocommerce_webhook' => array(
'table' => 'wc_webhooks',
'id_field' => 'webhook_id',
),
);
- function validate_input( $object ) {
+ /**
+ * Validate input.
+ *
+ * @param object $object - unused.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$query_args = $this->query_args();
if ( empty( $query_args['object_type'] ) || empty( $query_args['object_id'] ) ) {
@@ -61,6 +93,11 @@ class Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint extends Jetpack_JSON_
return true;
}
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
global $wpdb;
@@ -71,8 +108,8 @@ class Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint extends Jetpack_JSON_
$id_field = $this->object_type['id_field'];
// Fetch the requested object
- $query = $wpdb->prepare( 'select * from `' . $table . '` where `' . $id_field . '` = %d', $this->object_id );
- $object = $wpdb->get_row( $query );
+ $query = $wpdb->prepare( 'select * from `' . $table . '` where `' . $id_field . '` = %d', $this->object_id ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
+ $object = $wpdb->get_row( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( empty( $object ) ) {
return new WP_Error( 'object_not_found', __( 'Object not found', 'jetpack' ), 404 );
@@ -90,8 +127,8 @@ class Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint extends Jetpack_JSON_
$child_table = $wpdb->prefix . $this->object_type['child_table'];
$child_id_field = $this->object_type['child_id_field'];
- $query = $wpdb->prepare( 'select * from `' . $child_table . '` where `' . $child_id_field . '` = %d', $this->object_id );
- $result[ 'children' ] = $wpdb->get_results( $query );
+ $query = $wpdb->prepare( 'select * from `' . $child_table . '` where `' . $child_id_field . '` = %d', $this->object_id ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
+ $result['children'] = $wpdb->get_results( $query ); //phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
return $result;
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-option-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-option-backup-endpoint.php
index 642e3139..7b88603b 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-option-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-option-backup-endpoint.php
@@ -1,12 +1,33 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Get option backup endpoint.
+ *
+ * /sites/%s/options/backup -> $blog_id
+ */
class Jetpack_JSON_API_Get_Option_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/options/backup -> $blog_id
-
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * Option names.
+ *
+ * @var string
+ */
protected $option_names;
- function validate_input( $object ) {
+ /**
+ * Validate input.
+ *
+ * @param object $object - unused.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$query_args = $this->query_args();
if ( empty( $query_args['name'] ) ) {
@@ -22,6 +43,9 @@ class Jetpack_JSON_API_Get_Option_Backup_Endpoint extends Jetpack_JSON_API_Endpo
return true;
}
+ /**
+ * The result.
+ */
protected function result() {
// Disable Sync as this is a read-only operation and triggered by sync activity.
\Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
@@ -30,6 +54,13 @@ class Jetpack_JSON_API_Get_Option_Backup_Endpoint extends Jetpack_JSON_API_Endpo
return array( 'options' => $options );
}
+ /**
+ * Get options row.
+ *
+ * @param string $name - name of the row.
+ *
+ * @return object|null Database query result or null on failure.
+ */
private function get_option_row( $name ) {
global $wpdb;
return $wpdb->get_row( $wpdb->prepare( "select * from `{$wpdb->options}` where option_name = %s", $name ) );
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
index c6102dfc..e73c11cd 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-post-backup-endpoint.php
@@ -1,12 +1,32 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Get post backup endpoint class.
+ *
+ * /sites/%s/posts/%d/backup -> $blog_id, $post_id
+ */
class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/posts/%d/backup -> $blog_id, $post_id
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * The post ID.
+ *
+ * @var int
+ */
protected $post_id;
- function validate_input( $post_id ) {
+ /**
+ * Validate the input.
+ *
+ * @param int $post_id - the post ID.
+ */
+ public function validate_input( $post_id ) {
if ( empty( $post_id ) || ! is_numeric( $post_id ) ) {
return new WP_Error( 'post_id_not_specified', __( 'You must specify a Post ID', 'jetpack' ), 400 );
}
@@ -16,6 +36,11 @@ class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoin
return true;
}
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
global $wpdb;
@@ -28,14 +53,17 @@ class Jetpack_JSON_API_Get_Post_Backup_Endpoint extends Jetpack_JSON_API_Endpoin
}
// Fetch terms associated with this post object
- $terms = $wpdb->get_results( $wpdb->prepare(
- "SELECT term_taxonomy_id, term_order FROM {$wpdb->term_relationships} WHERE object_id = %d;", $post->ID
- ) );
+ $terms = $wpdb->get_results(
+ $wpdb->prepare(
+ "SELECT term_taxonomy_id, term_order FROM {$wpdb->term_relationships} WHERE object_id = %d;",
+ $post->ID
+ )
+ );
return array(
- 'post' => (array)$post,
+ 'post' => (array) $post,
'meta' => get_post_meta( $post->ID ),
- 'terms' => (array)$terms,
+ 'terms' => (array) $terms,
);
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-term-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-term-backup-endpoint.php
index 21882ddd..3774bd37 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-term-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-term-backup-endpoint.php
@@ -1,12 +1,34 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Get Term backup endpoint class.
+ *
+ * /sites/%s/terms/%d/backup -> $blog_id, $term_id
+ */
class Jetpack_JSON_API_Get_Term_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/terms/%d/backup -> $blog_id, $term_id
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * The term ID.
+ *
+ * @var int
+ */
protected $term_id;
- function validate_input( $term_id ) {
+ /**
+ * Validate input.
+ *
+ * @param int $term_id - the term ID.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $term_id ) {
if ( empty( $term_id ) || ! is_numeric( $term_id ) ) {
return new WP_Error( 'term_id_not_specified', __( 'You must specify a Term ID', 'jetpack' ), 400 );
}
@@ -16,6 +38,11 @@ class Jetpack_JSON_API_Get_Term_Backup_Endpoint extends Jetpack_JSON_API_Endpoin
return true;
}
+ /**
+ * Return the result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
// Disable Sync as this is a read-only operation and triggered by sync activity.
\Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php
index a57e4579..e61dfa72 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-get-user-backup-endpoint.php
@@ -1,12 +1,34 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Get user Backup endpoint class.
+ *
+ * /sites/%s/users/%d/backup -> $blog_id, $user_id
+ */
class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoint {
- // /sites/%s/users/%d/backup -> $blog_id, $user_id
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array(); // This endpoint is only accessible using a site token
+
+ /**
+ * The user ID.
+ *
+ * @var int
+ */
protected $user_id;
- function validate_input( $user_id ) {
+ /**
+ * Validate input.
+ *
+ * @param int $user_id - the user ID.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $user_id ) {
if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
return new WP_Error( 'user_id_not_specified', __( 'You must specify a User ID', 'jetpack' ), 400 );
}
@@ -16,6 +38,11 @@ class Jetpack_JSON_API_Get_User_Backup_Endpoint extends Jetpack_JSON_API_Endpoin
return true;
}
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
// Disable Sync as this is a read-only operation and triggered by sync activity.
\Automattic\Jetpack\Sync\Actions::mark_sync_read_only();
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php
index 75a3b04d..b44bd3e9 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php
@@ -1,10 +1,23 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * JPS WooCommerce connect endpoint.
+ */
class Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'manage_options';
- function result() {
+ /**
+ * The result.
+ *
+ * @return array|WP_Error
+ */
+ public function result() {
$input = $this->input();
$helper_data = get_option( 'woocommerce_helper_data', array() );
@@ -34,7 +47,14 @@ class Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint extends Jetpack_JSON_API
);
}
- function validate_input( $object ) {
+ /**
+ * Validate input.
+ *
+ * @param object $object - the object we're validating.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) {
$input = $this->input();
if ( empty( $input['access_token'] ) ) {
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php
index ba6ea7cf..7285aa82 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-log-endpoint.php
@@ -1,16 +1,30 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Jetpack log endpoint class.
+ *
+ * GET /sites/%s/jetpack-log
+ */
class Jetpack_JSON_API_Jetpack_Log_Endpoint extends Jetpack_JSON_API_Endpoint {
- // GET /sites/%s/jetpack-log
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = 'manage_options';
+ /**
+ * The result.
+ *
+ * @return array
+ */
protected function result() {
- $args = $this->input();
- $event = ( isset( $args['event'] ) && is_string( $args['event'] ) ) ? $code : false;
- $num = ( isset( $args['num'] ) ) ? (int) $num : false;
+ $args = $this->input();
+ $event = ( isset( $args['event'] ) && is_string( $args['event'] ) ) ? $args['event'] : false;
+ $num = ( isset( $args['num'] ) ) ? (int) $args['num'] : false;
return array(
- 'log' => Jetpack::get_log( $event, $num )
+ 'log' => Jetpack::get_log( $event, $num ),
);
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-maybe-auto-update-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-maybe-auto-update-endpoint.php
index 5b368760..cc027789 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-maybe-auto-update-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-maybe-auto-update-endpoint.php
@@ -1,16 +1,37 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Auto update endpoint class.
+ *
+ * POST /sites/%s/maybe_auto_update
+ */
class Jetpack_JSON_API_Maybe_Auto_Update_Endpoint extends Jetpack_JSON_API_Endpoint {
- // POST /sites/%s/maybe_auto_update
+
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' );
+ /**
+ * Update results.
+ *
+ * @var array
+ */
protected $update_results = array();
+ /**
+ * The result.
+ *
+ * @return array
+ */
protected function result() {
add_action( 'automatic_updates_complete', array( $this, 'get_update_results' ), 100, 1 );
wp_maybe_auto_update();
+ $result = array();
$result['log'] = $this->update_results;
if ( empty( $result['log'] ) ) {
@@ -19,12 +40,16 @@ class Jetpack_JSON_API_Maybe_Auto_Update_Endpoint extends Jetpack_JSON_API_Endpo
if ( $possible_reasons_for_failure ) {
$result['log']['error'] = $possible_reasons_for_failure;
}
-
}
return $result;
}
+ /**
+ * Get update results.
+ *
+ * @param array $results - the results.
+ */
public function get_update_results( $results ) {
$this->update_results = $results;
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php
index 2f56f1ee..2a9fdd1f 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-endpoint.php
@@ -1,15 +1,30 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Base class for working with Jetpack Modules.
*/
abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * The modules.
+ *
+ * @var array
+ */
protected $modules = array();
+ /**
+ * If we're working in bulk.
+ *
+ * @var boolean
+ */
protected $bulk = true;
- static $_response_format = array(
+ /**
+ * Response format.
+ *
+ * @var array
+ */
+ public static $_response_format = array( // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
'id' => '(string) The module\'s ID',
'active' => '(boolean) The module\'s status.',
'name' => '(string) The module\'s name.',
@@ -22,6 +37,11 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
'override' => '(string) The module\'s override. Empty if no override, otherwise \'active\' or \'inactive\'',
);
+ /**
+ * The result.
+ *
+ * @return array
+ */
protected function result() {
$modules = $this->get_modules();
@@ -35,12 +55,13 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
}
/**
- * Walks through either the submitted modules or list of themes and creates the global array
- * @param $theme
+ * Walks through either the submitted modules or list of themes and creates the global array.
+ *
+ * @param string $module - the modules.
*
- * @return bool
+ * @return bool|WP_Error
*/
- protected function validate_input( $module) {
+ protected function validate_input( $module ) {
$args = $this->input();
// lets set what modules were requested, and validate them
if ( ! isset( $module ) || empty( $module ) ) {
@@ -55,10 +76,11 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
}
} else {
$this->modules[] = urldecode( $module );
- $this->bulk = false;
+ $this->bulk = false;
}
- if ( is_wp_error( $error = $this->validate_modules() ) ) {
+ $error = $this->validate_modules();
+ if ( is_wp_error( $error ) ) {
return $error;
}
@@ -67,21 +89,30 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
/**
* Walks through submitted themes to make sure they are valid
+ *
* @return bool|WP_Error
*/
protected function validate_modules() {
foreach ( $this->modules as $module ) {
if ( ! Jetpack::is_module( $module ) ) {
+ // Translators: the module that's not found.
return new WP_Error( 'unknown_jetpack_module', sprintf( __( 'Module not found: `%s`.', 'jetpack' ), $module ), 404 );
}
}
return true;
}
+ /**
+ * Format the module.
+ *
+ * @param string $module_slug - the module slug.
+ *
+ * @return array
+ */
protected static function format_module( $module_slug ) {
$module_data = Jetpack::get_module( $module_slug );
- $module = array();
+ $module = array();
$module['id'] = $module_slug;
$module['active'] = Jetpack::is_module_active( $module_slug );
$module['name'] = $module_data['name'];
@@ -93,19 +124,20 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
$module['module_tags'] = $module_data['module_tags'];
$overrides_instance = Jetpack_Modules_Overrides::instance();
- $module['override'] = $overrides_instance->get_module_override( $module_slug );
+ $module['override'] = $overrides_instance->get_module_override( $module_slug );
// Fetch the HTML formatted long description
ob_start();
/** This action is documented in class.jetpack-modules-list-table.php */
do_action( 'jetpack_module_more_info_' . $module_slug );
- $module['description'] = ob_get_clean();
+ $module['description'] = ob_get_clean();
return $module;
}
/**
* Format a list of modules for public display, using the supplied offset and limit args
+ *
* @uses WPCOM_JSON_API_Endpoint::query_args()
* @return array Public API modules objects
*/
@@ -114,10 +146,12 @@ abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoi
// do offset & limit - we've already returned a 400 error if they're bad numbers
$args = $this->query_args();
- if ( isset( $args['offset'] ) )
+ if ( isset( $args['offset'] ) ) {
$modules = array_slice( $modules, (int) $args['offset'] );
- if ( isset( $args['limit'] ) )
+ }
+ if ( isset( $args['limit'] ) ) {
$modules = array_slice( $modules, 0, (int) $args['limit'] );
+ }
return array_map( array( $this, 'format_module' ), $modules );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-get-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-get-endpoint.php
index 28a70dba..279c60d6 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-get-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-get-endpoint.php
@@ -1,6 +1,15 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * The Modules get endpoint.
+ *
+ * /sites/%s/jetpack/modules/%s
+ */
class Jetpack_JSON_API_Modules_Get_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
- // GET /sites/%s/jetpack/modules/%s
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'jetpack_manage_modules';
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-list-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-list-endpoint.php
index 2ed4dbdd..f89c272d 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-list-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-list-endpoint.php
@@ -1,11 +1,27 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileNames
+/**
+ * Modules list endpoint.
+ *
+ * GET /sites/%s/jetpack/modules
+ */
class Jetpack_JSON_API_Modules_List_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
- // GET /sites/%s/jetpack/modules
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'jetpack_manage_modules';
- public function validate_input( $module ) {
+ /**
+ * Validate the input.
+ *
+ * @param string $module - the module.
+ *
+ * @return bool
+ */
+ public function validate_input( $module ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$this->modules = Jetpack::get_available_modules();
return true;
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php
index e1562f50..8cb7bb84 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-modules-modify-endpoint.php
@@ -1,13 +1,30 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Modules modify endpoint class.
+ *
+ * POST /sites/%s/jetpack/modules/%s/activate
+ * POST /sites/%s/jetpack/modules/%s
+ * POST /sites/%s/jetpack/modules
+ */
class Jetpack_JSON_API_Modules_Modify_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
- // POST /sites/%s/jetpack/modules/%s/activate
- // POST /sites/%s/jetpack/modules/%s
- // POST /sites/%s/jetpack/modules
-
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'activate_plugins';
- protected $action = 'default_action';
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action = 'default_action';
+
+ /**
+ * The default action.
+ */
public function default_action() {
$args = $this->input();
if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) {
@@ -21,15 +38,22 @@ class Jetpack_JSON_API_Modules_Modify_Endpoint extends Jetpack_JSON_API_Modules_
return true;
}
+ /**
+ * Activate module.
+ *
+ * @return bool|WP_Error
+ */
protected function activate_module() {
foreach ( $this->modules as $module ) {
if ( Jetpack::is_module_active( $module ) ) {
- $error = $this->log[ $module ][] = __( 'The Jetpack Module is already activated.', 'jetpack' );
+ $error = __( 'The Jetpack Module is already activated.', 'jetpack' );
+ $this->log[ $module ][] = $error;
continue;
}
$result = Jetpack::activate_module( $module, false, false );
if ( false === $result || ! Jetpack::is_module_active( $module ) ) {
- $error = $this->log[ $module ][] = __( 'There was an error while activating the module.', 'jetpack' );
+ $error = __( 'There was an error while activating the module.', 'jetpack' );
+ $this->log[ $module ][] = $error;
}
}
@@ -40,15 +64,22 @@ class Jetpack_JSON_API_Modules_Modify_Endpoint extends Jetpack_JSON_API_Modules_
return true;
}
+ /**
+ * Deactivate module.
+ *
+ * @return bool|WP_Error
+ */
protected function deactivate_module() {
foreach ( $this->modules as $module ) {
if ( ! Jetpack::is_module_active( $module ) ) {
- $error = $this->log[ $module ][] = __( 'The Jetpack Module is already deactivated.', 'jetpack' );
+ $error = __( 'The Jetpack Module is already deactivated.', 'jetpack' );
+ $this->log[ $module ] = $error;
continue;
}
$result = Jetpack::deactivate_module( $module );
if ( false === $result || Jetpack::is_module_active( $module ) ) {
- $error = $this->log[ $module ][] = __( 'There was an error while deactivating the module.', 'jetpack' );
+ $error = __( 'There was an error while deactivating the module.', 'jetpack' );
+ $this->log[ $module ] = $error;
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php
index 94b6ddd3..166f5b88 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-delete-endpoint.php
@@ -1,4 +1,5 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+
// POST /sites/%s/plugins/%s/delete
new Jetpack_JSON_API_Plugins_Delete_Endpoint(
array(
@@ -47,24 +48,46 @@ new Jetpack_JSON_API_Plugins_Delete_Endpoint(
)
);
+/**
+ * Plugins delete endpoint class.
+ *
+ * POST /sites/%s/plugins/%s/delete
+ */
class Jetpack_JSON_API_Plugins_Delete_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // POST /sites/%s/plugins/%s/delete
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'delete_plugins';
+
+ /**
+ * The action.
+ *
+ * @var string
+ */
protected $action = 'delete';
+ /**
+ * The delete function.
+ *
+ * @return bool|WP_Error
+ */
protected function delete() {
foreach ( $this->plugins as $plugin ) {
if ( Jetpack::is_plugin_active( $plugin ) ) {
- $error = $this->log[ $plugin ][] = __( 'You cannot delete a plugin while it is active on the main site.', 'jetpack' );
+ $error = __( 'You cannot delete a plugin while it is active on the main site.', 'jetpack' );
+ $this->log[ $plugin ][] = $error;
continue;
}
$result = delete_plugins( array( $plugin ) );
if ( is_wp_error( $result ) ) {
- $error = $this->log[ $plugin ][] = $result->get_error_message();
+ $error = $result->get_error_message();
+ $this->log[ $plugin ][] = $error;
} else {
$this->log[ $plugin ][] = 'Plugin deleted';
}
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 95a6645c..4c1e1d76 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
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Constants;
use Automattic\Jetpack\Sync\Functions;
@@ -8,52 +8,88 @@ use Automattic\Jetpack\Sync\Functions;
*/
abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * Plugins.
+ *
+ * @var array
+ */
protected $plugins = array();
+ /**
+ * If the plugin is network wide.
+ *
+ * @var boolean
+ */
protected $network_wide = false;
+ /**
+ * If we're working in bulk.
+ *
+ * @var boolean
+ */
protected $bulk = true;
+
+ /**
+ * The log.
+ *
+ * @var array
+ */
protected $log;
- static $_response_format = array(
- 'id' => '(safehtml) The plugin\'s ID',
- 'slug' => '(safehtml) The plugin\'s .org slug',
- 'active' => '(boolean) The plugin status.',
- 'update' => '(object) The plugin update info.',
- 'name' => '(safehtml) The name of the plugin.',
- 'plugin_url' => '(url) Link to the plugin\'s web site.',
- 'version' => '(safehtml) The plugin version number.',
- 'description' => '(safehtml) Description of what the plugin does and/or notes from the author',
- 'author' => '(safehtml) The author\'s name',
- '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',
+ /**
+ * Response format.
+ *
+ * @var array
+ */
+ public static $_response_format = array( // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
+ 'id' => '(safehtml) The plugin\'s ID',
+ 'slug' => '(safehtml) The plugin\'s .org slug',
+ 'active' => '(boolean) The plugin status.',
+ 'update' => '(object) The plugin update info.',
+ 'name' => '(safehtml) The name of the plugin.',
+ 'plugin_url' => '(url) Link to the plugin\'s web site.',
+ 'version' => '(safehtml) The plugin version number.',
+ 'description' => '(safehtml) Description of what the plugin does and/or notes from the author',
+ 'author' => '(safehtml) The author\'s name',
+ '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.',
- 'action_links' => '(array) An array of action links that the plugin uses.',
+ '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.',
+ 'action_links' => '(array) An array of action links that the plugin uses.',
);
- static $_response_format_v1_2 = array(
- 'slug' => '(safehtml) The plugin\'s .org slug',
- 'active' => '(boolean) The plugin status.',
- 'update' => '(object) The plugin update info.',
- 'name' => '(safehtml) The plugin\'s ID',
- 'display_name' => '(safehtml) The name of the plugin.',
- 'version' => '(safehtml) The plugin version number.',
- 'description' => '(safehtml) Description of what the plugin does and/or notes from the author',
- 'author' => '(safehtml) The author\'s name',
- 'author_url' => '(url) The authors web site address',
- 'plugin_url' => '(url) Link to the plugin\'s web site.',
- 'network' => '(boolean) Whether the plugin can only be activated network wide.',
- 'autoupdate' => '(boolean) Whether the plugin is automatically updated',
+ /**
+ * Response format v1_2
+ *
+ * @var array
+ */
+ public static $_response_format_v1_2 = array( // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
+ 'slug' => '(safehtml) The plugin\'s .org slug',
+ 'active' => '(boolean) The plugin status.',
+ 'update' => '(object) The plugin update info.',
+ 'name' => '(safehtml) The plugin\'s ID',
+ 'display_name' => '(safehtml) The name of the plugin.',
+ 'version' => '(safehtml) The plugin version number.',
+ 'description' => '(safehtml) Description of what the plugin does and/or notes from the author',
+ 'author' => '(safehtml) The author\'s name',
+ 'author_url' => '(url) The authors web site address',
+ 'plugin_url' => '(url) Link to the plugin\'s web site.',
+ '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',
- 'uninstallable' => '(boolean) Whether the plugin is unistallable.',
- 'action_links' => '(array) An array of action links that the plugin uses.',
- 'log' => '(array:safehtml) An array of update log strings.',
+ 'uninstallable' => '(boolean) Whether the plugin is unistallable.',
+ 'action_links' => '(array) An array of action links that the plugin uses.',
+ 'log' => '(array:safehtml) An array of update log strings.',
);
+ /**
+ * The result.
+ *
+ * @return array
+ */
protected function result() {
$plugins = $this->get_plugins();
@@ -66,13 +102,22 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
}
+ /**
+ * Validate the input.
+ *
+ * @param string $plugin - the plugin we're validating.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_input( $plugin ) {
- if ( is_wp_error( $error = parent::validate_input( $plugin ) ) ) {
+ $error = parent::validate_input( $plugin );
+ if ( is_wp_error( $error ) ) {
return $error;
}
- if ( is_wp_error( $error = $this->validate_network_wide() ) ) {
+ $error = $this->validate_network_wide();
+ if ( is_wp_error( $error ) ) {
return $error;
}
@@ -89,31 +134,33 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$this->plugins[] = $args['plugins'];
}
} else {
- $this->bulk = false;
+ $this->bulk = false;
$this->plugins[] = urldecode( $plugin );
}
- if ( is_wp_error( $error = $this->validate_plugins() ) ) {
+ $error = $this->validate_plugins();
+ if ( is_wp_error( $error ) ) {
return $error;
- };
+ }
return true;
}
/**
* Walks through submitted plugins to make sure they are valid
+ *
* @return bool|WP_Error
*/
protected function validate_plugins() {
if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
- return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ));
+ return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ) );
}
- foreach( $this->plugins as $index => $plugin ) {
- if ( ! preg_match( "/\.php$/", $plugin ) ) {
- $plugin = $plugin . '.php';
+ foreach ( $this->plugins as $index => $plugin ) {
+ if ( ! preg_match( '/\.php$/', $plugin ) ) {
+ $plugin = $plugin . '.php';
$this->plugins[ $index ] = $plugin;
}
- $valid = $this->validate_plugin( urldecode( $plugin ) ) ;
+ $valid = $this->validate_plugin( urldecode( $plugin ) );
if ( is_wp_error( $valid ) ) {
return $valid;
}
@@ -122,12 +169,20 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return true;
}
+ /**
+ * Format the plugin.
+ *
+ * @param string $plugin_file - the plugin file.
+ * @param array $plugin_data - the plugin data.
+ *
+ * @return array
+ */
protected function format_plugin( $plugin_file, $plugin_data ) {
if ( version_compare( $this->min_version, '1.2', '>=' ) ) {
return $this->format_plugin_v1_2( $plugin_file, $plugin_data );
}
- $plugin = array();
- $plugin['id'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
+ $plugin = array();
+ $plugin['id'] = preg_replace( '/(.+)\.php$/', '$1', $plugin_file );
$plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug( $plugin_file );
$plugin['active'] = Jetpack::is_plugin_active( $plugin_file );
$plugin['name'] = $plugin_data['Name'];
@@ -138,8 +193,8 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$plugin['author_url'] = $plugin_data['AuthorURI'];
$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' ) );
- $action_link = $this->get_plugin_action_links( $plugin_file );
+ $plugin['next_autoupdate'] = gmdate( 'Y-m-d H:i:s', wp_next_scheduled( 'wp_maybe_auto_update' ) );
+ $action_link = $this->get_plugin_action_links( $plugin_file );
if ( ! empty( $action_link ) ) {
$plugin['action_links'] = $action_link;
}
@@ -151,35 +206,43 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$autoupdate = ( new WP_Automatic_Updater() )->should_update( 'plugin', (object) $plugin, WP_PLUGIN_DIR );
$plugin['autoupdate'] = $autoupdate;
- $autoupdate_translation = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ) );
+ $autoupdate_translation = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ), true );
$plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation || Jetpack_Options::get_option( 'autoupdate_translations', false );
- $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
+ $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
if ( is_multisite() ) {
$plugin['network_active'] = is_plugin_active_for_network( $plugin_file );
}
- if ( ! empty ( $this->log[ $plugin_file ] ) ) {
+ if ( ! empty( $this->log[ $plugin_file ] ) ) {
$plugin['log'] = $this->log[ $plugin_file ];
}
return $plugin;
}
+ /**
+ * Format the plugin for v1_2.
+ *
+ * @param string $plugin_file - the plugin file.
+ * @param array $plugin_data - the plugin data.
+ *
+ * @return array
+ */
protected function format_plugin_v1_2( $plugin_file, $plugin_data ) {
- $plugin = array();
- $plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug( $plugin_file );
- $plugin['active'] = Jetpack::is_plugin_active( $plugin_file );
- $plugin['name'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
- $plugin['display_name'] = $plugin_data['Name'];
- $plugin['plugin_url'] = $plugin_data['PluginURI'];
- $plugin['version'] = $plugin_data['Version'];
- $plugin['description'] = $plugin_data['Description'];
- $plugin['author'] = $plugin_data['Author'];
- $plugin['author_url'] = $plugin_data['AuthorURI'];
- $plugin['network'] = $plugin_data['Network'];
- $plugin['update'] = $this->get_plugin_updates( $plugin_file );
- $action_link = $this->get_plugin_action_links( $plugin_file );
+ $plugin = array();
+ $plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug( $plugin_file );
+ $plugin['active'] = Jetpack::is_plugin_active( $plugin_file );
+ $plugin['name'] = preg_replace( '/(.+)\.php$/', '$1', $plugin_file );
+ $plugin['display_name'] = $plugin_data['Name'];
+ $plugin['plugin_url'] = $plugin_data['PluginURI'];
+ $plugin['version'] = $plugin_data['Version'];
+ $plugin['description'] = $plugin_data['Description'];
+ $plugin['author'] = $plugin_data['Author'];
+ $plugin['author_url'] = $plugin_data['AuthorURI'];
+ $plugin['network'] = $plugin_data['Network'];
+ $plugin['update'] = $this->get_plugin_updates( $plugin_file );
+ $action_link = $this->get_plugin_action_links( $plugin_file );
if ( ! empty( $action_link ) ) {
$plugin['action_links'] = $action_link;
}
@@ -191,37 +254,47 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
$autoupdate = ( new WP_Automatic_Updater() )->should_update( 'plugin', (object) $plugin, WP_PLUGIN_DIR );
$plugin['autoupdate'] = $autoupdate;
- $autoupdate_translation = $this->plugin_has_translations_autoupdates_enabled( $plugin_file );
+ $autoupdate_translation = $this->plugin_has_translations_autoupdates_enabled( $plugin_file );
$plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation || Jetpack_Options::get_option( 'autoupdate_translations', false );
- $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
+ $plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
if ( is_multisite() ) {
$plugin['network_active'] = is_plugin_active_for_network( $plugin_file );
}
- if ( ! empty ( $this->log[ $plugin_file ] ) ) {
+ if ( ! empty( $this->log[ $plugin_file ] ) ) {
$plugin['log'] = $this->log[ $plugin_file ];
}
return $plugin;
}
+ /**
+ * Check if plugin has autoupdates for translations enabled.
+ *
+ * @param string $plugin_file - the plugin file.
+ *
+ * @return bool
+ */
protected function plugin_has_translations_autoupdates_enabled( $plugin_file ) {
- return (bool) in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ) );
+ return (bool) in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ), true );
}
+ /**
+ * Get file mod capabilities.
+ */
protected function get_file_mod_capabilities() {
- $reasons_can_not_autoupdate = array();
+ $reasons_can_not_autoupdate = array();
$reasons_can_not_modify_files = array();
$has_file_system_write_access = Functions::file_system_write_access();
if ( ! $has_file_system_write_access ) {
- $reasons_can_not_modify_files['has_no_file_system_write_access'] = __( 'The file permissions on this host prevent editing files.', 'jetpack' );
+ $reasons_can_not_modify_files['has_no_file_system_write_access'] = __( 'The file permissions on this host prevent editing files.', 'jetpack' );
}
- $disallow_file_mods = Constants::get_constant('DISALLOW_FILE_MODS' );
+ $disallow_file_mods = Constants::get_constant( 'DISALLOW_FILE_MODS' );
if ( $disallow_file_mods ) {
- $reasons_can_not_modify_files['disallow_file_mods'] = __( 'File modifications are explicitly disabled by a site administrator.', 'jetpack' );
+ $reasons_can_not_modify_files['disallow_file_mods'] = __( 'File modifications are explicitly disabled by a site administrator.', 'jetpack' );
}
$automatic_updater_disabled = Constants::get_constant( 'AUTOMATIC_UPDATER_DISABLED' );
@@ -232,16 +305,16 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
if ( is_multisite() ) {
// is it the main network ? is really is multi network
if ( Jetpack::is_multi_network() ) {
- $reasons_can_not_modify_files['is_multi_network'] = __( 'Multi network install are not supported.', 'jetpack' );
+ $reasons_can_not_modify_files['is_multi_network'] = __( 'Multi network install are not supported.', 'jetpack' );
}
// Is the site the main site here.
if ( ! is_main_site() ) {
- $reasons_can_not_modify_files['is_sub_site'] = __( 'The site is not the main network site', 'jetpack' );
+ $reasons_can_not_modify_files['is_sub_site'] = __( 'The site is not the main network site', 'jetpack' );
}
}
$file_mod_capabilities = array(
- 'modify_files' => (bool) empty( $reasons_can_not_modify_files ), // install, remove, update
+ 'modify_files' => (bool) empty( $reasons_can_not_modify_files ), // install, remove, update
'autoupdate_files' => (bool) empty( $reasons_can_not_modify_files ) && empty( $reasons_can_not_autoupdate ), // enable autoupdates
);
@@ -255,6 +328,11 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return $file_mod_capabilities;
}
+ /**
+ * Get plugins.
+ *
+ * @return array
+ */
protected function get_plugins() {
$plugins = array();
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
@@ -299,6 +377,11 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return $plugins;
}
+ /**
+ * Validate network wide.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_network_wide() {
$args = $this->input();
@@ -318,25 +401,39 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return true;
}
-
+ /**
+ * Validate the plugin.
+ *
+ * @param string $plugin - the plugin we're validating.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_plugin( $plugin ) {
- if ( ! isset( $plugin) || empty( $plugin ) ) {
+ if ( ! isset( $plugin ) || empty( $plugin ) ) {
return new WP_Error( 'missing_plugin', __( 'You are required to specify a plugin to activate.', 'jetpack' ), 400 );
}
- if ( is_wp_error( $error = validate_plugin( $plugin ) ) ) {
- return new WP_Error( 'unknown_plugin', $error->get_error_messages() , 404 );
+ $error = validate_plugin( $plugin );
+ if ( is_wp_error( $error ) ) {
+ return new WP_Error( 'unknown_plugin', $error->get_error_messages(), 404 );
}
return true;
}
+ /**
+ * Get plugin updates.
+ *
+ * @param string $plugin_file - the plugin file.
+ *
+ * @return object|null
+ */
protected function get_plugin_updates( $plugin_file ) {
$plugin_updates = get_plugin_updates();
if ( isset( $plugin_updates[ $plugin_file ] ) ) {
- $update = $plugin_updates[ $plugin_file ]->update;
+ $update = $plugin_updates[ $plugin_file ]->update;
$cleaned_update = array();
- foreach( (array) $update as $update_key => $update_value ) {
+ foreach ( (array) $update as $update_key => $update_value ) {
switch ( $update_key ) {
case 'id':
case 'slug':
@@ -356,6 +453,13 @@ abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoi
return null;
}
+ /**
+ * Get plugin action links.
+ *
+ * @param string $plugin_file - the plugin file.
+ *
+ * @return array
+ */
protected function get_plugin_action_links( $plugin_file ) {
return Functions::get_plugins_action_links( $plugin_file );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-get-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-get-endpoint.php
index 6d2dd612..02fb18d1 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-get-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-get-endpoint.php
@@ -1,5 +1,8 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * JSON API plugins get endpoint.
+ */
new Jetpack_JSON_API_Plugins_Get_Endpoint(
array(
'description' => 'Get the Plugin data.',
@@ -22,8 +25,19 @@ new Jetpack_JSON_API_Plugins_Get_Endpoint(
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello',
)
);
-// no v1.2 version since it is .com only
+
+/**
+ * Plugins get endpoint class.
+ *
+ * GET /sites/%s/plugins/%s
+ *
+ * No v1.2 version since it is .com only
+ */
class Jetpack_JSON_API_Plugins_Get_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // GET /sites/%s/plugins/%s
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'activate_plugins';
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php
index 77e09c88..10c22a33 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-install-endpoint.php
@@ -1,7 +1,9 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-include_once ABSPATH . 'wp-admin/includes/file.php';
+use Automattic\Jetpack\Plugins_Installer;
+
+require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+require_once ABSPATH . 'wp-admin/includes/file.php';
// POST /sites/%s/plugins/%s/install
new Jetpack_JSON_API_Plugins_Install_Endpoint(
array(
@@ -50,17 +52,36 @@ new Jetpack_JSON_API_Plugins_Install_Endpoint(
)
);
+/**
+ * Plugins install enedpoint class.
+ *
+ * POST /sites/%s/plugins/%s/install
+ */
class Jetpack_JSON_API_Plugins_Install_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // POST /sites/%s/plugins/%s/install
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'install_plugins';
+
+ /**
+ * The action.
+ *
+ * @var string
+ */
protected $action = 'install';
+ /**
+ * Installation.
+ *
+ * @return bool|WP_Error
+ */
protected function install() {
- jetpack_require_lib( 'plugins' );
$result = '';
foreach ( $this->plugins as $index => $slug ) {
- $result = Jetpack_Plugins::install_plugin( $slug );
+ $result = Plugins_Installer::install_plugin( $slug );
if ( is_wp_error( $result ) ) {
$this->log[ $slug ][] = $result->get_error_message();
if ( ! $this->bulk ) {
@@ -74,23 +95,26 @@ class Jetpack_JSON_API_Plugins_Install_Endpoint extends Jetpack_JSON_API_Plugins
}
// No errors, install worked. Now replace the slug with the actual plugin id
- $this->plugins[$index] = Jetpack_Plugins::get_plugin_id_by_slug( $slug );
+ $this->plugins[ $index ] = Plugins_Installer::get_plugin_id_by_slug( $slug );
return true;
}
+ /**
+ * Validate the plugins.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_plugins() {
if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ) );
}
- jetpack_require_lib( 'plugins' );
- foreach ( $this->plugins as $index => $slug ) {
+ foreach ( $this->plugins as $slug ) {
// make sure it is not already installed
- if ( Jetpack_Plugins::get_plugin_id_by_slug( $slug ) ) {
+ if ( Plugins_Installer::get_plugin_id_by_slug( $slug ) ) {
return new WP_Error( 'plugin_already_installed', __( 'The plugin is already installed', 'jetpack' ) );
}
-
}
return true;
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-list-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-list-endpoint.php
index 5f59b687..e354a29f 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-list-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-list-endpoint.php
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
new Jetpack_JSON_API_Plugins_List_Endpoint(
array(
@@ -23,11 +23,30 @@ new Jetpack_JSON_API_Plugins_List_Endpoint(
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins',
)
);
-// No v1.2 versions since they are .com only
+
+/**
+ * Plugins list endpoint class.
+ *
+ * GET /sites/%s/plugins
+ *
+ * No v1.2 versions since they are .com only
+ */
class Jetpack_JSON_API_Plugins_List_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // GET /sites/%s/plugins
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'activate_plugins';
- public function validate_input( $plugin ) {
+
+ /**
+ * Validate the input.
+ *
+ * @param string $plugin - the plugin.
+ *
+ * @return bool
+ */
+ public function validate_input( $plugin ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
wp_update_plugins();
$this->plugins = array_keys( get_plugins() );
return true;
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 d562f02e..19b32bc8 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
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Constants;
@@ -107,24 +107,62 @@ new Jetpack_JSON_API_Plugins_Modify_Endpoint(
)
);
+/**
+ * Plugins modify endpoint class.
+ *
+ * POST /sites/%s/plugins/%s
+ * POST /sites/%s/plugins
+ */
class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // POST /sites/%s/plugins/%s
- // POST /sites/%s/plugins
+
+ /**
+ * The slug.
+ *
+ * @var string
+ */
protected $slug = null;
+
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'activate_plugins';
+
+ /**
+ * Action.
+ *
+ * @var string
+ */
protected $action = 'default_action';
+
+ /**
+ * Expected actions.
+ *
+ * @var array
+ */
protected $expected_actions = array( 'update', 'install', 'delete', 'update_translations' );
+ /**
+ * Callback.
+ *
+ * @param string $path - the path.
+ * @param int $blog_id - the blog ID.
+ * @param object $object - the object.
+ *
+ * @return bool|WP_Error
+ */
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';
+ break;
case 'update_translations':
- case 'update' :
+ case 'update':
$this->needed_capabilities = 'update_plugins';
break;
- case 'install' :
+ case 'install':
$this->needed_capabilities = 'install_plugins';
break;
}
@@ -136,6 +174,11 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return parent::callback( $path, $blog_id, $object );
}
+ /**
+ * The default action.
+ *
+ * @return bool|WP_Error
+ */
public function default_action() {
$args = $this->input();
@@ -172,58 +215,75 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return true;
}
+ /**
+ * Turn on autoupdate.
+ */
protected function autoupdate_on() {
$autoupdate_plugins = (array) get_site_option( 'auto_update_plugins', array() );
$autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) );
update_site_option( 'auto_update_plugins', $autoupdate_plugins );
}
+ /**
+ * Turn off autoupdate.
+ */
protected function autoupdate_off() {
$autoupdate_plugins = (array) get_site_option( 'auto_update_plugins', array() );
$autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins );
update_site_option( 'auto_update_plugins', $autoupdate_plugins );
}
+ /**
+ * Turn autoupdate translations on.
+ */
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 );
}
+ /**
+ * Turn autoupdate translations off.
+ */
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 );
}
+ /**
+ * Activate the plugin.
+ *
+ * @return null|WP_Error null if the activation was successful.
+ */
protected function activate() {
$permission_error = false;
foreach ( $this->plugins as $plugin ) {
if ( ! $this->current_user_can( 'activate_plugin', $plugin ) ) {
- $this->log[$plugin]['error'] = __( 'Sorry, you are not allowed to activate this plugin.' );
- $has_errors = true;
- $permission_error = true;
+ $this->log[ $plugin ]['error'] = __( 'Sorry, you are not allowed to activate this plugin.', 'jetpack' );
+ $has_errors = true;
+ $permission_error = true;
continue;
}
if ( ( ! $this->network_wide && Jetpack::is_plugin_active( $plugin ) ) || is_plugin_active_for_network( $plugin ) ) {
- $this->log[$plugin]['error'] = __( 'The Plugin is already active.', 'jetpack' );
- $has_errors = true;
+ $this->log[ $plugin ]['error'] = __( 'The Plugin is already active.', 'jetpack' );
+ $has_errors = true;
continue;
}
if ( ! $this->network_wide && is_network_only_plugin( $plugin ) && is_multisite() ) {
- $this->log[$plugin]['error'] = __( 'Plugin can only be Network Activated', 'jetpack' );
- $has_errors = true;
+ $this->log[ $plugin ]['error'] = __( 'Plugin can only be Network Activated', 'jetpack' );
+ $has_errors = true;
continue;
}
$result = activate_plugin( $plugin, '', $this->network_wide );
if ( is_wp_error( $result ) ) {
- $this->log[$plugin]['error'] = $result->get_error_messages();
- $has_errors = true;
+ $this->log[ $plugin ]['error'] = $result->get_error_messages();
+ $has_errors = true;
continue;
}
@@ -233,23 +293,31 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
}
if ( ! $success ) {
- $this->log[$plugin]['error'] = $result->get_error_messages;
- $has_errors = true;
+ $this->log[ $plugin ]['error'] = $result->get_error_messages;
+ $has_errors = true;
continue;
}
- $this->log[$plugin][] = __( 'Plugin activated.', 'jetpack' );
+ $this->log[ $plugin ][] = __( 'Plugin activated.', 'jetpack' );
}
if ( ! $this->bulk && isset( $has_errors ) ) {
$plugin = $this->plugins[0];
if ( $permission_error ) {
- return new WP_Error( 'unauthorized_error', $this->log[$plugin]['error'], 403 );
+ return new WP_Error( 'unauthorized_error', $this->log[ $plugin ]['error'], 403 );
}
- return new WP_Error( 'activation_error', $this->log[$plugin]['error'] );
+ return new WP_Error( 'activation_error', $this->log[ $plugin ]['error'] );
}
}
+ /**
+ * Check if the current user has capabilities.
+ *
+ * @param string $capability - the capability we're checking.
+ * @param string $plugin - the plugin we're checking.
+ *
+ * @return bool
+ */
protected function current_user_can( $capability, $plugin = null ) {
// If this endpoint accepts site based authentication and a blog token is used, skip capabilities check.
if ( $this->accepts_site_based_authentication() ) {
@@ -262,17 +330,24 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return current_user_can( $capability );
}
+ /**
+ * Deactivate the plugin.
+ *
+ * @return null|WP_Error null if the deactivation was successful
+ */
protected function deactivate() {
$permission_error = false;
foreach ( $this->plugins as $plugin ) {
if ( ! $this->current_user_can( 'deactivate_plugin', $plugin ) ) {
- $error = $this->log[$plugin]['error'] = __( 'Sorry, you are not allowed to deactivate this plugin.', 'jetpack' );
- $permission_error = true;
+ $error = __( 'Sorry, you are not allowed to deactivate this plugin.', 'jetpack' );
+ $this->log[ $plugin ]['error'] = $error;
+ $permission_error = true;
continue;
}
if ( ! Jetpack::is_plugin_active( $plugin ) ) {
- $error = $this->log[$plugin]['error'] = __( 'The Plugin is already deactivated.', 'jetpack' );
+ $error = __( 'The Plugin is already deactivated.', 'jetpack' );
+ $this->log[ $plugin ]['error'] = $error;
continue;
}
@@ -284,10 +359,11 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
}
if ( ! $success ) {
- $error = $this->log[$plugin]['error'] = __( 'There was an error deactivating your plugin', 'jetpack' );
+ $error = __( 'There was an error deactivating your plugin', 'jetpack' );
+ $this->log[ $plugin ]['error'] = $error;
continue;
}
- $this->log[$plugin][] = __( 'Plugin deactivated.', 'jetpack' );
+ $this->log[ $plugin ][] = __( 'Plugin deactivated.', 'jetpack' );
}
if ( ! $this->bulk && isset( $error ) ) {
if ( $permission_error ) {
@@ -298,6 +374,11 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
}
}
+ /**
+ * Update the plugin.
+ *
+ * @return bool|WP_Error
+ */
protected function update() {
$query_args = $this->query_args();
@@ -336,8 +417,8 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
foreach ( $this->plugins as $plugin ) {
- if ( ! in_array( $plugin, $plugin_updates_needed ) ) {
- $this->log[$plugin][] = __( 'No update needed', 'jetpack' );
+ if ( ! in_array( $plugin, $plugin_updates_needed, true ) ) {
+ $this->log[ $plugin ][] = __( 'No update needed', 'jetpack' );
continue;
}
@@ -372,9 +453,9 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
$upgrader->init();
// This avoids the plugin to be deactivated.
// Using bulk upgrade puts the site into maintenance mode during the upgrades
- $result = $upgrader->bulk_upgrade( array( $plugin ) );
- $errors = $upgrader->skin->get_errors();
- $this->log[$plugin] = $upgrader->skin->get_upgrade_messages();
+ $result = $upgrader->bulk_upgrade( array( $plugin ) );
+ $errors = $upgrader->skin->get_errors();
+ $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages();
// release individual plugin lock.
WP_Upgrader::release_lock( 'jetpack_' . $plugin_slug );
@@ -396,7 +477,12 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return $this->default_action();
}
- function update_translations() {
+ /**
+ * Update translations.
+ *
+ * @return bool|WP_Error
+ */
+ public function update_translations() {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Clear the cache.
@@ -417,7 +503,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
$translation = array_filter( $available_updates->translations, array( $this, 'get_translation' ) );
if ( empty( $translation ) ) {
- $this->log[$plugin][] = __( 'No update needed', 'jetpack' );
+ $this->log[ $plugin ][] = __( 'No update needed', 'jetpack' );
continue;
}
@@ -440,7 +526,7 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
$result = $upgrader->upgrade( (object) $translation[0] );
- $this->log[$plugin] = $upgrader->skin->get_upgrade_messages();
+ $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages();
}
if ( ! $this->bulk && ! $result ) {
@@ -450,6 +536,13 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_
return true;
}
+ /**
+ * Test whether the translation matches `$this->slug`.
+ *
+ * @param array $translation - the translation.
+ *
+ * @return bool
+ */
protected function get_translation( $translation ) {
return ( $translation['slug'] === $this->slug );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php
index 11d9f101..b7da3eab 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-v1-2-endpoint.php
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
new Jetpack_JSON_API_Plugins_Modify_v1_2_Endpoint(
array(
'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates',
@@ -101,7 +101,10 @@ new Jetpack_JSON_API_Plugins_Modify_v1_2_Endpoint(
)
);
-class Jetpack_JSON_API_Plugins_Modify_v1_2_Endpoint extends Jetpack_JSON_API_Plugins_Modify_Endpoint {
+/**
+ * Plugins modify 1_2 Endpoint.
+ */
+class Jetpack_JSON_API_Plugins_Modify_v1_2_Endpoint extends Jetpack_JSON_API_Plugins_Modify_Endpoint { // phpcs:ignore PEAR.NamingConventions.ValidClassName.Invalid, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
/**
* Activate plugins.
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php
index 3a16b1b0..7aa4dfcd 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-new-endpoint.php
@@ -1,8 +1,9 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-include_once ABSPATH . 'wp-admin/includes/file.php';
+require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+require_once ABSPATH . 'wp-admin/includes/file.php';
+use Automattic\Jetpack\Automatic_Install_Skin;
// POST /sites/%s/plugins/new
new Jetpack_JSON_API_Plugins_New_Endpoint(
@@ -31,7 +32,6 @@ new Jetpack_JSON_API_Plugins_New_Endpoint(
)
);
-
new Jetpack_JSON_API_Plugins_New_Endpoint(
array(
'description' => 'Install a plugin to a Jetpack site by uploading a zip file',
@@ -57,12 +57,36 @@ new Jetpack_JSON_API_Plugins_New_Endpoint(
)
);
+/**
+ * Plugins new endpoint class.
+ *
+ * POST /sites/%s/plugins/new
+ */
class Jetpack_JSON_API_Plugins_New_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
- // POST /sites/%s/plugins/new
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'install_plugins';
+
+ /**
+ * The action.
+ *
+ * @var string
+ */
protected $action = 'install';
+ /**
+ * Validate call.
+ *
+ * @param int $_blog_id - the blog ID.
+ * @param string $capability - the capability.
+ * @param bool $check_manage_active - check if manage is active.
+ *
+ * @return bool|WP_Error a WP_Error object or true if things are good.
+ */
protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) {
$validate = parent::validate_call( $_blog_id, $capability, $check_manage_active );
if ( is_wp_error( $validate ) ) {
@@ -77,13 +101,22 @@ class Jetpack_JSON_API_Plugins_New_Endpoint extends Jetpack_JSON_API_Plugins_End
return $validate;
}
- // no need to try to validate the plugin since we didn't pass one in.
- protected function validate_input( $plugin ) {
+ /**
+ * No need to try to validate the plugin since we didn't pass one in.
+ *
+ * @param string $plugin - the plugin we're validating.
+ */
+ protected function validate_input( $plugin ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$this->bulk = false;
$this->plugins = array();
}
- function install() {
+ /**
+ * Install the plugin.
+ *
+ * @return bool|WP_Error
+ */
+ public function install() {
$args = $this->input();
if ( isset( $args['zip'][0]['id'] ) ) {
@@ -92,8 +125,7 @@ class Jetpack_JSON_API_Plugins_New_Endpoint extends Jetpack_JSON_API_Plugins_End
if ( ! $local_file ) {
return new WP_Error( 'local-file-does-not-exist' );
}
- jetpack_require_lib( 'class.jetpack-automatic-install-skin' );
- $skin = new Jetpack_Automatic_Install_Skin();
+ $skin = new Automatic_Install_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$pre_install_plugin_list = get_plugins();
@@ -127,7 +159,7 @@ class Jetpack_JSON_API_Plugins_New_Endpoint extends Jetpack_JSON_API_Plugins_End
return new WP_Error( 'plugin_already_installed' );
}
- $this->plugins = $plugin;
+ $this->plugins = $plugin;
$this->log[ $plugin[0] ] = $upgrader->skin->get_upgrade_messages();
return true;
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 94e7c790..9f4dd026 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
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Sync\Actions;
use Automattic\Jetpack\Sync\Health;
@@ -9,7 +9,13 @@ use Automattic\Jetpack\Sync\Replicastore;
use Automattic\Jetpack\Sync\Sender;
use Automattic\Jetpack\Sync\Settings;
-// POST /sites/%s/sync
+// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
+
+/**
+ * Sync endpoint class.
+ *
+ * POST /sites/%s/sync
+ */
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
/**
@@ -20,12 +26,26 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
*/
protected $needed_capabilities = 'manage_options';
- protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) {
+ /**
+ * Validate the call.
+ *
+ * @param int $_blog_id - the blog ID.
+ * @param string $capability - the capability.
+ * @param bool $check_manage_active - unused.
+ *
+ * @return bool|WP_Error
+ */
+ protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return parent::validate_call( $_blog_id, $capability, false );
}
+ /**
+ * The result.
+ *
+ * @return array
+ */
protected function result() {
- $args = $this->input();
+ $args = $this->input();
$modules = null;
// convert list of modules in comma-delimited format into an array
@@ -36,7 +56,7 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
foreach ( array( 'posts', 'comments', 'users' ) as $module_name ) {
if ( 'users' === $module_name && isset( $args[ $module_name ] ) && 'initial' === $args[ $module_name ] ) {
- $modules[ 'users' ] = 'initial';
+ $modules['users'] = 'initial';
} elseif ( isset( $args[ $module_name ] ) ) {
$ids = explode( ',', $args[ $module_name ] );
if ( count( $ids ) > 0 ) {
@@ -51,20 +71,36 @@ class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
return array( 'scheduled' => Actions::do_full_sync( $modules ) );
}
+ /**
+ * Validate the queue.
+ *
+ * @param array $query - the query.
+ *
+ * @return string|WP_Error
+ */
protected function validate_queue( $query ) {
if ( ! isset( $query ) ) {
return new WP_Error( 'invalid_queue', 'Queue name is required', 400 );
}
- if ( ! in_array( $query, array( 'sync', 'full_sync', 'immediate' ) ) ) {
+ if ( ! in_array( $query, array( 'sync', 'full_sync', 'immediate' ), true ) ) {
return new WP_Error( 'invalid_queue', 'Queue name should be sync, full_sync or immediate', 400 );
}
return $query;
}
}
-// GET /sites/%s/sync/status
+/**
+ * Sync status endpoint class.
+ *
+ * GET /sites/%s/sync/status
+ */
class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Callback for the endpoint.
+ *
+ * @return array
+ */
protected function result() {
$args = $this->query_args();
$fields = isset( $args['fields'] ) ? $args['fields'] : array();
@@ -72,8 +108,16 @@ class Jetpack_JSON_API_Sync_Status_Endpoint extends Jetpack_JSON_API_Sync_Endpoi
}
}
-// GET /sites/%s/data-check
+/**
+ * Sync Check Endpoint class.
+ * GET /sites/%s/data-check
+ */
class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Callback for the endpoint.
+ *
+ * @return array
+ */
protected function result() {
Actions::mark_sync_read_only();
$store = new Replicastore();
@@ -81,8 +125,16 @@ class Jetpack_JSON_API_Sync_Check_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
}
}
-// GET /sites/%s/data-histogram
+/**
+ * Sync histogram endpoint.
+ * GET /sites/%s/data-histogram
+ */
class Jetpack_JSON_API_Sync_Histogram_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Callback for endpoint.
+ *
+ * @return array
+ */
protected function result() {
$args = $this->query_args();
@@ -118,11 +170,13 @@ class Jetpack_JSON_API_Sync_Histogram_Endpoint extends Jetpack_JSON_API_Sync_End
// Hack to disable Sync during this call, so we can resolve faster.
Actions::mark_sync_read_only();
- return array( 'histogram' => $histogram, 'type' => $store->get_checksum_type() );
+ return array(
+ 'histogram' => $histogram,
+ 'type' => $store->get_checksum_type(),
+ );
}
}
-// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
/**
* POST /sites/%s/sync/health
*/
@@ -151,10 +205,16 @@ class Jetpack_JSON_API_Sync_Modify_Health_Endpoint extends Jetpack_JSON_API_Sync
);
}
}
-// phpcs:enable
-// POST /sites/%s/sync/settings
+/**
+ * POST /sites/%s/sync/settings
+ */
class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * The endpoint callback.
+ *
+ * @return array
+ */
protected function result() {
$args = $this->input();
@@ -182,22 +242,37 @@ class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sy
}
}
-// GET /sites/%s/sync/settings
+/**
+ * GET /sites/%s/sync/settings
+ */
class Jetpack_JSON_API_Sync_Get_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array
+ */
protected function result() {
return Settings::get_settings();
}
}
-// GET /sites/%s/sync/object
+/**
+ * GET /sites/%s/sync/object
+ */
class Jetpack_JSON_API_Sync_Object extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->query_args();
$module_name = $args['module_name'];
- if ( ! $sync_module = Modules::get_module( $module_name ) ) {
+ $sync_module = Modules::get_module( $module_name );
+ if ( ! $sync_module ) {
return new WP_Error( 'invalid_module', 'You specified an invalid sync module' );
}
@@ -213,30 +288,46 @@ class Jetpack_JSON_API_Sync_Object extends Jetpack_JSON_API_Sync_Endpoint {
return array(
'objects' => $objects,
- 'codec' => $codec->name(),
+ 'codec' => $codec->name(),
);
}
}
+/**
+ * Sync Now endpoint class.
+ */
class Jetpack_JSON_API_Sync_Now_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array
+ */
protected function result() {
- $args = $this->input();
+ $args = $this->input();
$queue_name = $this->validate_queue( $args['queue'] );
- if ( is_wp_error( $queue_name ) ){
+ if ( is_wp_error( $queue_name ) ) {
return $queue_name;
}
- $sender = Sender::get_instance();
+ $sender = Sender::get_instance();
$response = $sender->do_sync_for_queue( new Queue( $args['queue'] ) );
return array(
- 'response' => $response
+ 'response' => $response,
);
}
}
+/**
+ * Sync checkout endpoint.
+ */
class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->input();
$queue_name = $this->validate_queue( $args['queue'] );
@@ -258,7 +349,16 @@ class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endp
return $this->queue_pull( $queue_name, $number_of_items, $args );
}
- function queue_pull( $queue_name, $number_of_items, $args ){
+ /**
+ * Create a queue.
+ *
+ * @param string $queue_name - the queue name.
+ * @param int $number_of_items - the number of items.
+ * @param array $args - the arguments.
+ *
+ * @return array|WP_Error
+ */
+ public function queue_pull( $queue_name, $number_of_items, $args ) {
$queue = new Queue( $queue_name );
if ( 0 === $queue->size() ) {
@@ -301,8 +401,16 @@ class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endp
);
}
- public $items = [];
+ /**
+ * The items.
+ *
+ * @var array
+ */
+ public $items = array();
+ /**
+ * Send the data listener.
+ */
public function jetpack_sync_send_data_listener() {
foreach ( func_get_args()[0] as $key => $item ) {
$this->items[ $key ] = $item;
@@ -316,7 +424,7 @@ class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endp
*
* @return array Sync Actions to be returned to requestor
*/
- public function immediate_full_sync_pull( $number_of_items = null ) {
+ public function immediate_full_sync_pull( $number_of_items = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// try to give ourselves as much time as possible.
set_time_limit( 0 );
@@ -338,17 +446,25 @@ class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endp
);
}
+ /**
+ * Get the queue buffer.
+ *
+ * @param object $queue - the queue.
+ * @param int $number_of_items - the number of items.
+ *
+ * @return Automattic\Jetpack\Sync\Queue_Buffer|bool|int|\WP_Error
+ */
protected function get_buffer( $queue, $number_of_items ) {
- $start = time();
+ $start = time();
$max_duration = 5; // this will try to get the buffer
- $buffer = $queue->checkout( $number_of_items );
+ $buffer = $queue->checkout( $number_of_items );
$duration = time() - $start;
- while( is_wp_error( $buffer ) && $duration < $max_duration ) {
+ while ( is_wp_error( $buffer ) && $duration < $max_duration ) {
sleep( 2 );
$duration = time() - $start;
- $buffer = $queue->checkout( $number_of_items );
+ $buffer = $queue->checkout( $number_of_items );
}
if ( $buffer === false ) {
@@ -359,11 +475,19 @@ class Jetpack_JSON_API_Sync_Checkout_Endpoint extends Jetpack_JSON_API_Sync_Endp
}
}
+/**
+ * Close endpoint class.
+ */
class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$request_body = $this->input();
- $queue_name = $this->validate_queue( $request_body['queue'] );
+ $queue_name = $this->validate_queue( $request_body['queue'] );
if ( is_wp_error( $queue_name ) ) {
return $queue_name;
@@ -377,9 +501,8 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
return new WP_Error( 'missing_item_ids', 'Please provide a list of item ids in the item_ids argument', 400 );
}
- //Limit to A-Z,a-z,0-9,_,-
- $request_body ['buffer_id'] = preg_replace( '/[^A-Za-z0-9]/', '', $request_body['buffer_id'] );
- $request_body['item_ids'] = array_filter( array_map( array( 'Jetpack_JSON_API_Sync_Close_Endpoint', 'sanitize_item_ids' ), $request_body['item_ids'] ) );
+ $request_body['buffer_id'] = preg_replace( '/[^A-Za-z0-9]/', '', $request_body['buffer_id'] );
+ $request_body['item_ids'] = array_filter( array_map( array( 'Jetpack_JSON_API_Sync_Close_Endpoint', 'sanitize_item_ids' ), $request_body['item_ids'] ) );
$queue = new Queue( $queue_name );
@@ -392,7 +515,7 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
$full_sync_module->update_sent_progress_action( $items );
}
- $buffer = new Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] );
+ $buffer = new Queue_Buffer( $request_body['buffer_id'], $request_body['item_ids'] );
$response = $queue->close( $buffer, $request_body['item_ids'] );
// Perform another checkout?
@@ -414,21 +537,36 @@ class Jetpack_JSON_API_Sync_Close_Endpoint extends Jetpack_JSON_API_Sync_Endpoin
return array(
'success' => $response,
- 'status' => Actions::get_sync_status(),
+ 'status' => Actions::get_sync_status(),
);
}
+ /**
+ * Sanitize item IDs.
+ *
+ * @param string $item - the item we're sanitizing.
+ *
+ * @return string|null
+ */
protected static function sanitize_item_ids( $item ) {
// lets not delete any options that don't start with jpsq_sync-
if ( ! is_string( $item ) || substr( $item, 0, 5 ) !== 'jpsq_' ) {
return null;
}
- //Limit to A-Z,a-z,0-9,_,-,.
+ // Limit to A-Z,a-z,0-9,_,-,.
return preg_replace( '/[^A-Za-z0-9-_.]/', '', $item );
}
}
+/**
+ * Unlock ednpoint class.
+ */
class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->input();
@@ -436,7 +574,7 @@ class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoi
return new WP_Error( 'invalid_queue', 'Queue name is required', 400 );
}
- if ( ! in_array( $args['queue'], array( 'sync', 'full_sync' ) ) ) {
+ if ( ! in_array( $args['queue'], array( 'sync', 'full_sync' ), true ) ) {
return new WP_Error( 'invalid_queue', 'Queue name should be sync or full_sync', 400 );
}
@@ -445,12 +583,20 @@ class Jetpack_JSON_API_Sync_Unlock_Endpoint extends Jetpack_JSON_API_Sync_Endpoi
// False means that there was no lock to delete.
$response = $queue->unlock();
return array(
- 'success' => $response
+ 'success' => $response,
);
}
}
+/**
+ * Object ID range class.
+ */
class Jetpack_JSON_API_Sync_Object_Id_Range extends Jetpack_JSON_API_Sync_Endpoint {
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
$args = $this->query_args();
@@ -468,6 +614,13 @@ class Jetpack_JSON_API_Sync_Object_Id_Range extends Jetpack_JSON_API_Sync_Endpoi
);
}
+ /**
+ * Check if sync module is valid.
+ *
+ * @param string $module_name - the module name.
+ *
+ * @return bool
+ */
protected function is_valid_sync_module( $module_name ) {
return in_array(
$module_name,
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php
index db23c52f..446a1056 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-active-endpoint.php
@@ -1,21 +1,38 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * GET /sites/%s/themes/mine => current theme
+ * POST /sites/%s/themes/mine => switch theme
+ */
class Jetpack_JSON_API_Themes_Active_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // GET /sites/%s/themes/mine => current theme
- // POST /sites/%s/themes/mine => switch theme
- // The unused $object parameter is for making the method signature compatible with its parent class method.
- public function callback( $path = '', $blog_id = 0, $object = null ) {
- if ( is_wp_error( $error = $this->validate_call( $blog_id, 'switch_themes', true ) ) ) {
+ /**
+ * Endpoint callback.
+ *
+ * @param string $path - the path.
+ * @param int $blog_id - the blog ID.
+ * @param object $object - The unused $object parameter is for making the method signature compatible with its parent class method.
+ *
+ * @return array|bool|WP_Error
+ */
+ public function callback( $path = '', $blog_id = 0, $object = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
+ $error = $this->validate_call( $blog_id, 'switch_themes', true );
+ if ( is_wp_error( $error ) ) {
return $error;
}
- if ( 'POST' === $this->api->method )
+ if ( 'POST' === $this->api->method ) {
return $this->switch_theme();
- else
+ } else {
return $this->get_current_theme();
+ }
}
+ /**
+ * Switch the theme.
+ *
+ * @return array|WP_Error
+ */
protected function switch_theme() {
$args = $this->input();
@@ -44,6 +61,11 @@ class Jetpack_JSON_API_Themes_Active_Endpoint extends Jetpack_JSON_API_Themes_En
return $this->get_current_theme();
}
+ /**
+ * Get the current theme.
+ *
+ * @return array
+ */
protected function get_current_theme() {
return $this->format_theme( wp_get_theme() );
}
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 97bcc58d..b4f44445 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
@@ -1,23 +1,44 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Themes delete endpoint class.
+ * POST /sites/%s/plugins/%s/delete
+ */
class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // POST /sites/%s/plugins/%s/delete
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'delete_themes';
- protected $action = 'delete';
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action = 'delete';
+
+ /**
+ * Delete the theme.
+ *
+ * @return bool|WP_Error
+ */
protected function delete() {
- foreach( $this->themes as $theme ) {
+ foreach ( $this->themes as $theme ) {
// Don't delete an active child theme
- if ( is_child_theme() && $theme == get_stylesheet() ) {
- $error = $this->log[ $theme ]['error'] = 'You cannot delete a theme while it is active on the main site.';
+ if ( is_child_theme() && $theme === get_stylesheet() ) {
+ $error = 'You cannot delete a theme while it is active on the main site.';
+ $this->log[ $theme ]['error'] = $error;
continue;
}
- if( $theme == get_template() ) {
- $error = $this->log[ $theme ]['error'] = 'You cannot delete a theme while it is active on the main site.';
+ if ( $theme === get_template() ) {
+ $error = 'You cannot delete a theme while it is active on the main site.';
+ $this->log[ $theme ]['error'] = $error;
continue;
}
@@ -44,14 +65,15 @@ class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_En
}
if ( is_wp_error( $result ) ) {
- $error = $this->log[ $theme ]['error'] = $result->get_error_messages();
+ $error = $result->get_error_messages();
+ $this->log[ $theme ]['error'] = $error;
} else {
$this->log[ $theme ][] = 'Theme deleted';
}
}
- if( ! $this->bulk && isset( $error ) ) {
- return new WP_Error( 'delete_theme_error', $error, 400 );
+ if ( ! $this->bulk && isset( $error ) ) {
+ return new WP_Error( 'delete_theme_error', $error, 400 );
}
return true;
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 2e32dccd..a8f037e7 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
@@ -1,33 +1,60 @@
-<?php
-
-
-// THEMES
-
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Base class for working with themes, has useful helper functions.
*/
abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * The themes.
+ *
+ * @var array
+ */
protected $themes = array();
+ /**
+ * If we're working in bulk.
+ *
+ * @var boolean
+ */
protected $bulk = true;
+
+ /**
+ * The log.
+ *
+ * @var array
+ */
protected $log;
+
+ /**
+ * The current theme ID.
+ *
+ * @var int
+ */
protected $current_theme_id;
- static $_response_format = array(
- 'id' => '(string) The theme\'s ID.',
- 'screenshot' => '(string) A theme screenshot URL',
- 'name' => '(string) The name of the theme.',
- 'theme_uri' => '(string) The URI of the theme\'s webpage.',
- 'description' => '(string) A description of the theme.',
- 'author' => '(string) The author of the theme.',
- 'author_uri' => '(string) The website of the theme author.',
- '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',
+ /**
+ * The response format.
+ *
+ * @var array
+ */
+ public static $_response_format = array( // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
+ 'id' => '(string) The theme\'s ID.',
+ 'screenshot' => '(string) A theme screenshot URL',
+ 'name' => '(string) The name of the theme.',
+ 'theme_uri' => '(string) The URI of the theme\'s webpage.',
+ 'description' => '(string) A description of the theme.',
+ 'author' => '(string) The author of the theme.',
+ 'author_uri' => '(string) The website of the theme author.',
+ 'tags' => '(array) Tags indicating styles and features of the theme.',
+ 'log' => '(array) An array of log strings',
+ 'update' => '(array|null) An object containing information about the available update if there is an update available, null otherwise.',
+ 'autoupdate' => '(bool) Whether the theme is automatically updated',
'autoupdate_translation' => '(bool) Whether the theme is automatically updating translations',
);
+ /**
+ * The result.
+ */
protected function result() {
$themes = $this->get_themes();
@@ -42,9 +69,10 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
/**
* Walks through either the submitted theme or list of themes and creates the global array
- * @param $theme
*
- * @return bool
+ * @param string $theme - the theme URL.
+ *
+ * @return bool|WP_Error
*/
protected function validate_input( $theme ) {
$args = $this->input();
@@ -61,10 +89,11 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
}
} else {
$this->themes[] = urldecode( $theme );
- $this->bulk = false;
+ $this->bulk = false;
}
- if ( is_wp_error( $error = $this->validate_themes() ) ) {
+ $error = $this->validate_themes();
+ if ( is_wp_error( $error ) ) {
return $error;
}
@@ -73,12 +102,14 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
/**
* Walks through submitted themes to make sure they are valid
+ *
* @return bool|WP_Error
*/
protected function validate_themes() {
foreach ( $this->themes as $theme ) {
- if ( is_wp_error( $error = wp_get_theme( $theme )->errors() ) ) {
- return new WP_Error( 'unknown_theme', $error->get_error_messages() , 404 );
+ $error = wp_get_theme( $theme )->errors();
+ if ( is_wp_error( $error ) ) {
+ return new WP_Error( 'unknown_theme', $error->get_error_messages(), 404 );
}
}
return true;
@@ -86,7 +117,8 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
/**
* Format a theme for the public API
- * @param object $theme WP_Theme object
+ *
+ * @param object $theme WP_Theme object.
* @return array Named array of theme info used by the API
*/
protected function format_theme( $theme ) {
@@ -102,27 +134,27 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
'author' => 'Author',
'author_uri' => 'AuthorURI',
'tags' => 'Tags',
- 'version' => 'Version'
+ 'version' => 'Version',
);
- $id = $theme->get_stylesheet();
+ $id = $theme->get_stylesheet();
$formatted_theme = array(
- 'id' => $id,
- 'screenshot' => jetpack_photon_url( $theme->get_screenshot(), array(), 'network_path' ),
- 'active' => $id === $this->current_theme_id,
+ 'id' => $id,
+ 'screenshot' => jetpack_photon_url( $theme->get_screenshot(), array(), 'network_path' ),
+ 'active' => $id === $this->current_theme_id,
);
- foreach( $fields as $key => $field ) {
+ foreach ( $fields as $key => $field ) {
$formatted_theme[ $key ] = $theme->get( $field );
}
- $update_themes = get_site_transient( 'update_themes' );
+ $update_themes = get_site_transient( 'update_themes' );
$formatted_theme['update'] = ( isset( $update_themes->response[ $id ] ) ) ? $update_themes->response[ $id ] : null;
- $autoupdate = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes', array() ) );
- $formatted_theme['autoupdate'] = $autoupdate;
+ $autoupdate = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes', array() ), true );
+ $formatted_theme['autoupdate'] = $autoupdate;
- $autoupdate_translation = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ) );
+ $autoupdate_translation = in_array( $id, Jetpack_Options::get_option( 'autoupdate_themes_translations', array() ), true );
$formatted_theme['autoupdate_translation'] = $autoupdate || $autoupdate_translation || Jetpack_Options::get_option( 'autoupdate_translations', false );
if ( isset( $this->log[ $id ] ) ) {
@@ -143,19 +175,23 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
/**
* Checks the query_args our collection endpoint was passed to ensure that it's in the proper bounds.
+ *
* @return bool|WP_Error a WP_Error object if the args are out of bounds, true if things are good.
*/
protected function check_query_args() {
$args = $this->query_args();
- if ( $args['offset'] < 0 )
+ if ( $args['offset'] < 0 ) {
return new WP_Error( 'invalid_offset', __( 'Offset must be greater than or equal to 0.', 'jetpack' ), 400 );
- if ( $args['limit'] < 0 )
+ }
+ if ( $args['limit'] < 0 ) {
return new WP_Error( 'invalid_limit', __( 'Limit must be greater than or equal to 0.', 'jetpack' ), 400 );
+ }
return true;
}
/**
* Format a list of themes for public display, using the supplied offset and limit args
+ *
* @uses WPCOM_JSON_API_Endpoint::query_args()
* @return array Public API theme objects
*/
@@ -165,10 +201,12 @@ abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoin
// do offset & limit - we've already returned a 400 error if they're bad numbers
$args = $this->query_args();
- if ( isset( $args['offset'] ) )
+ if ( isset( $args['offset'] ) ) {
$themes = array_slice( $themes, (int) $args['offset'] );
- if ( isset( $args['limit'] ) )
+ }
+ if ( isset( $args['limit'] ) ) {
$themes = array_slice( $themes, 0, (int) $args['limit'] );
+ }
$this->current_theme_id = wp_get_theme()->get_stylesheet();
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-get-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-get-endpoint.php
index cfc352af..c1484e3f 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-get-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-get-endpoint.php
@@ -1,6 +1,15 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Themes get endpoint class.
+ *
+ * GET /sites/%s/themes/%s
+ */
class Jetpack_JSON_API_Themes_Get_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // GET /sites/%s/themes/%s
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'switch_themes';
}
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 5c69b4dd..8c6548e2 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
@@ -1,17 +1,44 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-include_once ABSPATH . 'wp-admin/includes/file.php';
+require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+require_once ABSPATH . 'wp-admin/includes/file.php';
+use Automattic\Jetpack\Automatic_Install_Skin;
use Automattic\Jetpack\Connection\Client;
+/**
+ * Themes install endpoint class.
+ *
+ * POST /sites/%s/themes/%s/install
+ */
class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // POST /sites/%s/themes/%s/install
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'install_themes';
- protected $action = 'install';
- protected $download_links = array();
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action = 'install';
+
+ /**
+ * Download links.
+ *
+ * @var array
+ */
+ protected $download_links = array();
+
+ /**
+ * Install the theme.
+ *
+ * @return bool|WP_Error
+ */
protected function install() {
foreach ( $this->themes as $theme ) {
@@ -34,14 +61,13 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
*/
$result = apply_filters( 'jetpack_wpcom_theme_install', false, $theme );
- $skin = null;
+ $skin = null;
$upgrader = null;
- $link = null;
+ $link = null;
// If the alternative install method was not used, use the standard method.
if ( ! $result ) {
- jetpack_require_lib( 'class.jetpack-automatic-install-skin' );
- $skin = new Jetpack_Automatic_Install_Skin();
+ $skin = new Automatic_Install_Skin();
$upgrader = new Theme_Upgrader( $skin );
$link = $this->download_links[ $theme ];
@@ -58,30 +84,33 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
}
if ( ! $result ) {
- $error = $this->log[ $theme ]['error'] = __( 'An unknown error occurred during installation', 'jetpack' );
- }
-
- elseif ( ! self::is_installed_theme( $theme ) ) {
- $error = $this->log[ $theme ]['error'] = __( 'There was an error installing your theme', 'jetpack' );
- }
-
- elseif ( $upgrader ) {
+ $error = __( 'An unknown error occurred during installation', 'jetpack' );
+ $this->log[ $theme ]['error'] = $error;
+ } elseif ( ! self::is_installed_theme( $theme ) ) {
+ $error = __( 'There was an error installing your theme', 'jetpack' );
+ $this->log[ $theme ]['error'] = $error;
+ } elseif ( $upgrader ) {
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages();
}
}
if ( ! $this->bulk && isset( $error ) ) {
- return new WP_Error( 'install_error', $error, 400 );
+ return new WP_Error( 'install_error', $error, 400 );
}
return true;
}
+ /**
+ * Validate the themes.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_themes() {
if ( empty( $this->themes ) || ! is_array( $this->themes ) ) {
return new WP_Error( 'missing_themes', __( 'No themes found.', 'jetpack' ) );
}
- foreach( $this->themes as $index => $theme ) {
+ foreach ( $this->themes as $theme ) {
if ( self::is_installed_theme( $theme ) ) {
return new WP_Error( 'theme_already_installed', __( 'The theme is already installed', 'jetpack' ) );
@@ -123,22 +152,22 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
continue;
}
- $params = (object) array( 'slug' => $theme );
- $url = 'https://api.wordpress.org/themes/info/1.0/';
- $args = array(
+ $params = (object) array( 'slug' => $theme );
+ $url = 'https://api.wordpress.org/themes/info/1.0/'; // @todo Switch to https://api.wordpress.org/themes/info/1.1/, which uses JSON rather than PHP serialization.
+ $args = array(
'body' => array(
- 'action' => 'theme_information',
- 'request' => serialize( $params ),
- )
+ 'action' => 'theme_information',
+ 'request' => serialize( $params ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
+ ),
);
- $response = wp_remote_post( $url, $args );
- $theme_data = unserialize( $response['body'] );
+ $response = wp_remote_post( $url, $args );
+ $theme_data = unserialize( $response['body'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize
if ( is_wp_error( $theme_data ) ) {
return $theme_data;
}
- if ( ! is_object( $theme_data ) && !isset( $theme_data->download_link ) ) {
- return new WP_Error( 'theme_not_found', __( 'This theme does not exist', 'jetpack' ) , 404 );
+ if ( ! is_object( $theme_data ) && ! isset( $theme_data->download_link ) ) {
+ return new WP_Error( 'theme_not_found', __( 'This theme does not exist', 'jetpack' ), 404 );
}
$this->download_links[ $theme ] = $theme_data->download_link;
@@ -147,25 +176,41 @@ class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_E
return true;
}
+ /**
+ * Check if the theme is installed.
+ *
+ * @param string $theme - the theme we're checking.
+ *
+ * @return bool
+ */
protected static function is_installed_theme( $theme ) {
$wp_theme = wp_get_theme( $theme );
return $wp_theme->exists();
}
+ /**
+ * Download the wpcom theme.
+ *
+ * @param string $theme - the theme to download.
+ *
+ * @return string|WP_Error
+ */
protected static function download_wpcom_theme_to_file( $theme ) {
- $wpcom_theme_slug = preg_replace( '/-wpcom$/', '', $theme );
$file = wp_tempnam( 'theme' );
if ( ! $file ) {
return new WP_Error( 'problem_creating_theme_file', __( 'Problem creating file for theme download', 'jetpack' ) );
}
- $url = "themes/download/$theme.zip";
- $args = array( 'stream' => true, 'filename' => $file );
+ $url = "themes/download/$theme.zip";
+ $args = array(
+ 'stream' => true,
+ 'filename' => $file,
+ );
$result = Client::wpcom_json_api_request_as_blog( $url, '1.1', $args );
- $response = $result[ 'response' ];
- if ( $response[ 'code' ] !== 200 ) {
+ $response = $result['response'];
+ if ( $response['code'] !== 200 ) {
unlink( $file );
return new WP_Error( 'problem_fetching_theme', __( 'Problem downloading theme', 'jetpack' ) );
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-list-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-list-endpoint.php
index 526cf4d7..1a5b361b 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-list-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-list-endpoint.php
@@ -1,11 +1,26 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Theme list endpoint class.
+ *
+ * GET /sites/%s/themes
+ */
class Jetpack_JSON_API_Themes_List_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // GET /sites/%s/themes
-
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'switch_themes';
- public function validate_input( $theme ) {
+ /**
+ * Validate the input.
+ *
+ * @param string $theme - the theme we're validating (unused, for keeping in sync with parent class).
+ *
+ * @return bool
+ */
+ public function validate_input( $theme ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$this->themes = wp_get_themes( array( 'allowed' => true ) );
return true;
}
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 072bfc5c..39560c86 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
@@ -1,13 +1,38 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Themes modify endpoint class.
+ * POST /sites/%s/themes/%s
+ * POST /sites/%s/themes
+ */
class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // POST /sites/%s/themes/%s
- // POST /sites/%s/themes
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'update_themes';
- protected $action = 'default_action';
- protected $expected_actions = array( 'update', 'update_translations' );
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action = 'default_action';
+
+ /**
+ * Expected actions.
+ *
+ * @var array
+ */
+ protected $expected_actions = array( 'update', 'update_translations' );
+
+ /**
+ * The default action.
+ *
+ * @return bool
+ */
public function default_action() {
$args = $this->input();
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) {
@@ -28,31 +53,48 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
return true;
}
- function autoupdate_on() {
+ /**
+ * Turn autoupdate on.
+ */
+ public function autoupdate_on() {
$autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() );
$autoupdate_themes = array_unique( array_merge( $autoupdate_themes, $this->themes ) );
Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes );
}
- function autoupdate_off() {
+ /**
+ * Turn autoupdate off.
+ */
+ public function autoupdate_off() {
$autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() );
$autoupdate_themes = array_diff( $autoupdate_themes, $this->themes );
Jetpack_Options::update_option( 'autoupdate_themes', $autoupdate_themes );
}
- function autoupdate_translations_on() {
+ /**
+ * Autoupdate translations on.
+ */
+ public 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 translations off.
+ */
+ public 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() {
+ /**
+ * Update the theme.
+ *
+ * @return bool|WP_Error True on success, WP_Error on failure.
+ */
+ public function update() {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Clear the cache.
@@ -61,18 +103,18 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
foreach ( $this->themes as $theme ) {
/**
* Pre-upgrade action
- *
+ *
* @since 3.9.3
- *
+ *
* @param object $theme WP_Theme object
* @param array $themes Array of theme objects
*/
- do_action('jetpack_pre_theme_upgrade', $theme, $this->themes);
+ do_action( 'jetpack_pre_theme_upgrade', $theme, $this->themes );
// Objects created inside the for loop to clean the messages for each theme
- $skin = new Automatic_Upgrader_Skin();
+ $skin = new Automatic_Upgrader_Skin();
$upgrader = new Theme_Upgrader( $skin );
$upgrader->init();
- $result = $upgrader->upgrade( $theme );
+ $result = $upgrader->upgrade( $theme );
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages();
}
@@ -83,21 +125,26 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
return true;
}
- function update_translations() {
+ /**
+ * Update translations.
+ *
+ * @return bool|WP_Error
+ */
+ public 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 ) ) {
+ foreach ( $available_themes_updates->translations as $translation ) {
+ $theme = $translation['slug'];
+ if ( ! in_array( $translation['slug'], $this->themes, true ) ) {
$this->log[ $theme ][] = __( 'No update needed', 'jetpack' );
continue;
}
@@ -112,11 +159,11 @@ class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_En
*/
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();
+ $skin = new Automatic_Upgrader_Skin();
$upgrader = new Language_Pack_Upgrader( $skin );
$upgrader->init();
- $result = $upgrader->upgrade( (object) $translation );
+ $result = $upgrader->upgrade( (object) $translation );
$this->log[ $theme ] = $upgrader->skin->get_upgrade_messages();
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-new-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-new-endpoint.php
index 75768183..d70fae8b 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-new-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-new-endpoint.php
@@ -1,15 +1,47 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
-include_once ABSPATH . 'wp-admin/includes/file.php';
+require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
+require_once ABSPATH . 'wp-admin/includes/file.php';
+use Automattic\Jetpack\Automatic_Install_Skin;
+
+/**
+ * Themes new endpoint class.
+ *
+ * /sites/%s/themes/%s/install
+ */
class Jetpack_JSON_API_Themes_New_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
- // POST /sites/%s/themes/%s/install
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'install_themes';
- protected $action = 'install';
- protected $download_links = array();
+ /**
+ * Action.
+ *
+ * @var string
+ */
+ protected $action = 'install';
+
+ /**
+ * Download links.
+ *
+ * @var array
+ */
+ protected $download_links = array();
+
+ /**
+ * Validate the call.
+ *
+ * @param int $_blog_id - the blod ID.
+ * @param string $capability - the capability we're checking.
+ * @param bool $check_manage_active - if managing capabilities is active.
+ *
+ * @return bool|WP_Error
+ */
protected function validate_call( $_blog_id, $capability, $check_manage_active = true ) {
$validate = parent::validate_call( $_blog_id, $capability, $check_manage_active );
if ( is_wp_error( $validate ) ) {
@@ -23,23 +55,32 @@ class Jetpack_JSON_API_Themes_New_Endpoint extends Jetpack_JSON_API_Themes_Endpo
return $validate;
}
- protected function validate_input( $theme ) {
- $this->bulk = false;
+ /**
+ * Validate the input.
+ *
+ * @param string $theme - the theme.
+ */
+ protected function validate_input( $theme ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
+ $this->bulk = false;
$this->themes = array();
}
- function install() {
+ /**
+ * Install the theme.
+ *
+ * @return bool
+ */
+ public function install() {
$args = $this->input();
if ( isset( $args['zip'][0]['id'] ) ) {
$attachment_id = $args['zip'][0]['id'];
- $local_file = get_attached_file( $attachment_id );
+ $local_file = get_attached_file( $attachment_id );
if ( ! $local_file ) {
return new WP_Error( 'local-file-does-not-exist' );
}
- jetpack_require_lib( 'class.jetpack-automatic-install-skin' );
- $skin = new Jetpack_Automatic_Install_Skin();
- $upgrader = new Theme_Upgrader( $skin );
+ $skin = new Automatic_Install_Skin();
+ $upgrader = new Theme_Upgrader( $skin );
$pre_install_list = wp_get_themes();
$result = $upgrader->install( $local_file );
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php
index 65b6e725..49f89745 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-endpoint.php
@@ -1,20 +1,45 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-// Translations
+/**
+ * Translations endpoint class.
+ *
+ * GET /sites/%s/translations
+ * POST /sites/%s/translations
+ * POST /sites/%s/translations/update
+ */
class Jetpack_JSON_API_Translations_Endpoint extends Jetpack_JSON_API_Endpoint {
- // GET /sites/%s/translations
- // POST /sites/%s/translations
- // POST /sites/%s/translations/update
+ /**
+ * Needed capabilities.
+ *
+ * @var array
+ */
protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' );
+
+ /**
+ * The log.
+ *
+ * @var array
+ */
protected $log;
+
+ /**
+ * If we're successful.
+ *
+ * @var bool
+ */
protected $success;
+ /**
+ * API Endpoint.
+ *
+ * @return array
+ */
public function result() {
return array(
- 'translations' => wp_get_translation_updates(),
- 'autoupdate' => Jetpack_Options::get_option( 'autoupdate_translations', false ),
- 'log' => $this->log,
- 'success' => $this->success,
+ 'translations' => wp_get_translation_updates(),
+ 'autoupdate' => Jetpack_Options::get_option( 'autoupdate_translations', false ),
+ 'log' => $this->log,
+ 'success' => $this->success,
);
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php
index fd5f6a56..e2553029 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-translations-modify-endpoint.php
@@ -1,12 +1,38 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Translations modify endpoint class.
+ * POST /sites/%s/translation
+ * POST /sites/%s/translations/update
+ */
class Jetpack_JSON_API_Translations_Modify_Endpoint extends Jetpack_JSON_API_Translations_Endpoint {
- // POST /sites/%s/translations
- // POST /sites/%s/translations/update
- protected $action = 'default_action';
+
+ /**
+ * The action.
+ *
+ * @var string
+ */
+ protected $action = 'default_action';
+
+ /**
+ * The new version.
+ *
+ * @var string
+ */
protected $new_version;
+
+ /**
+ * The log.
+ *
+ * @var array
+ */
protected $log;
+ /**
+ * Run the default action.
+ *
+ * @return true
+ */
public function default_action() {
$args = $this->input();
@@ -17,13 +43,16 @@ class Jetpack_JSON_API_Translations_Modify_Endpoint extends Jetpack_JSON_API_Tra
return true;
}
+ /**
+ * Update the translations.
+ */
protected function update() {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin() );
- $result = $upgrader->bulk_upgrade();
+ $result = $upgrader->bulk_upgrade();
- $this->log = $upgrader->skin->get_upgrade_messages();
+ $this->log = $upgrader->skin->get_upgrade_messages();
$this->success = ( ! is_wp_error( $result ) ) ? (bool) $result : false;
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-updates-status-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-updates-status-endpoint.php
index 48f9ae9d..f8bb2c06 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-updates-status-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-updates-status-endpoint.php
@@ -1,23 +1,37 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Updates status class.
+ *
+ * GET /sites/%s/updates
+ */
class Jetpack_JSON_API_Updates_Status extends Jetpack_JSON_API_Endpoint {
- // GET /sites/%s/updates
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'manage_options';
+ /**
+ * Endpoint callback.
+ *
+ * @return array|WP_Error
+ */
protected function result() {
wp_update_themes();
wp_update_plugins();
$update_data = wp_get_update_data();
- if ( ! isset( $update_data['counts'] ) ) {
+ if ( ! isset( $update_data['counts'] ) ) {
return new WP_Error( 'get_update_data_error', __( 'There was an error while getting the update data for this site.', 'jetpack' ), 500 );
}
$result = $update_data['counts'];
- include( ABSPATH . WPINC . '/version.php' ); // $wp_version;
- $result['wp_version'] = isset( $wp_version ) ? $wp_version : null;
+ include ABSPATH . WPINC . '/version.php'; // $wp_version;
+ $result['wp_version'] = isset( $wp_version ) ? $wp_version : null; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
if ( ! empty( $result['wordpress'] ) ) {
$cur = get_preferred_from_update_core();
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
index b88d0406..5424e5b5 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-connect-endpoint.php
@@ -1,21 +1,52 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
use Automattic\Jetpack\Connection\Tokens;
+/**
+ * User connect endpoint class.
+ */
class Jetpack_JSON_API_User_Connect_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'create_users';
+ /**
+ * The user ID.
+ *
+ * @var int
+ */
private $user_id;
+
+ /**
+ * The user token.
+ *
+ * @var string
+ */
private $user_token;
- function result() {
+ /**
+ * The endpoint callback.
+ *
+ * @return array
+ */
+ public function result() {
( new Tokens() )->update_user_token( $this->user_id, sprintf( '%s.%d', $this->user_token, $this->user_id ), false );
return array( 'success' => ( new Connection_Manager( 'jetpack' ) )->is_user_connected( $this->user_id ) );
}
- function validate_input( $user_id ) {
+ /**
+ * Validate input.
+ *
+ * @param int $user_id - the User ID.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $user_id ) {
$input = $this->input();
if ( ! isset( $user_id ) ) {
return new WP_Error( 'input_error', __( 'user_id is required', 'jetpack' ) );
@@ -27,7 +58,7 @@ class Jetpack_JSON_API_User_Connect_Endpoint extends Jetpack_JSON_API_Endpoint {
if ( ! isset( $input['user_token'] ) ) {
return new WP_Error( 'input_error', __( 'user_token is required', 'jetpack' ) );
}
- $this->user_token = sanitize_text_field( $input[ 'user_token'] );
+ $this->user_token = sanitize_text_field( $input['user_token'] );
return parent::validate_input( $user_id );
}
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
index 1a45b317..13a70ea7 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-user-create-endpoint.php
@@ -1,38 +1,68 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Constants;
+/**
+ * User create endpoint class.
+ */
class Jetpack_JSON_API_User_Create_Endpoint extends Jetpack_JSON_API_Endpoint {
+ /**
+ * Needed capabilities.
+ *
+ * @var string
+ */
protected $needed_capabilities = 'create_users';
+ /**
+ * User data.
+ *
+ * @var array
+ */
private $user_data;
- function result() {
+ /**
+ * Endpoint callback.
+ *
+ * @return object|false
+ */
+ public function result() {
return $this->create_or_get_user();
}
- function validate_input( $object ) {
+ /**
+ * Validate the input.
+ *
+ * @param object $object - the object.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) {
$this->user_data = $this->input();
if ( empty( $this->user_data ) ) {
return new WP_Error( 'input_error', __( 'user_data is required', 'jetpack' ) );
}
- if ( ! isset( $this->user_data[ 'email' ] ) ) {
+ if ( ! isset( $this->user_data['email'] ) ) {
return new WP_Error( 'input_error', __( 'user email is required', 'jetpack' ) );
}
- if ( ! isset( $this->user_data[ 'login' ] ) ) {
+ if ( ! isset( $this->user_data['login'] ) ) {
return new WP_Error( 'input_error', __( 'user login is required', 'jetpack' ) );
}
return parent::validate_input( $object );
}
- function create_or_get_user() {
+ /**
+ * Create or get the user.
+ *
+ * @return object|false
+ */
+ public function create_or_get_user() {
require_once JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php';
// Check for an existing user
- $user = get_user_by( 'email', $this->user_data['email'] );
+ $user = get_user_by( 'email', $this->user_data['email'] );
$roles = (array) $this->user_data['roles'];
- $role = array_pop( $roles );
+ $role = array_pop( $roles );
$query_args = $this->query_args();
if ( isset( $query_args['invite_accepted'] ) && $query_args['invite_accepted'] ) {
@@ -41,12 +71,12 @@ class Jetpack_JSON_API_User_Create_Endpoint extends Jetpack_JSON_API_Endpoint {
if ( ! $user ) {
// We modify the input here to mimick the same call structure of the update user endpoint.
- $this->user_data = (object) $this->user_data;
- $this->user_data->role = $role;
- $this->user_data->url = isset( $this->user_data->URL ) ? $this->user_data->URL : '';
+ $this->user_data = (object) $this->user_data;
+ $this->user_data->role = $role;
+ $this->user_data->url = isset( $this->user_data->URL ) ? $this->user_data->URL : '';
$this->user_data->display_name = $this->user_data->name;
- $this->user_data->description = '';
- $user = Jetpack_SSO_Helpers::generate_user( $this->user_data );
+ $this->user_data->description = '';
+ $user = Jetpack_SSO_Helpers::generate_user( $this->user_data );
}
if ( is_multisite() ) {
@@ -61,10 +91,17 @@ class Jetpack_JSON_API_User_Create_Endpoint extends Jetpack_JSON_API_Endpoint {
return $this->get_user( $user->ID );
}
+ /**
+ * Get the user.
+ *
+ * @param int $user_id - the user ID.
+ *
+ * @return object|WP_Error
+ */
public function get_user( $user_id ) {
$the_user = $this->get_author( $user_id, true );
if ( $the_user && ! is_wp_error( $the_user ) ) {
- $userdata = get_userdata( $user_id );
+ $userdata = get_userdata( $user_id );
$the_user->roles = ! is_wp_error( $userdata ) ? $userdata->roles : array();
}
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
index 16895cd4..6f89997d 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php
@@ -1,7 +1,10 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Sync\Defaults;
+/**
+ * Get option endpoint.
+ */
class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
/**
* This endpoint allows authentication both via a blog and a user token.
@@ -11,18 +14,41 @@ class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
*/
protected $needed_capabilities = 'manage_options';
+ /**
+ * Options name.
+ *
+ * @var string
+ */
public $option_name;
+
+ /**
+ * Site option.
+ *
+ * @var string
+ */
public $site_option;
- function result() {
+ /**
+ * Endpoint callback.
+ *
+ * @return array
+ */
+ public function result() {
if ( $this->site_option ) {
return array( 'option_value' => get_site_option( $this->option_name ) );
}
return array( 'option_value' => get_option( $this->option_name ) );
}
- function validate_input( $object ) {
- $query_args = $this->query_args();
+ /**
+ * Validate the input.
+ *
+ * @param object $object - unused, for parent class compatability.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
+ $query_args = $this->query_args();
$this->option_name = isset( $query_args['option_name'] ) ? $query_args['option_name'] : false;
if ( ! $this->option_name ) {
return new WP_Error( 'option_name_not_set', __( 'You must specify an option_name', 'jetpack' ) );
@@ -39,7 +65,7 @@ class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
* @param array The default list of site options.
* @param bool Is the option a site option.
*/
- if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ) ) ) {
+ if ( ! in_array( $this->option_name, apply_filters( 'jetpack_options_whitelist', Defaults::$default_options_whitelist, $this->site_option ), true ) ) {
return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
}
return true;
diff --git a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php
index 20f8895c..746879b7 100644
--- a/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php
+++ b/plugins/jetpack/json-endpoints/jetpack/class.wpcom-json-api-update-option-endpoint.php
@@ -1,9 +1,22 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
+/**
+ * Update option endpoint.
+ */
class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_Endpoint {
+ /**
+ * The option value.
+ *
+ * @var string
+ */
public $option_value;
- function result() {
+ /**
+ * Endpoint callback.
+ *
+ * @return array
+ */
+ public function result() {
if ( $this->site_option ) {
update_site_option( $this->option_name, $this->option_value );
} else {
@@ -12,8 +25,15 @@ class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_En
return parent::result();
}
- function validate_input( $object ) {
- $input = $this->input();
+ /**
+ * Validate the input.
+ *
+ * @param object $object - the object we're validating.
+ *
+ * @return bool|WP_Error
+ */
+ public function validate_input( $object ) {
+ $input = $this->input();
$query_args = $this->query_args();
if ( ! isset( $input['option_value'] ) || is_array( $input['option_value'] ) ) {
return new WP_Error( 'option_value_not_set', __( 'You must specify an option_value', 'jetpack' ) );
diff --git a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
index f252fa75..da377d72 100644
--- a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
+++ b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php
@@ -1,12 +1,12 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
-$json_jetpack_endpoints_dir = dirname( __FILE__ ) . '/';
+$json_jetpack_endpoints_dir = __DIR__ . '/';
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-endpoint.php';
// THEMES
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-active-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-active-endpoint.php';
new Jetpack_JSON_API_Themes_Active_Endpoint(
array(
@@ -57,7 +57,7 @@ new Jetpack_JSON_API_Themes_Active_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-list-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-list-endpoint.php';
new Jetpack_JSON_API_Themes_List_Endpoint(
array(
@@ -83,8 +83,8 @@ new Jetpack_JSON_API_Themes_List_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-get-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-new-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-get-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-new-endpoint.php';
// POST /sites/%s/themes/%new
new Jetpack_JSON_API_Themes_New_Endpoint(
@@ -133,7 +133,7 @@ new Jetpack_JSON_API_Themes_Get_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-modify-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-modify-endpoint.php';
new Jetpack_JSON_API_Themes_Modify_Endpoint(
array(
'description' => 'Modify a single theme on a jetpack blog',
@@ -198,7 +198,7 @@ new Jetpack_JSON_API_Themes_Modify_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-install-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-install-endpoint.php';
// POST /sites/%s/themes/%s/install
new Jetpack_JSON_API_Themes_Install_Endpoint(
array(
@@ -222,7 +222,7 @@ new Jetpack_JSON_API_Themes_Install_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-delete-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-delete-endpoint.php';
// POST /sites/%s/themes/%s/delete
new Jetpack_JSON_API_Themes_Delete_Endpoint(
array(
@@ -246,22 +246,21 @@ new Jetpack_JSON_API_Themes_Delete_Endpoint(
)
);
-
// PLUGINS
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-get-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-list-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-new-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-install-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-delete-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-modify-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-get-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-list-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-new-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-install-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-delete-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-modify-endpoint.php';
// PLUGINS V1.2
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-modify-v1-2-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-modify-v1-2-endpoint.php';
// Jetpack Modules
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-get-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-get-endpoint.php';
new Jetpack_JSON_API_Modules_Get_Endpoint(
array(
@@ -284,7 +283,7 @@ new Jetpack_JSON_API_Modules_Get_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-modify-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-modify-endpoint.php';
new Jetpack_JSON_API_Modules_Modify_Endpoint(
array(
@@ -313,7 +312,7 @@ new Jetpack_JSON_API_Modules_Modify_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-list-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-list-endpoint.php';
new Jetpack_JSON_API_Modules_List_Endpoint(
array(
@@ -365,134 +364,142 @@ new Jetpack_JSON_API_Modules_List_V1_2_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-updates-status-endpoint.php' );
-
-new Jetpack_JSON_API_Updates_Status( array(
- 'description' => 'Get counts for available updates',
- 'method' => 'GET',
- 'path' => '/sites/%s/updates',
- 'stat' => 'updates',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'plugins' => '(int) The total number of plugins updates.',
- 'themes' => '(int) The total number of themes updates.',
- 'wordpress' => '(int) The total number of core updates.',
- 'translations' => '(int) The total number of translation updates.',
- 'total' => '(int) The total number of updates.',
- 'wp_version' => '(safehtml) The wp_version string.',
- 'wp_update_version' => '(safehtml) The wp_version to update string.',
- 'jp_version' => '(safehtml) The site Jetpack version.',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/updates'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-updates-status-endpoint.php';
+new Jetpack_JSON_API_Updates_Status(
+ array(
+ 'description' => 'Get counts for available updates',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/updates',
+ 'stat' => 'updates',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'plugins' => '(int) The total number of plugins updates.',
+ 'themes' => '(int) The total number of themes updates.',
+ 'wordpress' => '(int) The total number of core updates.',
+ 'translations' => '(int) The total number of translation updates.',
+ 'total' => '(int) The total number of updates.',
+ 'wp_version' => '(safehtml) The wp_version string.',
+ 'wp_update_version' => '(safehtml) The wp_version to update string.',
+ 'jp_version' => '(safehtml) The site Jetpack version.',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/updates',
+ )
+);
// Jetpack Extras
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-check-capabilities-endpoint.php' );
-
-new Jetpack_JSON_API_Check_Capabilities_Endpoint( array(
- 'description' => 'Check if the current user has a certain capability over a Jetpack site',
- 'method' => 'GET',
- 'path' => '/sites/%s/me/capability',
- 'stat' => 'me:capabulity',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => '(bool) True if the user has the queried capability.',
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- 'body' => array(
- 'capability' => 'A single capability or an array of capabilities'
- )
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/me/capability'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-check-capabilities-endpoint.php';
+new Jetpack_JSON_API_Check_Capabilities_Endpoint(
+ array(
+ 'description' => 'Check if the current user has a certain capability over a Jetpack site',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/me/capability',
+ 'stat' => 'me:capabulity',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => '(bool) True if the user has the queried capability.',
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'capability' => 'A single capability or an array of capabilities',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/me/capability',
+ )
+);
// CORE
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-core-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-core-modify-endpoint.php' );
-
-new Jetpack_JSON_API_Core_Endpoint( array(
- 'description' => 'Gets info about a Jetpack blog\'s core installation',
- 'method' => 'GET',
- 'path' => '/sites/%s/core',
- 'stat' => 'core',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'version' => '(string) The current version',
- 'autoupdate' => '(bool) Whether or not we automatically update core'
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core'
-) );
-
-new Jetpack_JSON_API_Core_Modify_Endpoint( array(
- 'description' => 'Update WordPress installation on a Jetpack blog',
- 'method' => 'POST',
- 'path' => '/sites/%s/core/update',
- 'stat' => 'core:update',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'version' => '(string) The core version to update',
- ),
- 'response_format' => array(
- 'version' => '(string) The core version after the upgrade has run.',
- 'log' => '(array:safehtml) An array of log strings.',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core/update'
-) );
-
-new Jetpack_JSON_API_Core_Endpoint( array(
- 'description' => 'Toggle automatic core updates for a Jetpack blog',
- 'method' => 'POST',
- 'path' => '/sites/%s/core',
- 'stat' => 'core',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'autoupdate' => '(bool) Whether or not we automatically update core',
- ),
- 'response_format' => array(
- 'version' => '(string) The current version',
- 'autoupdate' => '(bool) Whether or not we automatically update core'
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- 'body' => array(
- 'autoupdate' => true,
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core'
-) );
-
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-sync-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-core-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-core-modify-endpoint.php';
+
+new Jetpack_JSON_API_Core_Endpoint(
+ array(
+ 'description' => 'Gets info about a Jetpack blog\'s core installation',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/core',
+ 'stat' => 'core',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'version' => '(string) The current version',
+ 'autoupdate' => '(bool) Whether or not we automatically update core',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core',
+ )
+);
+
+new Jetpack_JSON_API_Core_Modify_Endpoint(
+ array(
+ 'description' => 'Update WordPress installation on a Jetpack blog',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/core/update',
+ 'stat' => 'core:update',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'version' => '(string) The core version to update',
+ ),
+ 'response_format' => array(
+ 'version' => '(string) The core version after the upgrade has run.',
+ 'log' => '(array:safehtml) An array of log strings.',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core/update',
+ )
+);
+
+new Jetpack_JSON_API_Core_Endpoint(
+ array(
+ 'description' => 'Toggle automatic core updates for a Jetpack blog',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/core',
+ 'stat' => 'core',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'autoupdate' => '(bool) Whether or not we automatically update core',
+ ),
+ 'response_format' => array(
+ 'version' => '(string) The current version',
+ 'autoupdate' => '(bool) Whether or not we automatically update core',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'autoupdate' => true,
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/core',
+ )
+);
+
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-sync-endpoint.php';
// POST /sites/%s/sync
new Jetpack_JSON_API_Sync_Endpoint(
@@ -560,7 +567,6 @@ new Jetpack_JSON_API_Sync_Status_Endpoint(
)
);
-
// GET /sites/%s/data-checksums
new Jetpack_JSON_API_Sync_Check_Endpoint(
array(
@@ -653,7 +659,7 @@ $sync_settings_response = array(
'max_queue_size_full_sync' => '(int|bool=false) Maximum queue size that full sync is allowed to use',
'full_sync_send_duration' => '(float) Max full sync duration per request',
'sync_via_cron' => '(int|bool=false) Set to 1 or true to avoid using cron for sync.',
- 'cron_sync_time_limit' => '(int|bool=false) Limit cron jobs to number of seconds',
+ 'cron_sync_time_limit' => '(int|bool=false) Limit cron jobs to number of seconds',
'enqueue_wait_time' => '(int|bool=false) Wait time in seconds between attempting to continue a full sync, via requests',
'sync_sender_enabled' => '(int|bool=false) Set to 1 or true to enable the default sender for the incremental queue.',
'full_sync_sender_enabled' => '(int|bool=false) Set to 1 or true to enable the default sender for the "full sync" queue.',
@@ -740,7 +746,6 @@ new Jetpack_JSON_API_Sync_Now_Endpoint(
)
);
-
// POST /sites/%s/sync/unlock
new Jetpack_JSON_API_Sync_Unlock_Endpoint(
array(
@@ -841,115 +846,125 @@ new Jetpack_JSON_API_Sync_Close_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-log-endpoint.php' );
-
-new Jetpack_JSON_API_Jetpack_Log_Endpoint( array(
- 'description' => 'Get the Jetpack log',
- 'method' => 'GET',
- 'path' => '/sites/%s/jetpack-log',
- 'stat' => 'log',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'event' => '(string) The event to filter by, by default all entries are returned',
- 'num' => '(int) The number of entries to get, by default all entries are returned'
- ),
- 'response_format' => array(
- 'log' => '(array) An array of jetpack log entries'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/jetpack-log'
-) );
-
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-maybe-auto-update-endpoint.php' );
-
-new Jetpack_JSON_API_Maybe_Auto_Update_Endpoint( array(
- 'description' => 'Maybe Auto Update Core, Plugins, Themes and Languages',
- 'method' => 'POST',
- 'path' => '/sites/%s/maybe-auto-update',
- 'stat' => 'maybe-auto-update',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'log' => '(array) Results of running the update job'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/maybe-auto-update'
-
-) );
-
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-endpoint.php' );
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-modify-endpoint.php' );
-
-new Jetpack_JSON_API_Translations_Endpoint( array(
- 'description' => 'Gets info about a Jetpack blog\'s core installation',
- 'method' => 'GET',
- 'path' => '/sites/%s/translations',
- 'stat' => 'translations',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'translations' => '(array) A list of translations that are available',
- 'autoupdate' => '(bool) Whether or not we automatically update translations',
- 'log' => '(array:safehtml) An array of log strings.',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations'
-) );
-
-new Jetpack_JSON_API_Translations_Modify_Endpoint( array(
- 'description' => 'Toggle automatic core updates for a Jetpack blog',
- 'method' => 'POST',
- 'path' => '/sites/%s/translations',
- 'stat' => 'translations',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'autoupdate' => '(bool) Whether or not we automatically update translations',
- ),
- 'response_format' => array(
- 'translations' => '(array) A list of translations that are available',
- 'autoupdate' => '(bool) Whether or not we automatically update translations',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- 'body' => array(
- 'autoupdate' => true,
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations'
-) );
-
-new Jetpack_JSON_API_Translations_Modify_Endpoint( array(
- 'description' => 'Update All Translations installation on a Jetpack blog',
- 'method' => 'POST',
- 'path' => '/sites/%s/translations/update',
- 'stat' => 'translations:update',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'log' => '(array:safehtml) An array of log strings.',
- 'success' => '(bool) Was the operation successful'
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations/update'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-log-endpoint.php';
+
+new Jetpack_JSON_API_Jetpack_Log_Endpoint(
+ array(
+ 'description' => 'Get the Jetpack log',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/jetpack-log',
+ 'stat' => 'log',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'event' => '(string) The event to filter by, by default all entries are returned',
+ 'num' => '(int) The number of entries to get, by default all entries are returned',
+ ),
+ 'response_format' => array(
+ 'log' => '(array) An array of jetpack log entries',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/jetpack-log',
+ )
+);
+
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-maybe-auto-update-endpoint.php';
+
+new Jetpack_JSON_API_Maybe_Auto_Update_Endpoint(
+ array(
+ 'description' => 'Maybe Auto Update Core, Plugins, Themes and Languages',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/maybe-auto-update',
+ 'stat' => 'maybe-auto-update',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'log' => '(array) Results of running the update job',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/maybe-auto-update',
+
+ )
+);
+
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-endpoint.php';
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-translations-modify-endpoint.php';
+
+new Jetpack_JSON_API_Translations_Endpoint(
+ array(
+ 'description' => 'Gets info about a Jetpack blog\'s core installation',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/translations',
+ 'stat' => 'translations',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'translations' => '(array) A list of translations that are available',
+ 'autoupdate' => '(bool) Whether or not we automatically update translations',
+ 'log' => '(array:safehtml) An array of log strings.',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations',
+ )
+);
+
+new Jetpack_JSON_API_Translations_Modify_Endpoint(
+ array(
+ 'description' => 'Toggle automatic core updates for a Jetpack blog',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/translations',
+ 'stat' => 'translations',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'autoupdate' => '(bool) Whether or not we automatically update translations',
+ ),
+ 'response_format' => array(
+ 'translations' => '(array) A list of translations that are available',
+ 'autoupdate' => '(bool) Whether or not we automatically update translations',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'autoupdate' => true,
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations',
+ )
+);
+
+new Jetpack_JSON_API_Translations_Modify_Endpoint(
+ array(
+ 'description' => 'Update All Translations installation on a Jetpack blog',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/translations/update',
+ 'stat' => 'translations:update',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'log' => '(array:safehtml) An array of log strings.',
+ 'success' => '(bool) Was the operation successful',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/translations/update',
+ )
+);
// Options
-require_once( $json_jetpack_endpoints_dir . 'class.wpcom-json-api-get-option-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.wpcom-json-api-get-option-endpoint.php';
new WPCOM_JSON_API_Get_Option_Endpoint(
array(
@@ -976,7 +991,7 @@ new WPCOM_JSON_API_Get_Option_Endpoint(
)
);
-require_once( $json_jetpack_endpoints_dir . 'class.wpcom-json-api-update-option-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.wpcom-json-api-update-option-endpoint.php';
new WPCOM_JSON_API_Update_Option_Endpoint(
array(
@@ -1010,342 +1025,364 @@ new WPCOM_JSON_API_Update_Option_Endpoint(
)
);
-
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-cron-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-cron-endpoint.php';
// GET /sites/%s/cron
-new Jetpack_JSON_API_Cron_Endpoint( array(
- 'description' => 'Fetches the cron array',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/cron',
- 'stat' => 'cron-get',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'response_format' => array(
- 'cron_array' => '(array) The cron array',
- 'current_timestamp' => '(int) Current server timestamp'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron',
- 'example_request_data' => array(
- 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
- ),
-) );
+new Jetpack_JSON_API_Cron_Endpoint(
+ array(
+ 'description' => 'Fetches the cron array',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/cron',
+ 'stat' => 'cron-get',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'cron_array' => '(array) The cron array',
+ 'current_timestamp' => '(int) Current server timestamp',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron',
+ 'example_request_data' => array(
+ 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
+ ),
+ )
+);
// POST /sites/%s/cron
-new Jetpack_JSON_API_Cron_Post_Endpoint( array(
- 'description' => 'Process items in the cron',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/cron',
- 'stat' => 'cron-run',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'hooks' => '(array) List of hooks to run if they have been scheduled (optional)',
- ),
- 'response_format' => array(
- 'success' => '(array) Of processed hooks with their arguments'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron',
- 'example_request_data' => array(
- 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
- 'body' => array(
- 'hooks' => array( 'jetpack_sync_cron' )
- ),
- ),
-) );
+new Jetpack_JSON_API_Cron_Post_Endpoint(
+ array(
+ 'description' => 'Process items in the cron',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/cron',
+ 'stat' => 'cron-run',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'hooks' => '(array) List of hooks to run if they have been scheduled (optional)',
+ ),
+ 'response_format' => array(
+ 'success' => '(array) Of processed hooks with their arguments',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron',
+ 'example_request_data' => array(
+ 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
+ 'body' => array(
+ 'hooks' => array( 'jetpack_sync_cron' ),
+ ),
+ ),
+ )
+);
// POST /sites/%s/cron/schedule
-new Jetpack_JSON_API_Cron_Schedule_Endpoint( array(
- 'description' => 'Schedule one or a recurring hook to fire at a particular time',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/cron/schedule',
- 'stat' => 'cron-schedule',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'hook' => '(string) Hook name that should run when the event is scheduled',
- 'timestamp' => '(int) Timestamp when the event should take place, has to be in the future',
- 'arguments' => '(string) JSON Object of arguments that the hook will use (optional)',
- 'recurrence' => '(string) How often the event should take place. If empty only one event will be scheduled. Possible values 1min, hourly, twicedaily, daily (optional) '
- ),
- 'response_format' => array(
- 'success' => '(bool) Was the event scheduled?'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron/schedule',
- 'example_request_data' => array(
- 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
- 'body' => array(
- 'hook' => 'jetpack_sync_cron',
- 'arguments' => '[]',
- 'recurrence'=> '1min',
- 'timestamp' => 1476385523
- ),
- ),
-) );
+new Jetpack_JSON_API_Cron_Schedule_Endpoint(
+ array(
+ 'description' => 'Schedule one or a recurring hook to fire at a particular time',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/cron/schedule',
+ 'stat' => 'cron-schedule',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'hook' => '(string) Hook name that should run when the event is scheduled',
+ 'timestamp' => '(int) Timestamp when the event should take place, has to be in the future',
+ 'arguments' => '(string) JSON Object of arguments that the hook will use (optional)',
+ 'recurrence' => '(string) How often the event should take place. If empty only one event will be scheduled. Possible values 1min, hourly, twicedaily, daily (optional) ',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Was the event scheduled?',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron/schedule',
+ 'example_request_data' => array(
+ 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
+ 'body' => array(
+ 'hook' => 'jetpack_sync_cron',
+ 'arguments' => '[]',
+ 'recurrence' => '1min',
+ 'timestamp' => 1476385523,
+ ),
+ ),
+ )
+);
// POST /sites/%s/cron/unschedule
-new Jetpack_JSON_API_Cron_Unschedule_Endpoint( array(
- 'description' => 'Unschedule one or all events with a particular hook and arguments',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/cron/unschedule',
- 'stat' => 'cron-unschedule',
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain'
- ),
- 'request_format' => array(
- 'hook' => '(string) Name of the hook that should be unscheduled',
- 'timestamp' => '(int) Timestamp of the hook that you want to unschedule. This will unschedule only 1 event. (optional)',
- 'arguments' => '(string) JSON Object of arguments that the hook has been scheduled with (optional)',
- ),
- 'response_format' => array(
- 'success' => '(bool) Was the event unscheduled?'
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron/unschedule',
- 'example_request_data' => array(
- 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
- 'body' => array(
- 'hook' => 'jetpack_sync_cron',
- 'arguments' => '[]',
- 'timestamp' => 1476385523
- ),
- ),
-) );
-
-// BACKUPS
+new Jetpack_JSON_API_Cron_Unschedule_Endpoint(
+ array(
+ 'description' => 'Unschedule one or all events with a particular hook and arguments',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/cron/unschedule',
+ 'stat' => 'cron-unschedule',
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'hook' => '(string) Name of the hook that should be unscheduled',
+ 'timestamp' => '(int) Timestamp of the hook that you want to unschedule. This will unschedule only 1 event. (optional)',
+ 'arguments' => '(string) JSON Object of arguments that the hook has been scheduled with (optional)',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Was the event unscheduled?',
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/cron/unschedule',
+ 'example_request_data' => array(
+ 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
+ 'body' => array(
+ 'hook' => 'jetpack_sync_cron',
+ 'arguments' => '[]',
+ 'timestamp' => 1476385523,
+ ),
+ ),
+ )
+);
+
+// BACKUPS
// GET /sites/%s/database-object/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-database-object-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of a database object, along with all of its metadata',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/database-object/backup',
- 'stat' => 'database-objects:1:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'query_parameters' => array(
- 'object_type' => '(string) Type of object to fetch from the database',
- 'object_id' => '(int) ID of the database object to fetch',
- ),
- 'response_format' => array(
- 'object' => '(array) Database object row',
- 'meta' => '(array) Associative array of key/value metadata associated with the row',
- 'children' => '(array) Where appropriate, child records associated with the object. eg: Woocommerce tax rate locations',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/database-object/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-database-object-backup-endpoint.php';
+new Jetpack_JSON_API_Get_Database_Object_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of a database object, along with all of its metadata',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/database-object/backup',
+ 'stat' => 'database-objects:1:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'query_parameters' => array(
+ 'object_type' => '(string) Type of object to fetch from the database',
+ 'object_id' => '(int) ID of the database object to fetch',
+ ),
+ 'response_format' => array(
+ 'object' => '(array) Database object row',
+ 'meta' => '(array) Associative array of key/value metadata associated with the row',
+ 'children' => '(array) Where appropriate, child records associated with the object. eg: Woocommerce tax rate locations',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/database-object/backup',
+ )
+);
// GET /sites/%s/comments/%d/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-comment-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_Comment_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of a comment, along with all of its metadata',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/comments/%d/backup',
- 'stat' => 'comments:1:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- '$post' => '(int) The comment ID',
- ),
- 'response_format' => array(
- 'comment' => '(array) Comment table row',
- 'meta' => '(array) Associative array of key/value commentmeta data',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/comments/1/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-comment-backup-endpoint.php';
+new Jetpack_JSON_API_Get_Comment_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of a comment, along with all of its metadata',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/comments/%d/backup',
+ 'stat' => 'comments:1:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ '$post' => '(int) The comment ID',
+ ),
+ 'response_format' => array(
+ 'comment' => '(array) Comment table row',
+ 'meta' => '(array) Associative array of key/value commentmeta data',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/comments/1/backup',
+ )
+);
// GET /sites/%s/options/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-option-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_Option_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of an option',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/options/backup',
- 'stat' => 'options:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'query_parameters' => array(
- 'name' => '(string|array) One or more option names to include in the backup',
- ),
- 'response_format' => array(
- 'options' => '(array) Associative array of option_name => option_value entries',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- )
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/options/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-option-backup-endpoint.php';
+new Jetpack_JSON_API_Get_Option_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of an option',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/options/backup',
+ 'stat' => 'options:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'query_parameters' => array(
+ 'name' => '(string|array) One or more option names to include in the backup',
+ ),
+ 'response_format' => array(
+ 'options' => '(array) Associative array of option_name => option_value entries',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/options/backup',
+ )
+);
// GET /sites/%s/posts/%d/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-post-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_Post_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of a post, along with all of its metadata',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/posts/%d/backup',
- 'stat' => 'posts:1:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- '$post' => '(int) The post ID',
- ),
- 'response_format' => array(
- 'post' => '(array) Post table row',
- 'meta' => '(array) Associative array of key/value postmeta data',
- 'terms' => '(array) List of terms attached to the post object',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/posts/1/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-post-backup-endpoint.php';
+new Jetpack_JSON_API_Get_Post_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of a post, along with all of its metadata',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/posts/%d/backup',
+ 'stat' => 'posts:1:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ '$post' => '(int) The post ID',
+ ),
+ 'response_format' => array(
+ 'post' => '(array) Post table row',
+ 'meta' => '(array) Associative array of key/value postmeta data',
+ 'terms' => '(array) List of terms attached to the post object',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/posts/1/backup',
+ )
+);
// GET /sites/%s/terms/%d/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-term-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_Term_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of a term, along with all of its metadata',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/terms/%d/backup',
- 'stat' => 'terms:1:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- '$term' => '(int) The term ID',
- ),
- 'response_format' => array(
- 'term' => '(array) Term table row',
- 'meta' => '(array) Metadata associated with the term',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/terms/1/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-term-backup-endpoint.php';
+new Jetpack_JSON_API_Get_Term_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of a term, along with all of its metadata',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/terms/%d/backup',
+ 'stat' => 'terms:1:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ '$term' => '(int) The term ID',
+ ),
+ 'response_format' => array(
+ 'term' => '(array) Term table row',
+ 'meta' => '(array) Metadata associated with the term',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/terms/1/backup',
+ )
+);
// GET /sites/%s/users/%d/backup
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-user-backup-endpoint.php' );
-new Jetpack_JSON_API_Get_User_Backup_Endpoint( array(
- 'description' => 'Fetch a backup of a user, along with all of its metadata',
- 'group' => '__do_not_document',
- 'method' => 'GET',
- 'path' => '/sites/%s/users/%d/backup',
- 'stat' => 'users:1:backup',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- '$user' => '(int) The user ID',
- ),
- 'response_format' => array(
- 'user' => '(array) User table row',
- 'meta' => '(array) Associative array of key/value usermeta data',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/1/backup'
-) );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-get-user-backup-endpoint.php';
+new Jetpack_JSON_API_Get_User_Backup_Endpoint(
+ array(
+ 'description' => 'Fetch a backup of a user, along with all of its metadata',
+ 'group' => '__do_not_document',
+ 'method' => 'GET',
+ 'path' => '/sites/%s/users/%d/backup',
+ 'stat' => 'users:1:backup',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ '$user' => '(int) The user ID',
+ ),
+ 'response_format' => array(
+ 'user' => '(array) User table row',
+ 'meta' => '(array) Associative array of key/value usermeta data',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/1/backup',
+ )
+);
// USERS
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-user-connect-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-user-connect-endpoint.php';
// POST /sites/%s/users/%d/connect
-new Jetpack_JSON_API_User_Connect_Endpoint( array(
- 'description' => 'Creates or returns a new user given profile data',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/users/%d/connect',
- 'stat' => 'users:connect',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- '$user_id' => '(int) The site user ID to connect',
- ),
- 'request_format' => array(
- 'user_token' => '(string) The user token',
- ),
- 'response_format' => array(
- 'success' => '(bool) Was the user connected',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN',
- ),
- 'body' => array(
- 'user_token' => 'XDH55jndskjf3klh3',
- )
- ),
- 'example_response' => '{
+new Jetpack_JSON_API_User_Connect_Endpoint(
+ array(
+ 'description' => 'Creates or returns a new user given profile data',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/users/%d/connect',
+ 'stat' => 'users:connect',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ '$user_id' => '(int) The site user ID to connect',
+ ),
+ 'request_format' => array(
+ 'user_token' => '(string) The user token',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Was the user connected',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'user_token' => 'XDH55jndskjf3klh3',
+ ),
+ ),
+ 'example_response' => '{
"success" => true
}',
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/6/connect'
-) );
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/6/connect',
+ )
+);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-user-create-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-user-create-endpoint.php';
// POST /sites/%s/users/create
-new Jetpack_JSON_API_User_Create_Endpoint( array(
- 'description' => 'Creates or returns a new user given profile data',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/users/create',
- 'stat' => 'users:create',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'query_parameters' => array(
- 'invite_accepted' => '(bool=false) If the user is being created in the invite context',
- ),
- 'request_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
- 'response_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN'
- ),
- 'body' => array(
- 'roles' => array(
- array(
- 'administrator',
- )
+new Jetpack_JSON_API_User_Create_Endpoint(
+ array(
+ 'description' => 'Creates or returns a new user given profile data',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/users/create',
+ 'stat' => 'users:create',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'query_parameters' => array(
+ 'invite_accepted' => '(bool=false) If the user is being created in the invite context',
+ ),
+ 'request_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
+ 'response_format' => WPCOM_JSON_API_Site_User_Endpoint::$user_format,
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'roles' => array(
+ array(
+ 'administrator',
+ ),
+ ),
+ 'first_name' => 'John',
+ 'last_name' => 'Doe',
+ 'email' => 'john.doe@example.wordpress.org',
),
- 'first_name' => 'John',
- 'last_name' => 'Doe',
- 'email' => 'john.doe@example.wordpress.org',
- )
- ),
- 'example_response' => '{
+ ),
+ 'example_response' => '{
"ID": 18342963,
"login": "binarysmash"
"email": false,
@@ -1355,97 +1392,104 @@ new Jetpack_JSON_API_User_Create_Endpoint( array(
"profile_URL": "http:\/\/en.gravatar.com\/binarysmash",
"roles": [ "administrator" ]
}',
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/create'
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/create',
-) );
+ )
+);
-require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-jps-woocommerce-connect-endpoint.php' );
+require_once $json_jetpack_endpoints_dir . 'class.jetpack-json-api-jps-woocommerce-connect-endpoint.php';
// POST /sites/%s/jps/woo-connect
-new Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint( array(
- 'description' => 'Attempts to connect the WooCommerce plugin for this site to WooCommerce.com.',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'path' => '/sites/%s/jps/woo-connect',
- 'stat' => 'jps:woo-connect',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'request_format' => array(
- 'access_token' => '(string) The access token for WooCommerce to connect to WooCommerce.com',
- 'access_token_secret' => '(string) The access token secret for WooCommerce to connect to WooCommerce.com',
- 'user_id' => '(int) The user\'s ID after registering for a host plan',
- 'site_id' => '(int) The site\'s ID after registering for a host plan',
- ),
- 'response_format' => array(
- 'success' => '(bool) Setting access token and access token secret successful?',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN',
- ),
- 'body' => array(
- 'access_token' => '123456789',
- 'access_token_secret' => 'abcdefghiklmnop',
- 'user_id' => 1,
- 'site_id' => 2,
- ),
- ),
- 'example_response' => '{ "success": true }',
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jps/woo-connect'
-) );
+new Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint(
+ array(
+ 'description' => 'Attempts to connect the WooCommerce plugin for this site to WooCommerce.com.',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'path' => '/sites/%s/jps/woo-connect',
+ 'stat' => 'jps:woo-connect',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'access_token' => '(string) The access token for WooCommerce to connect to WooCommerce.com',
+ 'access_token_secret' => '(string) The access token secret for WooCommerce to connect to WooCommerce.com',
+ 'user_id' => '(int) The user\'s ID after registering for a host plan',
+ 'site_id' => '(int) The site\'s ID after registering for a host plan',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Setting access token and access token secret successful?',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ 'body' => array(
+ 'access_token' => '123456789',
+ 'access_token_secret' => 'abcdefghiklmnop',
+ 'user_id' => 1,
+ 'site_id' => 2,
+ ),
+ ),
+ 'example_response' => '{ "success": true }',
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jps/woo-connect',
+ )
+);
// POST /sites/%s/install-backup-helper-script
-require_once( $json_jetpack_endpoints_dir . 'class-jetpack-json-api-install-backup-helper-script-endpoint.php' );
-new Jetpack_JSON_API_Install_Backup_Helper_Script_Endpoint( array(
- 'description' => 'Setup a Helper Script, to allow Jetpack Backup to connect to this site',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'stat' => 'install-backup-helper-script',
- 'path' => '/sites/%s/install-backup-helper-script',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'request_format' => array(
- 'helper' => '(string) Base64-encoded Helper Script contents',
- ),
- 'response_format' => array(
- 'abspath' => '(string) WordPress install path',
- 'path' => '(string) Path of the helper script',
- 'url' => '(string) URL to access the helper script',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN',
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/install-backup-helper-script'
-) );
+require_once $json_jetpack_endpoints_dir . 'class-jetpack-json-api-install-backup-helper-script-endpoint.php';
+new Jetpack_JSON_API_Install_Backup_Helper_Script_Endpoint(
+ array(
+ 'description' => 'Setup a Helper Script, to allow Jetpack Backup to connect to this site',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'stat' => 'install-backup-helper-script',
+ 'path' => '/sites/%s/install-backup-helper-script',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'request_format' => array(
+ 'helper' => '(string) Base64-encoded Helper Script contents',
+ ),
+ 'response_format' => array(
+ 'abspath' => '(string) WordPress install path',
+ 'path' => '(string) Path of the helper script',
+ 'url' => '(string) URL to access the helper script',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/install-backup-helper-script',
+ )
+);
// POST /sites/%s/delete-backup-helper-script
-require_once( $json_jetpack_endpoints_dir . 'class-jetpack-json-api-delete-backup-helper-script-endpoint.php' );
-new Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint( array(
- 'description' => 'Delete a Helper Script',
- 'group' => '__do_not_document',
- 'method' => 'POST',
- 'stat' => 'delete-backup-helper-script',
- 'path' => '/sites/%s/delete-backup-helper-script',
- 'allow_jetpack_site_auth' => true,
- 'path_labels' => array(
- '$site' => '(int|string) The site ID, The site domain',
- ),
- 'response_format' => array(
- 'success' => '(bool) Deleted the Helper Script successfully?'
- ),
- 'request_format' => array(
- 'path' => '(string) Path to Helper Script to delete',
- ),
- 'example_request_data' => array(
- 'headers' => array(
- 'authorization' => 'Bearer YOUR_API_TOKEN',
- ),
- ),
- 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/delete-backup-helper-script'
-) );
+require_once $json_jetpack_endpoints_dir . 'class-jetpack-json-api-delete-backup-helper-script-endpoint.php';
+new Jetpack_JSON_API_Delete_Backup_Helper_Script_Endpoint(
+ array(
+ 'description' => 'Delete a Helper Script',
+ 'group' => '__do_not_document',
+ 'method' => 'POST',
+ 'stat' => 'delete-backup-helper-script',
+ 'path' => '/sites/%s/delete-backup-helper-script',
+ 'allow_jetpack_site_auth' => true,
+ 'path_labels' => array(
+ '$site' => '(int|string) The site ID, The site domain',
+ ),
+ 'response_format' => array(
+ 'success' => '(bool) Deleted the Helper Script successfully?',
+ ),
+ 'request_format' => array(
+ 'path' => '(string) Path to Helper Script to delete',
+ ),
+ 'example_request_data' => array(
+ 'headers' => array(
+ 'authorization' => 'Bearer YOUR_API_TOKEN',
+ ),
+ ),
+ 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/delete-backup-helper-script',
+ )
+);