PHP Class Jetpack_Core_Json_Api_Endpoints, jetpack

Since: 4.1.0
ファイルを表示 Open project: automattic/jetpack Class Usage Examples

Public Properties

Property Type Description
$stats_roles Roles that can access Stats once they're granted access.
$user_permissions_error_msg Generic error message when user is not allowed to perform an action.

Public Methods

Method Description
activate_plugins_permission_check ( ) : boolean Verify that user can view Jetpack admin page and can activate plugins.
build_connect_url ( ) : string | WP_Error Gets a new connect raw URL with fresh nonce.
cast_value ( mixed $value, array $definition ) : boolean | float | integer | string Perform a casting to the value specified in the option definition.
configure_modules_permission_check ( ) : boolean Verify that user can update Jetpack modules.
confirm_safe_mode ( ) : boolean Handles identity crisis mitigation, confirming safe mode for this site.
connect_url_permission_callback ( ) : boolean | WP_Error Verify that the user can get a connect/link URL
disconnect_site ( $data ) : boolean | WP_Error Disconnects Jetpack from the WordPress.com Servers
disconnect_site_permission_callback ( ) : boolean | WP_Error Verify that the user can disconnect the site.
dismiss_notice ( $data ) : array | wp-error Handles dismissing of Jetpack Notices
get_module_requested ( string $route = '/module/(?P<slug>[a-z\-]+)' ) : array Get the currently accessed route and return the module slug in it.
get_plugin ( WP_REST_Request $data ) : boolean | WP_Error Get data about the queried plugin. Currently it only returns whether the plugin is active or not.
get_plugin_update_count ( ) : mixed | WP_Error Get number of plugin updates available.
get_plugins ( ) : WP_REST_Response | WP_Error Get plugins data in site.
get_remote_value ( string $module, string $option ) : boolean Get a value not saved locally.
get_settings ( ) : object Get miscellaneous settings for this Jetpack installation, like Holiday Snow.
get_site_data ( ) : array Get site data, including for example, the site's current plan.
get_updateable_data_list ( string | array $selector = '' ) : array Returns a list of module options or general settings that can be updated.
get_updateable_parameters ( string $selector = '' ) : array Get the query parameters to update module options or general settings.
get_user_connection_data ( ) : object Get miscellaneous user data related to the connection. Similar data available in old "My Jetpack".
get_user_connection_data_permission_callback ( ) : boolean | WP_Error Verify that a user can get the data about the current user.
holiday_snow_option_name ( ) : string Returns the proper name for Jetpack Holiday Snow setting.
identity_crisis_mitigation_permission_check ( ) : boolean Verify that user can mitigate an identity crisis.
jetpack_connection_status ( ) : boolean Get connection status for this Jetpack site.
jumpstart_activate ( WP_REST_Request $data ) : boolean | WP_Error Activates a series of valid Jetpack modules and initializes some options.
jumpstart_deactivate ( WP_REST_Request $data ) : boolean | WP_Error Dismisses Jumpstart so user is not prompted to go through it again.
jumpstart_toggle ( WP_REST_Request $data ) : boolean | WP_Error Toggles activation or deactivation of the JumpStart
manage_modules_permission_check ( ) : boolean Verify that user can manage Jetpack modules.
migrate_stats_and_subscribers ( ) : boolean Handles identity crisis mitigation, migrating stats and subscribers from old url to this, new url.
prepare_modules_for_response ( string $modules = '', null | string $slug = null ) : array Adds extra information for modules.
prepare_options_for_response ( string $module = '' ) : array Remove 'validate_callback' item from options available for module.
register_endpoints ( ) Declare the Jetpack REST API endpoints.
reset_jetpack_options ( WP_REST_Request $data ) : boolean | WP_Error Reset Jetpack options
rest_authorization_required_code ( ) : integer Contextual HTTP error code for authorization failure.
route ( $path, $classname, $method, $constructor_arguments = NULL, $endpoint_arguments = NULL )
sanitize_stats_allowed_roles ( string | boolean $value ) : boolean If for some reason the roles allowed to see Stats are empty (for example, user tampering with checkboxes), return an array with only 'administrator' as the allowed role and save it for 'roles' option.
split_options ( array $separate_options, array $grouped_options, string $prefix = '' ) : array Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.
start_fresh_connection ( ) : boolean | WP_Error This IDC resolution will disconnect the site and re-connect to a completely new and separate shadow site than the original.
unlink_user ( $data ) : boolean | WP_Error Unlinks current user from the WordPress.com Servers.
unlink_user_permission_callback ( ) : boolean | WP_Error Verify that a user can use the /connection/user endpoint. Has to be a registered user and be currently linked.
update_setting ( WP_REST_Request $data ) : object Update a single miscellaneous setting for this Jetpack installation, like Holiday Snow.
update_settings_permission_check ( ) : boolean Verify that user can update Jetpack general settings.
validate_alphanum ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter is an alphanumeric or empty string (to be able to clear the field).
validate_boolean ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter is either a pure boolean or a numeric string that can be mapped to a boolean.
validate_custom_service ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter has enough information to build a custom sharing button.
validate_custom_service_id ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter is a custom sharing service ID like 'custom-1461976264'.
validate_list_item ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter belongs to a list of admitted values.
validate_module_list ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter belongs to a list of admitted values.
validate_posint ( integer $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter is a positive integer.
validate_services ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter is among the views where the Sharing can be displayed.
validate_sharing_show ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter is among the views where the Sharing can be displayed.
validate_stats_roles ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean Validates that the parameter is among the roles allowed for Stats.
validate_string ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter is a string.
validate_twitter_username ( string $value = '', WP_REST_Request $request, string $param ) : boolean Validates that the parameter is a Twitter username or empty string (to be able to clear the field).
view_admin_page_permission_check ( ) : boolean Verify that user can view Jetpack admin page.

Private Methods

Method Description
core_get_plugins ( ) : array Returns a list of all plugins in the site.
core_is_plugin_active ( $plugin ) : boolean Checks if the queried plugin is active.

Method Details

activate_plugins_permission_check() public static method

Verify that user can view Jetpack admin page and can activate plugins.
Since: 4.3.0
public static activate_plugins_permission_check ( ) : boolean
return boolean Whether user has the capability 'jetpack_admin_page' and 'activate_plugins'.

build_connect_url() public static method

Gets a new connect raw URL with fresh nonce.
Since: 4.3.0
public static build_connect_url ( ) : string | WP_Error
return string | WP_Error A raw URL if the connection URL could be built; error message otherwise.

cast_value() public static method

Perform a casting to the value specified in the option definition.
Since: 4.3.0
public static cast_value ( mixed $value, array $definition ) : boolean | float | integer | string
$value mixed Value to cast to the proper type.
$definition array Type to cast the value to.
return boolean | float | integer | string

configure_modules_permission_check() public static method

Verify that user can update Jetpack modules.
Since: 4.3.0
public static configure_modules_permission_check ( ) : boolean
return boolean Whether user has the capability 'jetpack_configure_modules'.

confirm_safe_mode() public static method

Handles identity crisis mitigation, confirming safe mode for this site.
Since: 4.4.0
public static confirm_safe_mode ( ) : boolean
return boolean | WP_Error True if option is properly set.

connect_url_permission_callback() public static method

Verify that the user can get a connect/link URL
Since: 4.3.0
public static connect_url_permission_callback ( ) : boolean | WP_Error
return boolean | WP_Error True if user is able to disconnect the site.

disconnect_site() public static method

Disconnects Jetpack from the WordPress.com Servers
Since: 4.3.0
public static disconnect_site ( $data ) : boolean | WP_Error
return boolean | WP_Error True if Jetpack successfully disconnected.

disconnect_site_permission_callback() public static method

Verify that the user can disconnect the site.
Since: 4.3.0
public static disconnect_site_permission_callback ( ) : boolean | WP_Error
return boolean | WP_Error True if user is able to disconnect the site.

dismiss_notice() public static method

Handles dismissing of Jetpack Notices
Since: 4.3.0
public static dismiss_notice ( $data ) : array | wp-error
return array | wp-error

get_module_requested() public static method

Get the currently accessed route and return the module slug in it.
Since: 4.3.0
public static get_module_requested ( string $route = '/module/(?P<slug>[a-z\-]+)' ) : array
$route string Regular expression for the endpoint with the module slug to return.
return array

get_plugin() public static method

Get data about the queried plugin. Currently it only returns whether the plugin is active or not.
Since: 4.2.0
public static get_plugin ( WP_REST_Request $data ) : boolean | WP_Error
$data WP_REST_Request { Array of parameters received by request. @type string $slug Plugin slug with the syntax 'plugin-directory/plugin-main-file.php'. }
return boolean | WP_Error True if module was activated. Otherwise, a WP_Error instance with the corresponding error.

get_plugin_update_count() public static method

Get number of plugin updates available.
Since: 4.3.0
public static get_plugin_update_count ( ) : mixed | WP_Error
return mixed | WP_Error Number of plugin updates available. Otherwise, a WP_Error instance with the corresponding error.

get_plugins() public static method

Get plugins data in site.
Since: 4.2.0
public static get_plugins ( ) : WP_REST_Response | WP_Error
return WP_REST_Response | WP_Error List of plugins in the site. Otherwise, a WP_Error instance with the corresponding error.

get_remote_value() public static method

Get a value not saved locally.
Since: 4.3.0
public static get_remote_value ( string $module, string $option ) : boolean
$module string Module slug.
$option string Option name.
return boolean Whether user is receiving notifications or not.

get_settings() public static method

Get miscellaneous settings for this Jetpack installation, like Holiday Snow.
Since: 4.3.0
public static get_settings ( ) : object
return object $response { Array of miscellaneous settings. @type bool $holiday-snow Did Jack steal Christmas? }

get_site_data() public static method

Get site data, including for example, the site's current plan.
Since: 4.3.0
public static get_site_data ( ) : array
return array Array of Jetpack modules.

get_updateable_data_list() public static method

Returns a list of module options or general settings that can be updated.
Since: 4.3.0
Since: 4.4.0 Accepts 'any' as a parameter which will make it return the entire list.
public static get_updateable_data_list ( string | array $selector = '' ) : array
$selector string | array Module slug, 'any', or an array of parameters. If empty, it's assumed we're updating a module and we'll try to get its slug. If 'any' the full list is returned. If it's an array of parameters, includes the elements by matching keys.
return array

get_updateable_parameters() public static method

Get the query parameters to update module options or general settings.
Since: 4.3.0
Since: 4.4.0 Accepts a $selector parameter.
public static get_updateable_parameters ( string $selector = '' ) : array
$selector string Selects a set of options to update, Can be empty, a module slug or 'any'.
return array

get_user_connection_data() public static method

Information about the master/primary user. Information about the current user.
Since: 4.3.0
public static get_user_connection_data ( ) : object
return object

get_user_connection_data_permission_callback() public static method

Only those who can connect.
Since: 4.3.0
public static get_user_connection_data_permission_callback ( ) : boolean | WP_Error
return boolean | WP_Error True if user is able to unlink.

holiday_snow_option_name() public static method

When the REST route starts, the holiday-snow.php file where jetpack_holiday_snow_option_name() function is defined is not loaded, so where using this to replicate it and have the same functionality.
Since: 4.4.0
public static holiday_snow_option_name ( ) : string
return string

identity_crisis_mitigation_permission_check() public static method

Verify that user can mitigate an identity crisis.
Since: 4.4.0
public static identity_crisis_mitigation_permission_check ( ) : boolean
return boolean Whether user has capability 'jetpack_disconnect'.

jetpack_connection_status() public static method

Get connection status for this Jetpack site.
Since: 4.3.0
public static jetpack_connection_status ( ) : boolean
return boolean True if site is connected

jumpstart_activate() public static method

Activates a series of valid Jetpack modules and initializes some options.
Since: 4.3.0
public static jumpstart_activate ( WP_REST_Request $data ) : boolean | WP_Error
$data WP_REST_Request { Array of parameters received by request. }
return boolean | WP_Error True if Jumpstart succeeded. Otherwise, a WP_Error instance with the corresponding error.

jumpstart_deactivate() public static method

Dismisses Jumpstart so user is not prompted to go through it again.
Since: 4.3.0
public static jumpstart_deactivate ( WP_REST_Request $data ) : boolean | WP_Error
$data WP_REST_Request { Array of parameters received by request. }
return boolean | WP_Error True if Jumpstart was disabled or was nothing to dismiss. Otherwise, a WP_Error instance with a message.

jumpstart_toggle() public static method

Toggles activation or deactivation of the JumpStart
Since: 4.3.0
public static jumpstart_toggle ( WP_REST_Request $data ) : boolean | WP_Error
$data WP_REST_Request { Array of parameters received by request. }
return boolean | WP_Error True if toggling Jumpstart succeeded. Otherwise, a WP_Error instance with the corresponding error.

manage_modules_permission_check() public static method

Verify that user can manage Jetpack modules.
Since: 4.3.0
public static manage_modules_permission_check ( ) : boolean
return boolean Whether user has the capability 'jetpack_manage_modules'.

migrate_stats_and_subscribers() public static method

Handles identity crisis mitigation, migrating stats and subscribers from old url to this, new url.
Since: 4.4.0
public static migrate_stats_and_subscribers ( ) : boolean
return boolean | WP_Error True if option is properly set.

prepare_modules_for_response() public static method

Adds extra information for modules.
Since: 4.3.0
public static prepare_modules_for_response ( string $modules = '', null | string $slug = null ) : array
$modules string Can be a single module or a list of modules.
$slug null | string Slug of the module in the first parameter.
return array

prepare_options_for_response() public static method

Fetch current option value and add to array of module options. Prepare values of module options that need special handling, like those saved in wpcom.
Since: 4.3.0
public static prepare_options_for_response ( string $module = '' ) : array
$module string Module slug.
return array

register_endpoints() public static method

Declare the Jetpack REST API endpoints.
Since: 4.3.0
public static register_endpoints ( )

reset_jetpack_options() public static method

Reset Jetpack options
Since: 4.3.0
public static reset_jetpack_options ( WP_REST_Request $data ) : boolean | WP_Error
$data WP_REST_Request { Array of parameters received by request. @type string $options Available options to reset are options|modules }
return boolean | WP_Error True if options were reset. Otherwise, a WP_Error instance with the corresponding error.

rest_authorization_required_code() public static method

Taken from rest_authorization_required_code() in WP-API plugin until is added to core.
See also: https://github.com/WP-API/WP-API/commit/7ba0ae6fe4f605d5ffe4ee85b1cd5f9fb46900a6
Since: 4.3.0
public static rest_authorization_required_code ( ) : integer
return integer

route() public static method

public static route ( $path, $classname, $method, $constructor_arguments = NULL, $endpoint_arguments = NULL )

sanitize_stats_allowed_roles() public static method

If for some reason the roles allowed to see Stats are empty (for example, user tampering with checkboxes), return an array with only 'administrator' as the allowed role and save it for 'roles' option.
Since: 4.3.0
public static sanitize_stats_allowed_roles ( string | boolean $value ) : boolean
$value string | boolean Value to check.
return boolean

split_options() public static method

Splits module options saved as arrays like relatedposts or verification_services_codes into separate options to be returned in the response.
Since: 4.3.0
public static split_options ( array $separate_options, array $grouped_options, string $prefix = '' ) : array
$separate_options array Array of options admitted by the module.
$grouped_options array Option saved as array to be splitted.
$prefix string Optional prefix for the separate option keys.
return array

start_fresh_connection() public static method

It will first will disconnect the site without phoning home as to not disturb the production site. It then builds a fresh connection URL and sends it back along with the response.
Since: 4.4.0
public static start_fresh_connection ( ) : boolean | WP_Error
return boolean | WP_Error

update_setting() public static method

Update a single miscellaneous setting for this Jetpack installation, like Holiday Snow.
Since: 4.3.0
public static update_setting ( WP_REST_Request $data ) : object
$data WP_REST_Request
return object Jetpack miscellaneous settings.

update_settings_permission_check() public static method

Verify that user can update Jetpack general settings.
Since: 4.3.0
public static update_settings_permission_check ( ) : boolean
return boolean Whether user has the capability 'update_settings_permission_check'.

validate_alphanum() public static method

Validates that the parameter is an alphanumeric or empty string (to be able to clear the field).
Since: 4.3.0
public static validate_alphanum ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_boolean() public static method

Validates that the parameter is either a pure boolean or a numeric string that can be mapped to a boolean.
Since: 4.3.0
public static validate_boolean ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean
$value string | boolean Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_custom_service() public static method

Validates that the parameter has enough information to build a custom sharing button.
Since: 4.3.0
public static validate_custom_service ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean
$value string | boolean Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_custom_service_id() public static method

Validates that the parameter is a custom sharing service ID like 'custom-1461976264'.
Since: 4.3.0
public static validate_custom_service_id ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_list_item() public static method

Validates that the parameter belongs to a list of admitted values.
Since: 4.3.0
public static validate_list_item ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_module_list() public static method

Validates that the parameter belongs to a list of admitted values.
Since: 4.3.0
public static validate_module_list ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_posint() public static method

Validates that the parameter is a positive integer.
Since: 4.3.0
public static validate_posint ( integer $value, WP_REST_Request $request, string $param ) : boolean
$value integer Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_services() public static method

Validates that the parameter is among the views where the Sharing can be displayed.
Since: 4.3.0
public static validate_services ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean
$value string | boolean { Value to check received by request. @type array $visible List of slug of services to share to that are displayed directly in the page. @type array $hidden List of slug of services to share to that are concealed in a folding menu. }
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_sharing_show() public static method

Validates that the parameter is among the views where the Sharing can be displayed.
Since: 4.3.0
public static validate_sharing_show ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean
$value string | boolean Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_stats_roles() public static method

Validates that the parameter is among the roles allowed for Stats.
Since: 4.3.0
public static validate_stats_roles ( string | boolean $value, WP_REST_Request $request, string $param ) : boolean
$value string | boolean Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_string() public static method

Validates that the parameter is a string.
Since: 4.3.0
public static validate_string ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

validate_twitter_username() public static method

Validates that the parameter is a Twitter username or empty string (to be able to clear the field).
Since: 4.3.0
public static validate_twitter_username ( string $value = '', WP_REST_Request $request, string $param ) : boolean
$value string Value to check.
$request WP_REST_Request
$param string Name of the parameter passed to endpoint holding $value.
return boolean

view_admin_page_permission_check() public static method

Verify that user can view Jetpack admin page.
Since: 4.3.0
public static view_admin_page_permission_check ( ) : boolean
return boolean Whether user has the capability 'jetpack_admin_page'.

Property Details

$stats_roles public_oe static_oe property

Roles that can access Stats once they're granted access.
public static $stats_roles

$user_permissions_error_msg public_oe static_oe property

Generic error message when user is not allowed to perform an action.
public static $user_permissions_error_msg