Initial Commit
This commit is contained in:
parent
4c352bf02e
commit
1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Check_Capabilities_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
|
||||
// GET /sites/%s/me/capability
|
||||
public function callback( $path = '', $_blog_id = 0 ) {
|
||||
// Check minimum capability and blog membership first
|
||||
if ( is_wp_error( $error = $this->validate_call( $_blog_id, 'read', false ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$args = $this->input();
|
||||
|
||||
if ( ! isset( $args['capability'] ) || empty( $args['capability'] ) ) {
|
||||
return new WP_Error( 'missing_capability', __( 'You are required to specify a capability to check.', 'jetpack' ), 400 );
|
||||
}
|
||||
|
||||
$capability = $args['capability'];
|
||||
if ( is_array( $capability ) ) {
|
||||
$results = array_map( 'current_user_can', $capability );
|
||||
return array_combine( $capability, $results );
|
||||
} else {
|
||||
return current_user_can( $capability );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Core_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
// POST /sites/%s/core
|
||||
// POST /sites/%s/core/update
|
||||
protected $needed_capabilities = 'manage_options';
|
||||
protected $new_version;
|
||||
protected $log;
|
||||
|
||||
public function result() {
|
||||
global $wp_version;
|
||||
|
||||
return array(
|
||||
'version' => ( empty( $this->new_version ) ) ? $wp_version : $this->new_version,
|
||||
'autoupdate' => Jetpack_Options::get_option( 'autoupdate_core', false ),
|
||||
'log' => $this->log,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoint {
|
||||
// POST /sites/%s/core
|
||||
// POST /sites/%s/core/update
|
||||
protected $needed_capabilities = 'update_core';
|
||||
protected $action = 'default_action';
|
||||
protected $new_version;
|
||||
protected $log;
|
||||
|
||||
public function default_action() {
|
||||
$args = $this->input();
|
||||
|
||||
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) {
|
||||
Jetpack_Options::update_option( 'autoupdate_core', $args['autoupdate'] );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function update( $version, $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';
|
||||
|
||||
delete_site_transient( 'update_core' );
|
||||
wp_version_check( array(), true );
|
||||
|
||||
if ( $version ) {
|
||||
$update = find_core_update( $version, $locale );
|
||||
} else {
|
||||
$update = $this->find_latest_update_offer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
$skin = new Automatic_Upgrader_Skin();
|
||||
$upgrader = new Core_Upgrader( $skin );
|
||||
|
||||
$this->new_version = $upgrader->upgrade( $update );
|
||||
|
||||
$this->log = $upgrader->skin->get_upgrade_messages();
|
||||
|
||||
if ( is_wp_error( $this->new_version ) ) {
|
||||
return $this->new_version;
|
||||
}
|
||||
|
||||
return $this->new_version;
|
||||
}
|
||||
|
||||
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( '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( 'send_core_update_notification_email', '__return_false' );
|
||||
return $update;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
include 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 {
|
||||
|
||||
protected $needed_capabilities;
|
||||
protected $expected_actions = array();
|
||||
protected $action;
|
||||
|
||||
|
||||
public function callback( $path = '', $blog_id = 0, $object = null ) {
|
||||
if ( is_wp_error( $error = $this->validate_call( $blog_id, $this->needed_capabilities ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_input( $object ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->action ) ) {
|
||||
if( is_wp_error( $error = call_user_func( array( $this, $this->action ) ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->result();
|
||||
}
|
||||
|
||||
abstract protected function result();
|
||||
|
||||
protected function validate_input( $object ) {
|
||||
$args = $this->input();
|
||||
|
||||
if( isset( $args['action'] ) && $args['action'] == 'update' ) {
|
||||
$this->action = 'update';
|
||||
}
|
||||
|
||||
if ( preg_match( "/\/update\/?$/", $this->path ) ) {
|
||||
$this->action = 'update';
|
||||
|
||||
} elseif( preg_match( "/\/install\/?$/", $this->path ) ) {
|
||||
$this->action = 'install';
|
||||
|
||||
} elseif( ! empty( $args['action'] ) ) {
|
||||
if( ! in_array( $args['action'], $this->expected_actions ) ) {
|
||||
return new WP_Error( 'invalid_action', __( 'You must specify a valid action', 'jetpack' ) );
|
||||
}
|
||||
$this->action = $args['action'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches to the blog and checks current user capabilities.
|
||||
* @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 ) {
|
||||
$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $_blog_id ) );
|
||||
if ( is_wp_error( $blog_id ) ) {
|
||||
return $blog_id;
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->check_capability( $capability ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( $check_manage_active && 'GET' !== $this->method && ! Jetpack::is_module_active( 'manage' ) ) {
|
||||
return new WP_Error( 'unauthorized_full_access', __( 'Full management mode is off for this site.', 'jetpack' ), 403 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $capability
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
protected function check_capability( $capability ) {
|
||||
if ( is_array( $capability ) ) {
|
||||
// the idea is that the we can pass in an array of capabilitie that the user needs to have before we allowing them to do something
|
||||
$capabilities = ( isset( $capability['capabilities'] ) ? $capability['capabilities'] : $capability );
|
||||
|
||||
// We can pass in the number of conditions we must pass by default it is all.
|
||||
$must_pass = ( isset( $capability['must_pass'] ) && is_int( $capability['must_pass'] ) ? $capability['must_pass'] : count( $capabilities ) );
|
||||
|
||||
$failed = array(); // store the failed capabilities
|
||||
$passed = 0; //
|
||||
|
||||
foreach ( $capabilities as $cap ) {
|
||||
if ( current_user_can( $cap ) ) {
|
||||
$passed ++;
|
||||
} else {
|
||||
$failed[] = $cap;
|
||||
}
|
||||
}
|
||||
// Check that must have conditions is less then
|
||||
if ( $passed < $must_pass ) {
|
||||
return new WP_Error( 'unauthorized', sprintf( __( 'This user is not authorized to %s on this blog.', 'jetpack' ), implode( ', ', $failed ), 403 ) );
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( !current_user_can( $capability ) ) {
|
||||
return new WP_Error( 'unauthorized', sprintf( __( 'This user is not authorized to %s on this blog.', 'jetpack' ), $capability ), 403 );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Jetpack_Log_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
// GET /sites/%s/jetpack-log
|
||||
protected $needed_capabilities = 'manage_options';
|
||||
|
||||
protected function result() {
|
||||
$args = $this->input();
|
||||
$event = ( isset( $args['event'] ) && is_string( $args['event'] ) ) ? $code : false;
|
||||
$num = ( isset( $args['num'] ) ) ? intval( $num ) : false;
|
||||
|
||||
return array(
|
||||
'log' => Jetpack::get_log( $event, $num )
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Maybe_Auto_Update_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
// POST /sites/%s/maybe_auto_update
|
||||
protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' );
|
||||
|
||||
protected $update_results = array();
|
||||
|
||||
protected function result() {
|
||||
add_action( 'automatic_updates_complete', array( $this, 'get_update_results' ), 100, 1 );
|
||||
|
||||
wp_maybe_auto_update();
|
||||
|
||||
$result['log'] = $this->update_results;
|
||||
|
||||
if ( empty( $result['log'] ) ) {
|
||||
$possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures();
|
||||
|
||||
if ( $possible_reasons_for_failure ) {
|
||||
$result['log']['error'] = $possible_reasons_for_failure;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_update_results( $results ) {
|
||||
$this->update_results = $results;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base class for working with Jetpack Modules.
|
||||
*/
|
||||
abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
|
||||
protected $modules = array();
|
||||
|
||||
protected $bulk = true;
|
||||
|
||||
static $_response_format = array(
|
||||
'id' => '(string) The module\'s ID',
|
||||
'active' => '(boolean) The module\'s status.',
|
||||
'name' => '(string) The module\'s name.',
|
||||
'description' => '(safehtml) The module\'s description.',
|
||||
'sort' => '(int) The module\'s display order.',
|
||||
'introduced' => '(string) The Jetpack version when the module was introduced.',
|
||||
'changed' => '(string) The Jetpack version when the module was changed.',
|
||||
'free' => '(boolean) The module\'s Free or Paid status.',
|
||||
'module_tags' => '(array) The module\'s tags.'
|
||||
);
|
||||
|
||||
protected function result() {
|
||||
|
||||
$modules = $this->get_modules();
|
||||
|
||||
if ( ! $this->bulk && ! empty( $modules ) ) {
|
||||
return array_pop( $modules );
|
||||
}
|
||||
|
||||
return array( 'modules' => $modules );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks through either the submitted modules or list of themes and creates the global array
|
||||
* @param $theme
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_input( $module) {
|
||||
$args = $this->input();
|
||||
// lets set what modules were requested, and validate them
|
||||
if ( ! isset( $module ) || empty( $module ) ) {
|
||||
|
||||
if ( ! $args['modules'] || empty( $args['modules'] ) ) {
|
||||
return new WP_Error( 'missing_module', __( 'You are required to specify a module.', 'jetpack' ), 400 );
|
||||
}
|
||||
if ( is_array( $args['modules'] ) ) {
|
||||
$this->modules = $args['modules'];
|
||||
} else {
|
||||
$this->modules[] = $args['modules'];
|
||||
}
|
||||
} else {
|
||||
$this->modules[] = urldecode( $module );
|
||||
$this->bulk = false;
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_modules() ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return parent::validate_input( $module );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) ) {
|
||||
return new WP_Error( 'unknown_jetpack_module', sprintf( __( 'Module not found: `%s`.', 'jetpack' ), $module ), 404 );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function format_module( $module_slug ) {
|
||||
$module_data = Jetpack::get_module( $module_slug );
|
||||
|
||||
$module = array();
|
||||
$module['id'] = $module_slug;
|
||||
$module['active'] = Jetpack::is_module_active( $module_slug );
|
||||
$module['name'] = $module_data['name'];
|
||||
$module['short_description'] = $module_data['description'];
|
||||
$module['sort'] = $module_data['sort'];
|
||||
$module['introduced'] = $module_data['introduced'];
|
||||
$module['changed'] = $module_data['changed'];
|
||||
$module['free'] = $module_data['free'];
|
||||
$module['module_tags'] = $module_data['module_tags'];
|
||||
|
||||
// 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();
|
||||
|
||||
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
|
||||
*/
|
||||
protected function get_modules() {
|
||||
$modules = array_values( $this->modules );
|
||||
// do offset & limit - we've already returned a 400 error if they're bad numbers
|
||||
$args = $this->query_args();
|
||||
|
||||
if ( isset( $args['offset'] ) )
|
||||
$modules = array_slice( $modules, (int) $args['offset'] );
|
||||
if ( isset( $args['limit'] ) )
|
||||
$modules = array_slice( $modules, 0, (int) $args['limit'] );
|
||||
|
||||
return array_map( array( $this, 'format_module' ), $modules );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Modules_Get_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
|
||||
// GET /sites/%s/jetpack/modules/%s
|
||||
protected $needed_capabilities = 'jetpack_manage_modules';
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Modules_List_Endpoint extends Jetpack_JSON_API_Modules_Endpoint {
|
||||
// GET /sites/%s/jetpack/modules
|
||||
|
||||
protected $needed_capabilities = 'jetpack_manage_modules';
|
||||
|
||||
public function validate_input( $module ) {
|
||||
$this->modules = Jetpack::get_available_modules();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
|
||||
protected $needed_capabilities = 'activate_plugins';
|
||||
protected $action = 'default_action';
|
||||
|
||||
public function default_action() {
|
||||
$args = $this->input();
|
||||
if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) {
|
||||
if ( $args['active'] ) {
|
||||
return $this->activate_module();
|
||||
} else {
|
||||
return $this->deactivate_module();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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' );
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'activation_error', $error, 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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' );
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'deactivation_error', $error, 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Plugins_Delete_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
|
||||
|
||||
// POST /sites/%s/plugins/%s/delete
|
||||
protected $needed_capabilities = 'delete_plugins';
|
||||
protected $action = 'delete';
|
||||
|
||||
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.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = delete_plugins ( array( $plugin ) );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$error = $this->log[ $plugin ][] = $result->get_error_message();
|
||||
} else {
|
||||
$this->log[ $plugin ][] = 'Plugin deleted';
|
||||
}
|
||||
}
|
||||
|
||||
if( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'delete_plugin_error', $error, 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base class for working with plugins.
|
||||
*/
|
||||
abstract class Jetpack_JSON_API_Plugins_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
|
||||
protected $plugins = array();
|
||||
|
||||
protected $network_wide = false;
|
||||
|
||||
protected $bulk = true;
|
||||
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',
|
||||
'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.',
|
||||
);
|
||||
|
||||
protected function result() {
|
||||
|
||||
$plugins = $this->get_plugins();
|
||||
|
||||
if ( ! $this->bulk && ! empty( $plugins ) ) {
|
||||
return array_pop( $plugins );
|
||||
}
|
||||
|
||||
return array( 'plugins' => $plugins );
|
||||
|
||||
}
|
||||
|
||||
protected function validate_input( $plugin ) {
|
||||
|
||||
if ( is_wp_error( $error = parent::validate_input( $plugin ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_network_wide() ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
$args = $this->input();
|
||||
// find out what plugin, or plugins we are dealing with
|
||||
// validate the requested plugins
|
||||
if ( ! isset( $plugin ) || empty( $plugin ) ) {
|
||||
if ( ! $args['plugins'] || empty( $args['plugins'] ) ) {
|
||||
return new WP_Error( 'missing_plugin', __( 'You are required to specify a plugin.', 'jetpack' ), 400 );
|
||||
}
|
||||
if ( is_array( $args['plugins'] ) ) {
|
||||
$this->plugins = $args['plugins'];
|
||||
} else {
|
||||
$this->plugins[] = $args['plugins'];
|
||||
}
|
||||
} else {
|
||||
$this->bulk = false;
|
||||
$this->plugins[] = urldecode( $plugin );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_plugins() ) ) {
|
||||
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' ));
|
||||
}
|
||||
foreach( $this->plugins as $index => $plugin ) {
|
||||
if ( ! preg_match( "/\.php$/", $plugin ) ) {
|
||||
$plugin = $plugin . '.php';
|
||||
$this->plugins[ $index ] = $plugin;
|
||||
}
|
||||
if ( is_wp_error( $error = $this->validate_plugin( $plugin ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function format_plugin( $plugin_file, $plugin_data ) {
|
||||
$plugin = array();
|
||||
$plugin['id'] = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
|
||||
$plugin['slug'] = $this->get_plugin_slug( $plugin_file );
|
||||
$plugin['active'] = Jetpack::is_plugin_active( $plugin_file );
|
||||
$plugin['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 );
|
||||
$plugin['next_autoupdate'] = date( 'Y-m-d H:i:s', wp_next_scheduled( 'wp_maybe_auto_update' ) );
|
||||
$plugin['autoupdate'] = in_array( $plugin_file, Jetpack_Options::get_option( 'autoupdate_plugins', array() ) );
|
||||
$plugin['uninstallable'] = is_uninstallable_plugin( $plugin_file );
|
||||
if ( ! empty ( $this->log[ $plugin_file ] ) ) {
|
||||
$plugin['log'] = $this->log[ $plugin_file ];
|
||||
}
|
||||
return $plugin;
|
||||
}
|
||||
|
||||
protected function get_plugins() {
|
||||
$plugins = array();
|
||||
$installed_plugins = get_plugins();
|
||||
foreach( $this->plugins as $plugin ) {
|
||||
if ( ! isset( $installed_plugins[ $plugin ] ) )
|
||||
continue;
|
||||
$plugins[] = $this->format_plugin( $plugin, $installed_plugins[ $plugin ] );
|
||||
}
|
||||
$args = $this->query_args();
|
||||
|
||||
if ( isset( $args['offset'] ) ) {
|
||||
$plugins = array_slice( $plugins, (int) $args['offset'] );
|
||||
}
|
||||
if ( isset( $args['limit'] ) ) {
|
||||
$plugins = array_slice( $plugins, 0, (int) $args['limit'] );
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
protected function validate_network_wide() {
|
||||
$args = $this->input();
|
||||
|
||||
if ( isset( $args['network_wide'] ) && $args['network_wide'] ) {
|
||||
$this->network_wide = true;
|
||||
}
|
||||
|
||||
if ( $this->network_wide && ! current_user_can( 'manage_network_plugins' ) ) {
|
||||
return new WP_Error( 'unauthorized', __( 'This user is not authorized to manage plugins network wide.', 'jetpack' ), 403 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function validate_plugin( $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( urldecode( $plugin ) ) ) ) {
|
||||
return new WP_Error( 'unknown_plugin', $error->get_error_messages() , 404 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function get_plugin_updates( $plugin_file ) {
|
||||
$plugin_updates = get_plugin_updates();
|
||||
if ( isset( $plugin_updates[ $plugin_file ] ) ){
|
||||
return $plugin_updates[ $plugin_file ]->update;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function get_plugin_slug( $plugin_file ) {
|
||||
$update_plugins = get_site_transient( 'update_plugins' );
|
||||
if ( isset( $update_plugins->no_update ) ) {
|
||||
if ( isset( $update_plugins->no_update[ $plugin_file ] ) ) {
|
||||
$slug = $update_plugins->no_update[ $plugin_file ]->slug;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $slug ) && isset( $update_plugins->response ) ) {
|
||||
if ( isset( $update_plugins->response[ $plugin_file ] ) ) {
|
||||
$slug = $update_plugins->response[ $plugin_file ]->slug;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to infer from the plugin file if not cached
|
||||
if ( empty( $slug) ) {
|
||||
$slug = dirname( $plugin_file );
|
||||
if ( '.' === $slug ) {
|
||||
$slug = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
|
||||
}
|
||||
}
|
||||
return $slug;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Plugins_Get_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
|
||||
// GET /sites/%s/plugins/%s
|
||||
protected $needed_capabilities = 'activate_plugins';
|
||||
}
|
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
include_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
|
||||
class Jetpack_JSON_API_Plugins_Install_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
|
||||
|
||||
// POST /sites/%s/plugins/%s/install
|
||||
protected $needed_capabilities = 'install_plugins';
|
||||
protected $action = 'install';
|
||||
|
||||
protected function install() {
|
||||
foreach ( $this->plugins as $index => $slug ) {
|
||||
|
||||
$skin = new Jetpack_Automatic_Plugin_Install_Skin();
|
||||
$upgrader = new Plugin_Upgrader( $skin );
|
||||
$zip_url = self::generate_wordpress_org_plugin_download_link( $slug );
|
||||
|
||||
$result = $upgrader->install( $zip_url );
|
||||
|
||||
if ( ! $this->bulk && is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$plugin = self::get_plugin_id_by_slug( $slug );
|
||||
$error_code = 'install_error';
|
||||
if ( ! $plugin ) {
|
||||
$error = $this->log[ $slug ]['error'] = __( 'There was an error installing your plugin', 'jetpack' );
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && ! $result ) {
|
||||
$error_code = $upgrader->skin->get_main_error_code();
|
||||
$message = $upgrader->skin->get_main_error_message();
|
||||
$error = $this->log[ $slug ]['error'] = $message ? $message : __( 'An unknown error occurred during installation' , 'jetpack' );
|
||||
}
|
||||
|
||||
$this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages();
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && isset( $error ) ) {
|
||||
|
||||
if ( 'download_failed' === $error_code ) {
|
||||
// For backwards compatibility: versions prior to 3.9 would return no_package instead of download_failed.
|
||||
$error_code = 'no_package';
|
||||
}
|
||||
|
||||
return new WP_Error( $error_code, $this->log[ $slug ]['error'], 400 );
|
||||
}
|
||||
|
||||
// replace the slug with the actual plugin id
|
||||
$this->plugins[ $index ] = $plugin;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function validate_plugins() {
|
||||
if ( empty( $this->plugins ) || ! is_array( $this->plugins ) ) {
|
||||
return new WP_Error( 'missing_plugins', __( 'No plugins found.', 'jetpack' ) );
|
||||
}
|
||||
foreach( $this->plugins as $index => $slug ) {
|
||||
// make sure it is not already installed
|
||||
if ( self::get_plugin_id_by_slug( $slug ) ) {
|
||||
return new WP_Error( 'plugin_already_installed', __( 'The plugin is already installed', 'jetpack' ) );
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function generate_wordpress_org_plugin_download_link( $plugin_slug ) {
|
||||
return "https://downloads.wordpress.org/plugin/{$plugin_slug}.latest-stable.zip";
|
||||
}
|
||||
|
||||
protected static function get_plugin_id_by_slug( $slug ) {
|
||||
$plugins = get_plugins();
|
||||
if ( ! is_array( $plugins ) ) {
|
||||
return false;
|
||||
}
|
||||
foreach( $plugins as $plugin_file => $plugin_data ) {
|
||||
if ( self::get_slug_from_file_path( $plugin_file ) === $slug ) {
|
||||
return $plugin_file;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static function get_slug_from_file_path( $plugin_file ) {
|
||||
// Simular to get_plugin_slug() method.
|
||||
$slug = dirname( $plugin_file );
|
||||
if ( '.' === $slug ) {
|
||||
$slug = preg_replace("/(.+)\.php$/", "$1", $plugin_file );
|
||||
}
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Allows us to capture that the site doesn't have proper file system access.
|
||||
* In order to update the plugin.
|
||||
*/
|
||||
class Jetpack_Automatic_Plugin_Install_Skin extends Automatic_Upgrader_Skin {
|
||||
/**
|
||||
* Stores the last error key;
|
||||
**/
|
||||
protected $main_error_code = 'install_error';
|
||||
|
||||
/**
|
||||
* Stores the last error message.
|
||||
**/
|
||||
protected $main_error_message = 'An unknown error occurred during installation';
|
||||
|
||||
/**
|
||||
* Overwrites the set_upgrader to be able to tell if we e ven have the ability to write to the files.
|
||||
*
|
||||
* @param WP_Upgrader $upgrader
|
||||
*
|
||||
*/
|
||||
public function set_upgrader( &$upgrader ) {
|
||||
parent::set_upgrader( $upgrader );
|
||||
|
||||
// Check if we even have permission to.
|
||||
$result = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
|
||||
if ( ! $result ) {
|
||||
// set the string here since they are not available just yet
|
||||
$upgrader->generic_strings();
|
||||
$this->feedback( 'fs_unavailable' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the error function
|
||||
*/
|
||||
public function error( $error ) {
|
||||
if ( is_wp_error( $error ) ) {
|
||||
$this->feedback( $error );
|
||||
}
|
||||
}
|
||||
|
||||
private function set_main_error_code( $code ) {
|
||||
// Don't set the process_failed as code since it is not that helpful unless we don't have one already set.
|
||||
$this->main_error_code = ( $code === 'process_failed' && $this->main_error_code ? $this->main_error_code : $code );
|
||||
}
|
||||
|
||||
private function set_main_error_message( $message, $code ) {
|
||||
// Don't set the process_failed as message since it is not that helpful unless we don't have one already set.
|
||||
$this->main_error_message = ( $code === 'process_failed' && $this->main_error_code ? $this->main_error_code : $message );
|
||||
}
|
||||
|
||||
public function get_main_error_code() {
|
||||
return $this->main_error_code;
|
||||
}
|
||||
|
||||
public function get_main_error_message() {
|
||||
return $this->main_error_message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites the feedback function
|
||||
*/
|
||||
public function feedback( $data ) {
|
||||
|
||||
$current_error = null;
|
||||
if ( is_wp_error( $data ) ) {
|
||||
$this->set_main_error_code( $data->get_error_code() );
|
||||
$string = $data->get_error_message();
|
||||
} elseif ( is_array( $data ) ) {
|
||||
return;
|
||||
} else {
|
||||
$string = $data;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
|
||||
$this->set_main_error_code( $string );
|
||||
|
||||
$current_error = $string;
|
||||
$string = $this->upgrader->strings[ $string ];
|
||||
}
|
||||
|
||||
if ( strpos( $string, '%' ) !== false ) {
|
||||
$args = func_get_args();
|
||||
$args = array_splice( $args, 1 );
|
||||
if ( ! empty( $args ) )
|
||||
$string = vsprintf( $string, $args );
|
||||
}
|
||||
|
||||
$string = trim( $string );
|
||||
$string = wp_kses( $string, array(
|
||||
'a' => array(
|
||||
'href' => true
|
||||
),
|
||||
'br' => true,
|
||||
'em' => true,
|
||||
'strong' => true,
|
||||
) );
|
||||
|
||||
$this->set_main_error_message( $string, $current_error );
|
||||
$this->messages[] = $string;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Plugins_List_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
|
||||
// GET /sites/%s/plugins
|
||||
|
||||
protected $needed_capabilities = 'activate_plugins';
|
||||
|
||||
public function validate_input( $plugin ) {
|
||||
wp_update_plugins();
|
||||
$this->plugins = array_keys( get_plugins() );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
|
||||
// POST /sites/%s/plugins/%s
|
||||
// POST /sites/%s/plugins
|
||||
|
||||
protected $needed_capabilities = 'activate_plugins';
|
||||
protected $action = 'default_action';
|
||||
protected $expected_actions = array( 'update', 'install', 'delete' );
|
||||
|
||||
public function callback( $path = '', $blog_id = 0, $object = null ) {
|
||||
Jetpack_JSON_API_Endpoint::validate_input( $object );
|
||||
switch ( $this->action ) {
|
||||
case 'update' :
|
||||
$this->needed_capabilities = 'update_plugins';
|
||||
break;
|
||||
case 'install' :
|
||||
$this->needed_capabilities = 'install_plugins';
|
||||
break;
|
||||
}
|
||||
if ( isset( $args['autoupdate'] ) ) {
|
||||
$this->needed_capabilities = 'update_plugins';
|
||||
}
|
||||
|
||||
return parent::callback( $path, $blog_id, $object );
|
||||
}
|
||||
|
||||
public function default_action() {
|
||||
$args = $this->input();
|
||||
|
||||
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) {
|
||||
if ( $args['autoupdate'] ) {
|
||||
$this->autoupdate_on();
|
||||
} else {
|
||||
$this->autoupdate_off();
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) {
|
||||
if ( $args['active'] ) {
|
||||
return $this->activate();
|
||||
} else {
|
||||
return $this->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function autoupdate_on() {
|
||||
$autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
|
||||
$autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) );
|
||||
Jetpack_Options::update_option( 'autoupdate_plugins', $autoupdate_plugins );
|
||||
}
|
||||
|
||||
protected function autoupdate_off() {
|
||||
$autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins', array() );
|
||||
$autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins );
|
||||
Jetpack_Options::update_option( 'autoupdate_plugins', $autoupdate_plugins );
|
||||
}
|
||||
|
||||
protected function activate() {
|
||||
foreach ( $this->plugins as $plugin ) {
|
||||
if ( ( ! $this->network_wide && Jetpack::is_plugin_active( $plugin ) ) || is_plugin_active_for_network( $plugin ) ) {
|
||||
$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;
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = activate_plugin( $plugin, '', $this->network_wide );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$this->log[ $plugin ]['error'] = $result->get_error_messages();
|
||||
$has_errors = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
$success = Jetpack::is_plugin_active( $plugin );
|
||||
if ( $success && $this->network_wide ) {
|
||||
$success &= is_plugin_active_for_network( $plugin );
|
||||
}
|
||||
|
||||
if ( ! $success ) {
|
||||
$this->log[ $plugin ]['error'] = $result->get_error_messages;
|
||||
$has_errors = true;
|
||||
continue;
|
||||
}
|
||||
$this->log[ $plugin ][] = __( 'Plugin activated.', 'jetpack' );
|
||||
}
|
||||
if ( ! $this->bulk && isset( $has_errors ) ) {
|
||||
$plugin = $this->plugins[0];
|
||||
return new WP_Error( 'activation_error', $this->log[ $plugin ]['error'] );
|
||||
}
|
||||
}
|
||||
|
||||
protected function deactivate() {
|
||||
foreach ( $this->plugins as $plugin ) {
|
||||
if ( ! Jetpack::is_plugin_active( $plugin ) ) {
|
||||
$error = $this->log[ $plugin ]['error'] = __( 'The Plugin is already deactivated.', 'jetpack' );
|
||||
continue;
|
||||
}
|
||||
|
||||
deactivate_plugins( $plugin, false, $this->network_wide );
|
||||
|
||||
$success = ! Jetpack::is_plugin_active( $plugin );
|
||||
if ( $success && $this->network_wide ) {
|
||||
$success &= ! is_plugin_active_for_network( $plugin );
|
||||
}
|
||||
|
||||
if ( ! $success ) {
|
||||
$error = $this->log[ $plugin ]['error'] = __( 'There was an error deactivating your plugin', 'jetpack' );
|
||||
continue;
|
||||
}
|
||||
$this->log[ $plugin ][] = __( 'Plugin deactivated.', 'jetpack' );
|
||||
}
|
||||
if ( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'deactivation_error', $error );
|
||||
}
|
||||
}
|
||||
|
||||
protected function update() {
|
||||
|
||||
wp_clean_plugins_cache();
|
||||
ob_start();
|
||||
wp_update_plugins(); // Check for Plugin updates
|
||||
ob_end_clean();
|
||||
|
||||
$update_plugins = get_site_transient( 'update_plugins' );
|
||||
|
||||
if ( isset( $update_plugins->response ) ) {
|
||||
$plugin_updates_needed = array_keys( $update_plugins->response );
|
||||
} else {
|
||||
$plugin_updates_needed = array();
|
||||
}
|
||||
|
||||
$update_attempted = false;
|
||||
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
// unhook this functions that output things before we send our response header.
|
||||
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
|
||||
remove_action( 'upgrader_process_complete', 'wp_version_check' );
|
||||
remove_action( 'upgrader_process_complete', 'wp_update_themes' );
|
||||
|
||||
foreach ( $this->plugins as $plugin ) {
|
||||
|
||||
if ( ! in_array( $plugin, $plugin_updates_needed ) ) {
|
||||
$this->log[ $plugin ][] = __( 'No update needed', 'jetpack' );
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-upgrade action
|
||||
*
|
||||
* @since 3.9.3
|
||||
*
|
||||
* @param array $plugin Plugin data
|
||||
* @param array $plugin Array of plugin objects
|
||||
* @param bool $updated_attempted false for the first update, true subsequently
|
||||
*/
|
||||
do_action('jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted);
|
||||
|
||||
$update_attempted = true;
|
||||
|
||||
// Object created inside the for loop to clean the messages for each plugin
|
||||
$skin = new Automatic_Upgrader_Skin();
|
||||
// The Automatic_Upgrader_Skin skin shouldn't output anything.
|
||||
$upgrader = new Plugin_Upgrader( $skin );
|
||||
$upgrader->init();
|
||||
// This avoids the plugin to be deactivated.
|
||||
defined( 'DOING_CRON' ) or define( 'DOING_CRON', true );
|
||||
$result = $upgrader->upgrade( $plugin );
|
||||
|
||||
$this->log[ $plugin ][] = $upgrader->skin->get_upgrade_messages();
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && ! $result && $update_attempted ) {
|
||||
return new WP_Error( 'update_fail', __( 'There was an error updating your plugin', 'jetpack' ), 400 );
|
||||
}
|
||||
|
||||
return $this->default_action();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Sync_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
// POST /sites/%s/sync
|
||||
protected $needed_capabilities = 'manage_options';
|
||||
|
||||
protected function result() {
|
||||
Jetpack::init();
|
||||
/** This action is documented in class.jetpack.php */
|
||||
do_action( 'jetpack_sync_all_registered_options' );
|
||||
$result['scheduled'] = true;
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
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
|
||||
public function callback( $path = '', $blog_id = 0 ) {
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_call( $blog_id, 'switch_themes', true ) ) ) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
if ( 'POST' === $this->api->method )
|
||||
return $this->switch_theme();
|
||||
else
|
||||
return $this->get_current_theme();
|
||||
}
|
||||
|
||||
protected function switch_theme() {
|
||||
$args = $this->input();
|
||||
|
||||
if ( ! isset( $args['theme'] ) || empty( $args['theme'] ) ) {
|
||||
return new WP_Error( 'missing_theme', __( 'You are required to specify a theme to switch to.', 'jetpack' ), 400 );
|
||||
}
|
||||
|
||||
$theme_slug = $args['theme'];
|
||||
|
||||
if ( ! $theme_slug ) {
|
||||
return new WP_Error( 'theme_not_found', __( 'Theme is empty.', 'jetpack' ), 404 );
|
||||
}
|
||||
|
||||
$theme = wp_get_theme( $theme_slug );
|
||||
|
||||
if ( ! $theme->exists() ) {
|
||||
return new WP_Error( 'theme_not_found', __( 'The specified theme was not found.', 'jetpack' ), 404 );
|
||||
}
|
||||
|
||||
if ( ! $theme->is_allowed() ) {
|
||||
return new WP_Error( 'theme_not_found', __( 'You are not allowed to switch to this theme', 'jetpack' ), 403 );
|
||||
}
|
||||
|
||||
switch_theme( $theme_slug );
|
||||
|
||||
return $this->get_current_theme();
|
||||
}
|
||||
|
||||
protected function get_current_theme() {
|
||||
return $this->format_theme( wp_get_theme() );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Themes_Delete_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
|
||||
|
||||
// POST /sites/%s/plugins/%s/delete
|
||||
protected $needed_capabilities = 'delete_themes';
|
||||
protected $action = 'delete';
|
||||
|
||||
protected function delete() {
|
||||
|
||||
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.';
|
||||
continue;
|
||||
}
|
||||
|
||||
if( $theme == get_template() ) {
|
||||
$error = $this->log[ $theme ]['error'] = 'You cannot delete a theme while it is active on the main site.';
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = delete_theme( $theme );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
$error = $this->log[ $theme ]['error'] = $result->get_error_messages;
|
||||
} else {
|
||||
$this->log[ $theme ][] = 'Theme deleted';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'delete_theme_error', $error, 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
|
||||
// THEMES
|
||||
|
||||
/**
|
||||
* Base class for working with themes, has useful helper functions.
|
||||
*/
|
||||
abstract class Jetpack_JSON_API_Themes_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
|
||||
protected $themes = array();
|
||||
|
||||
protected $bulk = true;
|
||||
protected $log;
|
||||
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',
|
||||
);
|
||||
|
||||
protected function result() {
|
||||
|
||||
$themes = $this->get_themes();
|
||||
|
||||
if ( ! $this->bulk && ! empty( $themes ) ) {
|
||||
return array_pop( $themes );
|
||||
}
|
||||
|
||||
return array( 'themes' => $themes );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Walks through either the submitted theme or list of themes and creates the global array
|
||||
* @param $theme
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate_input( $theme ) {
|
||||
$args = $this->input();
|
||||
// lets set what themes were requested, and validate them
|
||||
if ( ! isset( $theme ) || empty( $theme ) ) {
|
||||
|
||||
if ( ! $args['themes'] || empty( $args['themes'] ) ) {
|
||||
return new WP_Error( 'missing_theme', __( 'You are required to specify a theme to update.', 'jetpack' ), 400 );
|
||||
}
|
||||
if ( is_array( $args['themes'] ) ) {
|
||||
$this->themes = $args['themes'];
|
||||
} else {
|
||||
$this->themes[] = $args['themes'];
|
||||
}
|
||||
} else {
|
||||
$this->themes[] = urldecode( $theme );
|
||||
$this->bulk = false;
|
||||
}
|
||||
|
||||
if ( is_wp_error( $error = $this->validate_themes() ) ) {
|
||||
return error;
|
||||
}
|
||||
|
||||
return parent::validate_input( $theme );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a theme for the public API
|
||||
* @param object $theme WP_Theme object
|
||||
* @return array Named array of theme info used by the API
|
||||
*/
|
||||
protected function format_theme( $theme ) {
|
||||
|
||||
if ( ! ( $theme instanceof WP_Theme ) ) {
|
||||
$theme = wp_get_theme( $theme );
|
||||
}
|
||||
|
||||
$fields = array(
|
||||
'name' => 'Name',
|
||||
'theme_uri' => 'ThemeURI',
|
||||
'description' => 'Description',
|
||||
'author' => 'Author',
|
||||
'author_uri' => 'AuthorURI',
|
||||
'tags' => 'Tags',
|
||||
'version' => 'Version'
|
||||
);
|
||||
|
||||
$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,
|
||||
);
|
||||
|
||||
foreach( $fields as $key => $field ) {
|
||||
$formatted_theme[ $key ] = $theme->get( $field );
|
||||
}
|
||||
|
||||
$update_themes = get_site_transient( 'update_themes' );
|
||||
$formatted_theme['update'] = ( isset( $update_themes->response[ $id ] ) ) ? $update_themes->response[ $id ] : null;
|
||||
|
||||
$autoupdate_themes = Jetpack_Options::get_option( 'autoupdate_themes', array() );
|
||||
|
||||
$autoupdate = in_array( $id, $autoupdate_themes );
|
||||
|
||||
$formatted_theme['autoupdate'] = $autoupdate;
|
||||
|
||||
if( isset( $this->log[ $id ] ) ) {
|
||||
$formatted_theme['log'] = $this->log[ $id ];
|
||||
}
|
||||
|
||||
return $formatted_theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
return new WP_Error( 'invalid_offset', __( 'Offset must be greater than or equal to 0.', 'jetpack' ), 400 );
|
||||
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
|
||||
*/
|
||||
protected function get_themes() {
|
||||
// ditch keys
|
||||
$themes = array_values( $this->themes );
|
||||
// do offset & limit - we've already returned a 400 error if they're bad numbers
|
||||
$args = $this->query_args();
|
||||
|
||||
if ( isset( $args['offset'] ) )
|
||||
$themes = array_slice( $themes, (int) $args['offset'] );
|
||||
if ( isset( $args['limit'] ) )
|
||||
$themes = array_slice( $themes, 0, (int) $args['limit'] );
|
||||
|
||||
$this->current_theme_id = wp_get_theme()->get_stylesheet();
|
||||
|
||||
return array_map( array( $this, 'format_theme' ), $themes );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Themes_Get_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
|
||||
// GET /sites/%s/themes/%s
|
||||
protected $needed_capabilities = 'activate_themes';
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
include_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
|
||||
class Jetpack_JSON_API_Themes_Install_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
|
||||
|
||||
// POST /sites/%s/themes/%s/install
|
||||
protected $needed_capabilities = 'install_themes';
|
||||
protected $action = 'install';
|
||||
protected $download_links = array();
|
||||
|
||||
protected function install() {
|
||||
|
||||
foreach ( $this->themes as $theme ) {
|
||||
|
||||
$skin = new Automatic_Upgrader_Skin();
|
||||
$upgrader = new Theme_Upgrader( $skin );
|
||||
|
||||
$result = $upgrader->install( $this->download_links[ $theme ] );
|
||||
|
||||
if ( ! $this->bulk && is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
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' );
|
||||
}
|
||||
|
||||
else {
|
||||
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && isset( $error ) ) {
|
||||
return new WP_Error( 'install_error', $error, 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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 ) {
|
||||
|
||||
if ( self::is_installed_theme( $theme ) ) {
|
||||
return new WP_Error( 'theme_already_installed', __( 'The theme is already installed', 'jetpack' ) );
|
||||
}
|
||||
|
||||
$params = (object) array( 'slug' => $theme );
|
||||
$url = 'https://api.wordpress.org/themes/info/1.0/';
|
||||
$args = array(
|
||||
'body' => array(
|
||||
'action' => 'theme_information',
|
||||
'request' => serialize( $params ),
|
||||
)
|
||||
);
|
||||
$response = wp_remote_post( $url, $args );
|
||||
$theme_data = unserialize( $response['body'] );
|
||||
if ( is_wp_error( $theme_data ) ) {
|
||||
return $theme_data;
|
||||
}
|
||||
$this->download_links[ $theme ] = $theme_data->download_link;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function is_installed_theme( $theme ) {
|
||||
$wp_theme = wp_get_theme( $theme );
|
||||
return $wp_theme->exists();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Themes_List_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
|
||||
// GET /sites/%s/themes
|
||||
|
||||
protected $needed_capabilities = 'switch_themes';
|
||||
|
||||
public function validate_input( $theme ) {
|
||||
$this->themes = wp_get_themes( array( 'allowed' => true ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Themes_Modify_Endpoint extends Jetpack_JSON_API_Themes_Endpoint {
|
||||
// POST /sites/%s/themes/%s
|
||||
// POST /sites/%s/themes
|
||||
|
||||
protected $needed_capabilities = 'update_themes';
|
||||
protected $action = 'default_action';
|
||||
protected $expected_actions = array( 'update' );
|
||||
|
||||
public function default_action() {
|
||||
$args = $this->input();
|
||||
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) {
|
||||
if ( $args['autoupdate'] ) {
|
||||
$this->autoupdate_on();
|
||||
} else {
|
||||
$this->autoupdate_off();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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() {
|
||||
$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 update() {
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
// Clear the cache.
|
||||
wp_update_themes();
|
||||
|
||||
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);
|
||||
// Objects created inside the for loop to clean the messages for each theme
|
||||
$skin = new Automatic_Upgrader_Skin();
|
||||
$upgrader = new Theme_Upgrader( $skin );
|
||||
$upgrader->init();
|
||||
$result = $upgrader->upgrade( $theme );
|
||||
$this->log[ $theme ][] = $upgrader->skin->get_upgrade_messages();
|
||||
}
|
||||
|
||||
if ( ! $this->bulk && ! $result ) {
|
||||
return new WP_Error( 'update_fail', __( 'There was an error updating your theme', 'jetpack' ), 400 );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
class Jetpack_JSON_API_Updates_Status extends Jetpack_JSON_API_Endpoint {
|
||||
// GET /sites/%s/updates
|
||||
protected $needed_capabilities = 'manage_options';
|
||||
|
||||
protected function result() {
|
||||
|
||||
wp_update_themes();
|
||||
wp_update_plugins();
|
||||
|
||||
$update_data = wp_get_update_data();
|
||||
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;
|
||||
|
||||
if ( ! empty( $result['wordpress'] ) ) {
|
||||
$cur = get_preferred_from_update_core();
|
||||
if ( isset( $cur->response ) && $cur->response === 'upgrade' ) {
|
||||
$result['wp_update_version'] = $cur->current;
|
||||
}
|
||||
}
|
||||
|
||||
$result['jp_version'] = JETPACK__VERSION;
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
class WPCOM_JSON_API_Get_Option_Endpoint extends Jetpack_JSON_API_Endpoint {
|
||||
|
||||
protected $needed_capabilities = 'manage_options';
|
||||
|
||||
public $option_name;
|
||||
public $site_option;
|
||||
|
||||
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();
|
||||
$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' ) );
|
||||
}
|
||||
$this->site_option = isset( $query_args['site_option'] ) ? $query_args['site_option'] : false;
|
||||
/**
|
||||
* Filter the list of options that are manageable via the JSON API.
|
||||
*
|
||||
* @module json-api
|
||||
*
|
||||
* @since 3.8.2
|
||||
*
|
||||
* @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', array(), $this->site_option ) ) ) {
|
||||
return new WP_Error( 'option_name_not_in_whitelist', __( 'You must specify a whitelisted option_name', 'jetpack' ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
class WPCOM_JSON_API_Update_Option_Endpoint extends WPCOM_JSON_API_Get_Option_Endpoint {
|
||||
public $option_value;
|
||||
|
||||
function result() {
|
||||
if ( $this->site_option ) {
|
||||
update_site_option( $this->option_name, $this->option_value );
|
||||
} else {
|
||||
update_option( $this->option_name, $this->option_value );
|
||||
}
|
||||
return parent::result();
|
||||
}
|
||||
|
||||
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' ) );
|
||||
}
|
||||
if ( $query_args['is_array'] ) {
|
||||
// When converted back from JSON, the value is an object.
|
||||
// Cast it to an array for options that expect arrays.
|
||||
$this->option_value = (array) $input['option_value'];
|
||||
} else {
|
||||
$this->option_value = $input['option_value'];
|
||||
}
|
||||
|
||||
return parent::validate_input( $object );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,673 @@
|
|||
<?php
|
||||
|
||||
$json_jetpack_endpoints_dir = dirname( __FILE__ ) . '/';
|
||||
|
||||
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' );
|
||||
|
||||
new Jetpack_JSON_API_Themes_Active_Endpoint( array(
|
||||
'description' => 'Get the active theme of your blog',
|
||||
'stat' => 'themes:mine',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/themes/mine',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/mine'
|
||||
) );
|
||||
|
||||
new Jetpack_JSON_API_Themes_Active_Endpoint( array(
|
||||
'description' => 'Change the active theme of your blog',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes/mine',
|
||||
'stat' => 'themes:mine',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'query_parameters' => array(
|
||||
'context' => false
|
||||
),
|
||||
'request_format' => array(
|
||||
'theme' => '(string) The ID of the theme that should be activated'
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'theme' => 'twentytwelve'
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/mine'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-list-endpoint.php' );
|
||||
|
||||
new Jetpack_JSON_API_Themes_List_Endpoint( array(
|
||||
'description' => 'Get WordPress.com Themes allowed on your blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/themes',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'response_format' => array(
|
||||
'found' => '(int) The total number of themes found.',
|
||||
'themes' => '(array) An array of theme objects.',
|
||||
),
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-themes-get-endpoint.php' );
|
||||
new Jetpack_JSON_API_Themes_Get_Endpoint( array(
|
||||
'description' => 'Get a single theme on a jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes:get:1',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes/%s',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$theme' => '(string) The theme slug',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/twentyfourteen'
|
||||
) );
|
||||
|
||||
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',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes:modify:1',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes/%s',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$theme' => '(string) The theme slug',
|
||||
),
|
||||
'request_format' => array(
|
||||
'action' => '(string) Only possible value is \'update\'. More to follow.',
|
||||
'autoupdate' => '(bool) Whether or not to automatically update the theme.',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'action' => 'update',
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/twentyfourteen'
|
||||
) );
|
||||
|
||||
new Jetpack_JSON_API_Themes_Modify_Endpoint( array(
|
||||
'description' => 'Modify a list of themes on a jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes:modify',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
),
|
||||
'request_format' => array(
|
||||
'action' => '(string) Only possible value is \'update\'. More to follow.',
|
||||
'autoupdate' => '(bool) Whether or not to automatically update the theme.',
|
||||
'themes' => '(array) A list of theme slugs',
|
||||
),
|
||||
'response_format' => array(
|
||||
'themes' => '(array:theme) A list of theme objects',
|
||||
),
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'action' => 'autoupdate_on',
|
||||
'themes' => array(
|
||||
'twentytwelve',
|
||||
'twentyfourteen',
|
||||
),
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes'
|
||||
) );
|
||||
|
||||
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(
|
||||
'description' => 'Install a theme to your jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes:1:install',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes/%s/install',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$theme' => '(int|string) The theme slug to install',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/twentyfourteen/install'
|
||||
) );
|
||||
|
||||
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(
|
||||
'description' => 'Delete/Uninstall a theme from your jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'themes:1:delete',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/themes/%s/delete',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$theme' => '(string) The slug of the theme to delete',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Themes_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/themes/twentyfourteen/delete'
|
||||
) );
|
||||
|
||||
|
||||
// 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' );
|
||||
|
||||
new Jetpack_JSON_API_Plugins_List_Endpoint( array(
|
||||
'description' => 'Get installed Plugins on your blog',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/plugins',
|
||||
'stat' => 'plugins',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'response_format' => array(
|
||||
'plugins' => '(array) An array of plugin objects.',
|
||||
),
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins'
|
||||
) );
|
||||
|
||||
new Jetpack_JSON_API_Plugins_Get_Endpoint( array(
|
||||
'description' => 'Get the Plugin data.',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/plugins/%s/',
|
||||
'stat' => 'plugins:1',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$plugin' => '(string) The plugin ID',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-modify-endpoint.php' );
|
||||
|
||||
new Jetpack_JSON_API_Plugins_Modify_Endpoint( array(
|
||||
'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/plugins/%s',
|
||||
'stat' => 'plugins:1:modify',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$plugin' => '(string) The plugin ID',
|
||||
),
|
||||
'request_format' => array(
|
||||
'action' => '(string) Possible values are \'update\'',
|
||||
'autoupdate' => '(bool) Whether or not to automatically update the plugin',
|
||||
'active' => '(bool) Activate or deactivate the plugin',
|
||||
'network_wide' => '(bool) Do action network wide (default value: false)',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'action' => 'update',
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello'
|
||||
) );
|
||||
|
||||
new Jetpack_JSON_API_Plugins_Modify_Endpoint( array(
|
||||
'description' => 'Activate/Deactivate a list of plugins on your Jetpack Site, or set automatic updates',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/plugins',
|
||||
'stat' => 'plugins:modify',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
),
|
||||
'request_format' => array(
|
||||
'action' => '(string) Possible values are \'update\'',
|
||||
'autoupdate' => '(bool) Whether or not to automatically update the plugin',
|
||||
'active' => '(bool) Activate or deactivate the plugin',
|
||||
'network_wide' => '(bool) Do action network wide (default value: false)',
|
||||
'plugins' => '(array) A list of plugin ids to modify',
|
||||
),
|
||||
'response_format' => array(
|
||||
'plugins' => '(array:plugin) An array of plugin objects.',
|
||||
'updated' => '(array) A list of plugin ids that were updated. Only present if action is update.',
|
||||
'not_updated' => '(array) A list of plugin ids that were not updated. Only present if action is update.',
|
||||
'log' => '(array) Update log. Only present if action is update.',
|
||||
),
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'active' => true,
|
||||
'plugins' => array(
|
||||
'jetpack/jetpack',
|
||||
'akismet/akismet',
|
||||
),
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-install-endpoint.php' );
|
||||
// POST /sites/%s/plugins/%s/install
|
||||
new Jetpack_JSON_API_Plugins_Install_Endpoint( array(
|
||||
'description' => 'Install a plugin to your jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'plugins:1:install',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/plugins/%s/install',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$plugin' => '(int|string) The plugin slug to install',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet/install'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-plugins-delete-endpoint.php' );
|
||||
// POST /sites/%s/plugins/%s/delete
|
||||
new Jetpack_JSON_API_Plugins_Delete_Endpoint( array(
|
||||
'description' => 'Delete/Uninstall a plugin from your jetpack blog',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'plugins:1:delete',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/plugins/%s/delete',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$plugin' => '(int|string) The plugin slug to delete',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/akismet%2Fakismet/delete'
|
||||
) );
|
||||
|
||||
new Jetpack_JSON_API_Plugins_Modify_Endpoint( array(
|
||||
'description' => 'Update a Plugin on your Jetpack Site',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/plugins/%s/update/',
|
||||
'stat' => 'plugins:1:update',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$plugin' => '(string) The plugin ID',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello/update'
|
||||
) );
|
||||
|
||||
// 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' );
|
||||
|
||||
new Jetpack_JSON_API_Modules_Get_Endpoint( array(
|
||||
'description' => 'Get the info about a Jetpack Module on your Jetpack Site',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/jetpack/modules/%s/',
|
||||
'stat' => 'jetpack:modules:1',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$module' => '(string) The module name',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Modules_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jetpack/modules/stats'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-modify-endpoint.php' );
|
||||
|
||||
new Jetpack_JSON_API_Modules_Modify_Endpoint( array(
|
||||
'description' => 'Modify the status of a Jetpack Module on your Jetpack Site',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/jetpack/modules/%s/',
|
||||
'stat' => 'jetpack:modules:1',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain',
|
||||
'$module' => '(string) The module name',
|
||||
),
|
||||
'request_format' => array(
|
||||
'active' => '(bool) The module activation status',
|
||||
),
|
||||
'response_format' => Jetpack_JSON_API_Modules_Endpoint::$_response_format,
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
'body' => array(
|
||||
'active' => true,
|
||||
)
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jetpack/modules/stats'
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-modules-list-endpoint.php' );
|
||||
|
||||
new Jetpack_JSON_API_Modules_List_Endpoint( array(
|
||||
'description' => 'Get the list of available Jetpack modules on your site',
|
||||
'method' => 'GET',
|
||||
'path' => '/sites/%s/jetpack/modules',
|
||||
'stat' => 'jetpack:modules',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'response_format' => array(
|
||||
'found' => '(int) The total number of modules found.',
|
||||
'modules' => '(array) An array of module objects.',
|
||||
),
|
||||
'example_request_data' => array(
|
||||
'headers' => array(
|
||||
'authorization' => 'Bearer YOUR_API_TOKEN'
|
||||
),
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jetpack/modules'
|
||||
) );
|
||||
|
||||
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'
|
||||
) );
|
||||
|
||||
|
||||
// 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' );
|
||||
|
||||
new Jetpack_JSON_API_Sync_Endpoint( array(
|
||||
'description' => 'Force sync of all options and constants',
|
||||
'method' => 'POST',
|
||||
'path' => '/sites/%s/sync',
|
||||
'stat' => 'sync',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) The site ID, The site domain'
|
||||
),
|
||||
'response_format' => array(
|
||||
'scheduled' => '(bool) Whether or not the synchronisation was scheduled'
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/example.wordpress.org/sync'
|
||||
) );
|
||||
|
||||
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'
|
||||
|
||||
) );
|
||||
|
||||
// Options
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.wpcom-json-api-get-option-endpoint.php' );
|
||||
|
||||
new WPCOM_JSON_API_Get_Option_Endpoint( array (
|
||||
'method' => 'GET',
|
||||
'description' => 'Fetches an option.',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'option',
|
||||
'path' => '/sites/%s/option',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) Site ID or domain',
|
||||
),
|
||||
'query_parameters' => array(
|
||||
'option_name' => '(string) The name of the option to fetch.',
|
||||
'site_option' => '(bool=false) True if the option is a site option.',
|
||||
),
|
||||
'response_format' => array(
|
||||
'option_value' => '(string|object) The value of the option.',
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/option?option_name=blogname',
|
||||
'example_request_data' => array(
|
||||
'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
|
||||
),
|
||||
) );
|
||||
|
||||
require_once( $json_jetpack_endpoints_dir . 'class.wpcom-json-api-update-option-endpoint.php' );
|
||||
|
||||
new WPCOM_JSON_API_Update_Option_Endpoint( array (
|
||||
'method' => 'POST',
|
||||
'description' => 'Updates an option.',
|
||||
'group' => '__do_not_document',
|
||||
'stat' => 'option:update',
|
||||
'path' => '/sites/%s/option',
|
||||
'path_labels' => array(
|
||||
'$site' => '(int|string) Site ID or domain',
|
||||
),
|
||||
'query_parameters' => array(
|
||||
'option_name' => '(string) The name of the option to fetch.',
|
||||
'site_option' => '(bool=false) True if the option is a site option.',
|
||||
'is_array' => '(bool=false) True if the value should be converted to an array before saving.',
|
||||
),
|
||||
'request_format' => array(
|
||||
'option_value' => '(string|object) The new value of the option.',
|
||||
),
|
||||
'response_format' => array(
|
||||
'option_value' => '(string|object) The value of the updated option.',
|
||||
),
|
||||
'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/option',
|
||||
'example_request_data' => array(
|
||||
'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
|
||||
'body' => array(
|
||||
'option_value' => 'My new blog name'
|
||||
),
|
||||
),
|
||||
) );
|
Reference in a new issue