PHP Class WPCOM_JSON_API_Endpoint, jetpack

Mostrar archivo Open project: automattic/jetpack Class Usage Examples

Public Properties

Property Type Description
$allow_cross_origin_request Set to true if the endpoint accepts all cross origin requests. You probably should not set this flag.
$allow_jetpack_site_auth Set to true if the endpoint should accept site based (not user based) authentication.
$allow_unauthorized_request Set to true if the endpoint can recieve unauthorized POST requests.
$allowed_if_flagged Is this endpoint still allowed if the site in question is flagged?
$allowed_if_red_flagged Is this endpoint allowed if the site is red flagged?
$api The API Object
$custom_fields_filtering Set to true if the endpoint implements its own filtering instead of the standard fields query method
$description One liner.
$example_request Example request to make
$example_request_data Example request data (for POST methods)
$example_response Example response from $example_request
$group Object Grouping For Documentation (Users, Posts, Comments)
$in_testing Is this endpoint still in testing phase? If so, not available to the public.
$links The link-generating utility class
$max_version Maximum version of the api for which to serve this endpoint
$method HTTP Method
$min_version Minimum version of the api for which to serve this endpoint
$pass_wpcom_user_details
$path Path at which to serve this endpoint: sprintf() format.
$path_labels Identifiers to fill sprintf() formatted $path
$query Accepted query parameters
$request_format Request format
$response_format Response format
$stat Stats extra value to bump
$version Version of the API

Public Methods

Method Description
__construct ( $args )
add_http_build_query_to_php_content_example ( $matches )
allow_video_uploads ( $mimes )
allows_cross_origin_requests ( )
allows_unauthorized_requests ( $origin, $complete_access_origins )
callback ( $path = '' ) Return endpoint response
cast_and_filter ( $data, $documentation, $return_default_values = false, $for_output = false )
cast_and_filter_item ( &$return, $type, $key, $value, $types = [], $for_output = false ) Casts $value according to $type.
copy_hooks ( $from_hook, $to_hook, $base_paths )
current_user_can_access_post_type ( string $post_type, string $context = 'display' ) : boolean Check whether a user can view or edit a post type
document ( $show_description = true ) Auto generates documentation based on description, method, path, path_labels, and query parameters.
format_date ( $date_gmt, $date = null ) : string Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00
format_taxonomy ( $taxonomy, $taxonomy_type, $context )
generate_doc_description ( $item ) Recursively generates the
's to document item descriptions.
generate_documentation ( ) Auto generates documentation based on description, method, path, path_labels, and query parameters.
get_author ( $author, $show_email = false ) : (object) Returns author object.
get_media_item ( $media_id )
get_media_item_v1_1 ( $media_id )
get_platform ( )
get_reflection ( $callback )
get_taxonomy ( $taxonomy_id, $taxonomy_type, $context )
handle_media_creation_v1_1 ( $media_files, $media_urls, $media_attrs = [], $force_parent_id = false )
handle_media_sideload ( $url, $parent_post_id, $type = 'any' )
input ( $return_default_values = true, $cast_and_filter = true ) Get POST body data
is_current_site_multi_user ( )
is_post_type_allowed ( $post_type )
is_publicly_documentable ( ) Checks if the endpoint is publicly displayable
load_theme_functions ( ) Load the functions.php file for the current theme to get its post formats, CPTs, etc.
parse_date ( $date_string ) : array( Parses a date string and returns the local and GMT representations of that date & time in 'YYYY-MM-DD HH:MM:SS' format without timezones or offsets. If the parsed datetime was not localized to a particular timezone or offset we will assume it was given in GMT relative to now and will convert it to local time using either the timezone set in the options table for the blog or the GMT offset.
parse_types ( $text )
query_args ( $return_default_values = true, $cast_and_filter = true ) Get all query args. Prefill with defaults
user_can_view_post ( $post_id )

Protected Methods

Method Description
_get_whitelisted_post_types ( ) : array Gets the whitelisted post types that JP should allow access to.
is_file_supported_for_sideloading ( string $file ) : boolean Checks that the mime type of the specified file is among those in a filterable list of mime types.

Method Details

__construct() public method

public __construct ( $args )

_get_whitelisted_post_types() protected method

Gets the whitelisted post types that JP should allow access to.
protected _get_whitelisted_post_types ( ) : array
return array Whitelisted post types.

add_http_build_query_to_php_content_example() public method

allow_video_uploads() public method

public allow_video_uploads ( $mimes )

allows_cross_origin_requests() public method

allows_unauthorized_requests() public method

public allows_unauthorized_requests ( $origin, $complete_access_origins )

callback() abstract public method

Return endpoint response
abstract public callback ( $path = '' )

cast_and_filter() public method

public cast_and_filter ( $data, $documentation, $return_default_values = false, $for_output = false )

cast_and_filter_item() public method

Handles fallbacks for certain values of $type when $value is not that $type Currently, only handles fallback between string <-> array (two way), from string -> false (one way), and from object -> false (one way), and string -> object (one way) Handles "child types" - array:URL, object:category array:URL means an array of URLs object:category means a hash of categories Handles object typing - object>post means an object of type post
public cast_and_filter_item ( &$return, $type, $key, $value, $types = [], $for_output = false )

copy_hooks() public method

public copy_hooks ( $from_hook, $to_hook, $base_paths )

current_user_can_access_post_type() public method

Check whether a user can view or edit a post type
public current_user_can_access_post_type ( string $post_type, string $context = 'display' ) : boolean
$post_type string post type to check
$context string 'display' or 'edit'
return boolean

document() public method

Echoes HTML.
public document ( $show_description = true )

format_date() public method

Returns ISO 8601 formatted datetime: 2011-12-08T01:15:36-08:00
public format_date ( $date_gmt, $date = null ) : string
$date_gmt (string) GMT datetime string.
$date (string) Optional. Used to calculate the offset from GMT.
return string

format_taxonomy() public method

public format_taxonomy ( $taxonomy, $taxonomy_type, $context )

generate_doc_description() public method

Echoes HTML.
public generate_doc_description ( $item )

generate_documentation() public method

Echoes HTML.

get_author() public method

Returns author object.
public get_author ( $author, $show_email = false ) : (object)
$author user ID, user row, WP_User object, comment row, post row
$show_email output the author's email address?
return (object)

get_media_item() public method

public get_media_item ( $media_id )

get_media_item_v1_1() public method

public get_media_item_v1_1 ( $media_id )

get_platform() public method

public get_platform ( )

get_reflection() public method

public get_reflection ( $callback )

get_taxonomy() public method

public get_taxonomy ( $taxonomy_id, $taxonomy_type, $context )

handle_media_creation_v1_1() public method

public handle_media_creation_v1_1 ( $media_files, $media_urls, $media_attrs = [], $force_parent_id = false )

handle_media_sideload() public method

public handle_media_sideload ( $url, $parent_post_id, $type = 'any' )

input() public method

Get POST body data
public input ( $return_default_values = true, $cast_and_filter = true )

is_current_site_multi_user() public method

is_file_supported_for_sideloading() protected method

Checks that the mime type of the specified file is among those in a filterable list of mime types.
protected is_file_supported_for_sideloading ( string $file ) : boolean
$file string Path to file to get its mime type.
return boolean

is_post_type_allowed() public method

public is_post_type_allowed ( $post_type )

is_publicly_documentable() public method

Checks if the endpoint is publicly displayable

load_theme_functions() public method

Load the functions.php file for the current theme to get its post formats, CPTs, etc.

parse_date() public method

Parses a date string and returns the local and GMT representations of that date & time in 'YYYY-MM-DD HH:MM:SS' format without timezones or offsets. If the parsed datetime was not localized to a particular timezone or offset we will assume it was given in GMT relative to now and will convert it to local time using either the timezone set in the options table for the blog or the GMT offset.
public parse_date ( $date_string ) : array(
return array(

parse_types() public method

public parse_types ( $text )

query_args() public method

Get all query args. Prefill with defaults
public query_args ( $return_default_values = true, $cast_and_filter = true )

user_can_view_post() public method

public user_can_view_post ( $post_id )

Property Details

$allow_cross_origin_request public_oe property

Set to true if the endpoint accepts all cross origin requests. You probably should not set this flag.
public $allow_cross_origin_request

$allow_jetpack_site_auth public_oe property

Set to true if the endpoint should accept site based (not user based) authentication.
public $allow_jetpack_site_auth

$allow_unauthorized_request public_oe property

Set to true if the endpoint can recieve unauthorized POST requests.
public $allow_unauthorized_request

$allowed_if_flagged public_oe property

Is this endpoint still allowed if the site in question is flagged?
public $allowed_if_flagged

$allowed_if_red_flagged public_oe property

Is this endpoint allowed if the site is red flagged?
public $allowed_if_red_flagged

$api public_oe property

The API Object
public $api

$custom_fields_filtering public_oe property

Set to true if the endpoint implements its own filtering instead of the standard fields query method
public $custom_fields_filtering

$description public_oe property

One liner.
public $description

$example_request public_oe property

Example request to make
public $example_request

$example_request_data public_oe property

Example request data (for POST methods)
public $example_request_data

$example_response public_oe property

Example response from $example_request
public $example_response

$group public_oe property

Object Grouping For Documentation (Users, Posts, Comments)
public $group

$in_testing public_oe property

Is this endpoint still in testing phase? If so, not available to the public.
public $in_testing

$max_version public_oe property

Maximum version of the api for which to serve this endpoint
public $max_version

$method public_oe property

HTTP Method
public $method

$min_version public_oe property

Minimum version of the api for which to serve this endpoint
public $min_version

$pass_wpcom_user_details public_oe property

public $pass_wpcom_user_details

$path public_oe property

Path at which to serve this endpoint: sprintf() format.
public $path

$path_labels public_oe property

Identifiers to fill sprintf() formatted $path
public $path_labels

$query public_oe property

Accepted query parameters
public $query

$request_format public_oe property

Request format
public $request_format

$response_format public_oe property

Response format
public $response_format

$stat public_oe property

Stats extra value to bump
public $stat

$version public_oe property

Version of the API
public $version