idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
36,000
public function get_items_permissions_check ( $ request ) { $ parent = $ this -> get_post ( $ request [ 'parent' ] ) ; if ( ! $ parent ) { return true ; } $ parent_post_type_obj = get_post_type_object ( $ parent -> post_type ) ; if ( ! current_user_can ( $ parent_post_type_obj -> cap -> edit_post , $ parent -> ID ) ) {...
Check if a given request has access to get revisions
36,001
public function get_items ( $ request ) { $ parent = $ this -> get_post ( $ request [ 'parent' ] ) ; if ( ! $ request [ 'parent' ] || ! $ parent || $ this -> parent_post_type !== $ parent -> post_type ) { return new WP_Error ( 'rest_post_invalid_parent' , __ ( 'Invalid post parent id.' ) , array ( 'status' => 404 ) ) ;...
Get a collection of revisions
36,002
public function get_item ( $ request ) { $ parent = $ this -> get_post ( $ request [ 'parent' ] ) ; if ( ! $ request [ 'parent' ] || ! $ parent || $ this -> parent_post_type !== $ parent -> post_type ) { return new WP_Error ( 'rest_post_invalid_parent' , __ ( 'Invalid post parent id.' ) , array ( 'status' => 404 ) ) ; ...
Get one revision from the collection
36,003
public function delete_item_permissions_check ( $ request ) { $ response = $ this -> get_items_permissions_check ( $ request ) ; if ( ! $ response || is_wp_error ( $ response ) ) { return $ response ; } $ post = $ this -> get_post ( $ request [ 'id' ] ) ; if ( ! $ post ) { return new WP_Error ( 'rest_post_invalid_id' ,...
Check if a given request has access to delete a revision
36,004
public function delete_item ( $ request ) { $ result = wp_delete_post ( $ request [ 'id' ] , true ) ; do_action ( 'rest_delete_revision' , $ result , $ request ) ; if ( $ result ) { return true ; } else { return new WP_Error ( 'rest_cannot_delete' , __ ( 'The post cannot be deleted.' ) , array ( 'status' => 500 ) ) ; }...
Delete a single revision
36,005
protected function prepare_excerpt_response ( $ excerpt , $ post ) { $ excerpt = apply_filters ( 'the_excerpt' , $ excerpt , $ post ) ; if ( empty ( $ excerpt ) ) { return '' ; } return $ excerpt ; }
Check the post excerpt and prepare it for single post output .
36,006
public function create_item_permissions_check ( $ request ) { $ ret = parent :: create_item_permissions_check ( $ request ) ; if ( ! $ ret || is_wp_error ( $ ret ) ) { return $ ret ; } if ( ! current_user_can ( 'upload_files' ) ) { return new WP_Error ( 'rest_cannot_create' , __ ( 'Sorry, you are not allowed to upload ...
Check if a given request has access to create an attachment .
36,007
protected function prepare_item_for_database ( $ request ) { $ prepared_attachment = parent :: prepare_item_for_database ( $ request ) ; if ( isset ( $ request [ 'caption' ] ) ) { $ prepared_attachment -> post_excerpt = $ request [ 'caption' ] ; } if ( isset ( $ request [ 'description' ] ) ) { $ prepared_attachment -> ...
Prepare a single attachment for create or update .
36,008
public function prepare_item_for_response ( $ post , $ request ) { $ response = parent :: prepare_item_for_response ( $ post , $ request ) ; $ data = $ response -> get_data ( ) ; $ data [ 'alt_text' ] = get_post_meta ( $ post -> ID , '_wp_attachment_image_alt' , true ) ; $ data [ 'caption' ] = $ post -> post_excerpt ; ...
Prepare a single attachment output for response .
36,009
public function get_item_schema ( ) { $ schema = parent :: get_item_schema ( ) ; $ schema [ 'properties' ] [ 'alt_text' ] = array ( 'description' => __ ( 'Alternative text to display when resource is not displayed.' ) , 'type' => 'string' , 'context' => array ( 'view' , 'edit' , 'embed' ) , 'arg_options' => array ( 'sa...
Get the Attachment s schema conforming to JSON Schema .
36,010
protected function upload_from_data ( $ data , $ headers ) { if ( empty ( $ data ) ) { return new WP_Error ( 'rest_upload_no_data' , __ ( 'No data supplied.' ) , array ( 'status' => 400 ) ) ; } if ( empty ( $ headers [ 'content_type' ] ) ) { return new WP_Error ( 'rest_upload_no_content_type' , __ ( 'No Content-Type su...
Handle an upload via raw POST data .
36,011
public static function get_filename_from_disposition ( $ disposition_header ) { $ filename = null ; foreach ( $ disposition_header as $ value ) { $ value = trim ( $ value ) ; if ( strpos ( $ value , ';' ) === false ) { continue ; } list ( $ type , $ attr_parts ) = explode ( ';' , $ value , 2 ) ; $ attr_parts = explode ...
Parse filename from a Content - Disposition header value .
36,012
public function validate_user_can_query_private_statuses ( $ value , $ request , $ parameter ) { if ( 'inherit' === $ value ) { return true ; } return parent :: validate_user_can_query_private_statuses ( $ value , $ request , $ parameter ) ; }
Validate whether the user can query private statuses
36,013
protected function get_media_types ( ) { $ media_types = array ( ) ; foreach ( get_allowed_mime_types ( ) as $ mime_type ) { $ parts = explode ( '/' , $ mime_type ) ; if ( ! isset ( $ media_types [ $ parts [ 0 ] ] ) ) { $ media_types [ $ parts [ 0 ] ] = array ( ) ; } $ media_types [ $ parts [ 0 ] ] [ ] = $ mime_type ; ...
Get the supported media types .
36,014
public function get_items_permissions_check ( $ request ) { if ( 'edit' === $ request [ 'context' ] ) { $ types = get_post_types ( array ( 'show_in_rest' => true ) , 'objects' ) ; foreach ( $ types as $ type ) { if ( current_user_can ( $ type -> cap -> edit_posts ) ) { return true ; } } return new WP_Error ( 'rest_cann...
Check whether a given request has permission to read post statuses .
36,015
public function get_items ( $ request ) { $ data = array ( ) ; $ statuses = get_post_stati ( array ( 'internal' => false ) , 'object' ) ; $ statuses [ 'trash' ] = get_post_status_object ( 'trash' ) ; foreach ( $ statuses as $ slug => $ obj ) { $ ret = $ this -> check_read_permission ( $ obj ) ; if ( ! $ ret ) { continu...
Get all post statuses depending on user context
36,016
public function get_item_permissions_check ( $ request ) { $ status = get_post_status_object ( $ request [ 'status' ] ) ; if ( empty ( $ status ) ) { return new WP_Error ( 'rest_status_invalid' , __ ( 'Invalid resource.' ) , array ( 'status' => 404 ) ) ; } $ check = $ this -> check_read_permission ( $ status ) ; if ( !...
Check if a given request has access to read a post status .
36,017
protected function check_read_permission ( $ status ) { if ( true === $ status -> public ) { return true ; } if ( false === $ status -> internal || 'trash' === $ status -> name ) { $ types = get_post_types ( array ( 'show_in_rest' => true ) , 'objects' ) ; foreach ( $ types as $ type ) { if ( current_user_can ( $ type ...
Check whether a given post status should be visible
36,018
public function get_item ( $ request ) { $ obj = get_post_status_object ( $ request [ 'status' ] ) ; if ( empty ( $ obj ) ) { return new WP_Error ( 'rest_status_invalid' , __ ( 'Invalid resource.' ) , array ( 'status' => 404 ) ) ; } $ data = $ this -> prepare_item_for_response ( $ obj , $ request ) ; return rest_ensure...
Get a specific post status
36,019
public function prepare_item_for_response ( $ status , $ request ) { $ data = array ( 'name' => $ status -> label , 'private' => ( bool ) $ status -> private , 'protected' => ( bool ) $ status -> protected , 'public' => ( bool ) $ status -> public , 'queryable' => ( bool ) $ status -> publicly_queryable , 'show_in_list...
Prepare a post status object for serialization
36,020
public function prepare_response_for_collection ( $ response ) { if ( ! ( $ response instanceof WP_REST_Response ) ) { return $ response ; } $ data = ( array ) $ response -> get_data ( ) ; $ server = rest_get_server ( ) ; if ( method_exists ( $ server , 'get_compact_response_links' ) ) { $ links = call_user_func ( arra...
Prepare a response for inserting into a collection .
36,021
public function filter_response_by_context ( $ data , $ context ) { $ schema = $ this -> get_item_schema ( ) ; foreach ( $ data as $ key => $ value ) { if ( empty ( $ schema [ 'properties' ] [ $ key ] ) || empty ( $ schema [ 'properties' ] [ $ key ] [ 'context' ] ) ) { continue ; } if ( ! in_array ( $ context , $ schem...
Filter a response based on the context defined in the schema .
36,022
public function get_context_param ( $ args = array ( ) ) { $ param_details = array ( 'description' => __ ( 'Scope under which the request is made; determines fields present in response.' ) , 'type' => 'string' , 'sanitize_callback' => 'sanitize_key' , 'validate_callback' => 'rest_validate_request_arg' , ) ; $ schema = ...
Get the magical context param .
36,023
protected function add_additional_fields_to_object ( $ object , $ request ) { $ additional_fields = $ this -> get_additional_fields ( ) ; foreach ( $ additional_fields as $ field_name => $ field_options ) { if ( ! $ field_options [ 'get_callback' ] ) { continue ; } $ object [ $ field_name ] = call_user_func ( $ field_o...
Add the values from additional fields to a data object .
36,024
protected function update_additional_fields_for_object ( $ object , $ request ) { $ additional_fields = $ this -> get_additional_fields ( ) ; foreach ( $ additional_fields as $ field_name => $ field_options ) { if ( ! $ field_options [ 'update_callback' ] ) { continue ; } if ( ! isset ( $ request [ $ field_name ] ) ) {...
Update the values of additional fields added to a data object .
36,025
protected function add_additional_fields_schema ( $ schema ) { if ( empty ( $ schema [ 'title' ] ) ) { return $ schema ; } $ object_type = $ schema [ 'title' ] ; $ additional_fields = $ this -> get_additional_fields ( $ object_type ) ; foreach ( $ additional_fields as $ field_name => $ field_options ) { if ( ! $ field_...
Add the schema from additional fields to an schema array .
36,026
protected function get_additional_fields ( $ object_type = null ) { if ( ! $ object_type ) { $ object_type = $ this -> get_object_type ( ) ; } if ( ! $ object_type ) { return array ( ) ; } global $ wp_rest_additional_fields ; if ( ! $ wp_rest_additional_fields || ! isset ( $ wp_rest_additional_fields [ $ object_type ] ...
Get all the registered additional fields for a given object - type .
36,027
public function get_endpoint_args_for_item_schema ( $ method = WP_REST_Server :: CREATABLE ) { $ schema = $ this -> get_item_schema ( ) ; $ schema_properties = ! empty ( $ schema [ 'properties' ] ) ? $ schema [ 'properties' ] : array ( ) ; $ endpoint_args = array ( ) ; foreach ( $ schema_properties as $ field_id => $ p...
Get an array of endpoint arguments from the item schema for the controller .
36,028
public function get_post ( $ post ) { $ post_obj = get_post ( $ post ) ; $ post = apply_filters ( 'rest_the_post' , $ post_obj , $ post ) ; return $ post ; }
Retrieves post data given a post ID or post object .
36,029
public function get_items_permissions_check ( $ request ) { if ( ! empty ( $ request [ 'roles' ] ) && ! current_user_can ( 'list_users' ) ) { return new WP_Error ( 'rest_user_cannot_view' , __ ( 'Sorry, you cannot filter by role.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } if ( 'edit' === $ re...
Permissions check for getting all users .
36,030
public function get_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ user = get_userdata ( $ id ) ; $ types = get_post_types ( array ( 'show_in_rest' => true ) , 'names' ) ; if ( empty ( $ id ) || empty ( $ user -> ID ) ) { return new WP_Error ( 'rest_user_invalid_id' , __ ( 'Invalid resourc...
Check if a given request has access to read a user
36,031
public function update_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; if ( ! current_user_can ( 'edit_user' , $ id ) ) { return new WP_Error ( 'rest_cannot_edit' , __ ( 'Sorry, you are not allowed to edit resource.' ) , array ( 'status' => rest_authorization_required_code ( ) ) ) ; } if ( ! ...
Check if a given request has access update a user
36,032
public function update_item ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ user = get_userdata ( $ id ) ; if ( ! $ user ) { return new WP_Error ( 'rest_user_invalid_id' , __ ( 'Invalid resource id.' ) , array ( 'status' => 404 ) ) ; } if ( email_exists ( $ request [ 'email' ] ) && $ request [ 'email' ] !== $ use...
Update a single user
36,033
public function delete_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; if ( ! current_user_can ( 'delete_user' , $ id ) ) { return new WP_Error ( 'rest_user_cannot_delete' , __ ( 'Sorry, you are not allowed to delete this resource.' ) , array ( 'status' => rest_authorization_required_code ( )...
Check if a given request has access delete a user
36,034
public function delete_item ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ reassign = isset ( $ request [ 'reassign' ] ) ? absint ( $ request [ 'reassign' ] ) : null ; $ force = isset ( $ request [ 'force' ] ) ? ( bool ) $ request [ 'force' ] : false ; if ( ! $ force ) { return new WP_Error ( 'rest_trash_not_sup...
Delete a single user
36,035
protected function prepare_item_for_database ( $ request ) { $ prepared_user = new stdClass ; $ schema = $ this -> get_item_schema ( ) ; if ( isset ( $ request [ 'email' ] ) && ! empty ( $ schema [ 'properties' ] [ 'email' ] ) ) { $ prepared_user -> user_email = $ request [ 'email' ] ; } if ( isset ( $ request [ 'usern...
Prepare a single user for create or update
36,036
protected function check_role_update ( $ user_id , $ roles ) { global $ wp_roles ; foreach ( $ roles as $ role ) { if ( ! isset ( $ wp_roles -> role_objects [ $ role ] ) ) { return new WP_Error ( 'rest_user_invalid_role' , sprintf ( __ ( 'The role %s does not exist.' ) , $ role ) , array ( 'status' => 400 ) ) ; } $ pot...
Determine if the current user is allowed to make the desired roles change .
36,037
public function get_value ( $ object_id , $ request ) { $ fields = $ this -> get_registered_fields ( ) ; $ response = array ( ) ; foreach ( $ fields as $ name => $ args ) { $ all_values = get_metadata ( $ this -> get_meta_type ( ) , $ object_id , $ name , false ) ; if ( $ args [ 'single' ] ) { if ( empty ( $ all_values...
Get the meta field value .
36,038
protected function prepare_value_for_response ( $ value , $ request , $ args ) { if ( ! empty ( $ args [ 'prepare_callback' ] ) ) { $ value = call_user_func ( $ args [ 'prepare_callback' ] , $ value , $ request , $ args ) ; } return $ value ; }
Prepare value for response .
36,039
public function update_value ( $ request , $ object_id ) { $ fields = $ this -> get_registered_fields ( ) ; foreach ( $ fields as $ name => $ args ) { if ( ! array_key_exists ( $ name , $ request ) ) { continue ; } if ( is_null ( $ request [ $ name ] ) ) { $ result = $ this -> delete_meta_value ( $ object_id , $ name )...
Update meta values .
36,040
protected function delete_meta_value ( $ object_id , $ name ) { if ( ! current_user_can ( 'delete_post_meta' , $ object_id , $ name ) ) { return new WP_Error ( 'rest_cannot_delete' , sprintf ( __ ( 'You do not have permission to edit the %s custom field.' ) , $ name ) , array ( 'key' => $ name , 'status' => rest_author...
Delete meta value for an object .
36,041
protected function update_multi_meta_value ( $ object_id , $ name , $ values ) { if ( ! current_user_can ( 'edit_post_meta' , $ object_id , $ name ) ) { return new WP_Error ( 'rest_cannot_update' , sprintf ( __ ( 'You do not have permission to edit the %s custom field.' ) , $ name ) , array ( 'key' => $ name , 'status'...
Update multiple meta values for an object .
36,042
protected function update_meta_value ( $ object_id , $ name , $ value ) { if ( ! current_user_can ( 'edit_post_meta' , $ object_id , $ name ) ) { return new WP_Error ( 'rest_cannot_update' , sprintf ( __ ( 'You do not have permission to edit the %s custom field.' ) , $ name ) , array ( 'key' => $ name , 'status' => res...
Update meta value for an object .
36,043
protected function get_registered_fields ( ) { $ registered = array ( ) ; foreach ( get_registered_meta_keys ( $ this -> get_meta_type ( ) ) as $ name => $ args ) { if ( empty ( $ args [ 'show_in_rest' ] ) ) { continue ; } $ rest_args = array ( ) ; if ( is_array ( $ args [ 'show_in_rest' ] ) ) { $ rest_args = $ args [ ...
Get all the registered meta fields .
36,044
public function get_field_schema ( ) { $ fields = $ this -> get_registered_fields ( ) ; $ schema = array ( 'description' => __ ( 'Meta fields.' ) , 'type' => 'object' , 'context' => array ( 'view' , 'edit' ) , 'properties' => array ( ) , ) ; foreach ( $ fields as $ key => $ args ) { $ schema [ 'properties' ] [ $ key ] ...
Get the object s meta schema conforming to JSON Schema .
36,045
public static function prepare_value ( $ value , $ request , $ args ) { $ type = $ args [ 'schema' ] [ 'type' ] ; if ( 'array' === $ type && ! empty ( $ args [ 'schema' ] [ 'items' ] [ 'type' ] ) ) { $ type = $ args [ 'schema' ] [ 'items' ] [ 'type' ] ; } switch ( $ type ) { case 'string' : $ value = ( string ) $ value...
Prepare a meta value for output .
36,046
public function get_items_permissions_check ( $ request ) { if ( 'edit' === $ request [ 'context' ] ) { if ( ! empty ( $ request [ 'type' ] ) ) { $ taxonomies = get_object_taxonomies ( $ request [ 'type' ] , 'objects' ) ; } else { $ taxonomies = get_taxonomies ( '' , 'objects' ) ; } foreach ( $ taxonomies as $ taxonomy...
Check whether a given request has permission to read taxonomies .
36,047
public function get_items ( $ request ) { $ registered = $ this -> get_collection_params ( ) ; if ( isset ( $ registered [ 'type' ] ) && ! empty ( $ request [ 'type' ] ) ) { $ taxonomies = get_object_taxonomies ( $ request [ 'type' ] , 'objects' ) ; } else { $ taxonomies = get_taxonomies ( '' , 'objects' ) ; } $ data =...
Get all public taxonomies
36,048
public function get_item_permissions_check ( $ request ) { $ tax_obj = get_taxonomy ( $ request [ 'taxonomy' ] ) ; if ( $ tax_obj ) { if ( empty ( $ tax_obj -> show_in_rest ) ) { return false ; } if ( 'edit' === $ request [ 'context' ] && ! current_user_can ( $ tax_obj -> cap -> manage_terms ) ) { return new WP_Error (...
Check if a given request has access a taxonomy
36,049
public function get_item ( $ request ) { $ tax_obj = get_taxonomy ( $ request [ 'taxonomy' ] ) ; if ( empty ( $ tax_obj ) ) { return new WP_Error ( 'rest_taxonomy_invalid' , __ ( 'Invalid resource.' ) , array ( 'status' => 404 ) ) ; } $ data = $ this -> prepare_item_for_response ( $ tax_obj , $ request ) ; return rest_...
Get a specific taxonomy
36,050
public function prepare_item_for_response ( $ taxonomy , $ request ) { $ data = array ( 'name' => $ taxonomy -> label , 'slug' => $ taxonomy -> name , 'capabilities' => $ taxonomy -> cap , 'description' => $ taxonomy -> description , 'labels' => $ taxonomy -> labels , 'types' => $ taxonomy -> object_type , 'show_cloud'...
Prepare a taxonomy object for serialization
36,051
public function get_item ( $ request ) { $ options = $ this -> get_registered_options ( ) ; $ response = array ( ) ; foreach ( $ options as $ name => $ args ) { $ response [ $ name ] = apply_filters ( 'rest_pre_get_setting' , null , $ name , $ args ) ; if ( is_null ( $ response [ $ name ] ) ) { $ response [ $ name ] = ...
Get the settings .
36,052
protected function prepare_value ( $ value , $ schema ) { switch ( $ schema [ 'type' ] ) { case 'string' : return ( string ) $ value ; case 'number' : return ( float ) $ value ; case 'boolean' : return ( bool ) $ value ; default : return null ; } }
Prepare a value for output based off a schema array .
36,053
public function update_item ( $ request ) { $ options = $ this -> get_registered_options ( ) ; $ params = $ request -> get_params ( ) ; foreach ( $ options as $ name => $ args ) { if ( ! array_key_exists ( $ name , $ params ) ) { continue ; } $ updated = apply_filters ( 'rest_pre_update_setting' , false , $ name , $ re...
Update settings for the settings object .
36,054
protected function get_registered_options ( ) { $ rest_options = array ( ) ; foreach ( get_registered_settings ( ) as $ name => $ args ) { if ( empty ( $ args [ 'show_in_rest' ] ) ) { continue ; } $ rest_args = array ( ) ; if ( is_array ( $ args [ 'show_in_rest' ] ) ) { $ rest_args = $ args [ 'show_in_rest' ] ; } $ def...
Get all the registered options for the Settings API
36,055
public function get_item_schema ( ) { $ options = $ this -> get_registered_options ( ) ; $ schema = array ( '$schema' => 'http://json-schema.org/draft-04/schema#' , 'title' => 'settings' , 'type' => 'object' , 'properties' => array ( ) , ) ; foreach ( $ options as $ option_name => $ option ) { $ schema [ 'properties' ]...
Get the site setting schema conforming to JSON Schema .
36,056
public function get_items_permissions_check ( $ request ) { if ( ! empty ( $ request [ 'post' ] ) ) { foreach ( ( array ) $ request [ 'post' ] as $ post_id ) { $ post = $ this -> get_post ( $ post_id ) ; if ( ! empty ( $ post_id ) && $ post && ! $ this -> check_read_post_permission ( $ post ) ) { return new WP_Error ( ...
Check if a given request has access to read comments
36,057
public function get_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ comment = get_comment ( $ id ) ; if ( ! $ comment ) { return true ; } if ( ! $ this -> check_read_permission ( $ comment ) ) { return new WP_Error ( 'rest_cannot_read' , __ ( 'Sorry, you cannot read this comment.' ) , array...
Check if a given request has access to read the comment
36,058
public function create_item_permissions_check ( $ request ) { if ( ! is_user_logged_in ( ) && get_option ( 'comment_registration' ) ) { return new WP_Error ( 'rest_comment_login_required' , __ ( 'Sorry, you must be logged in to comment.' ) , array ( 'status' => 401 ) ) ; } if ( isset ( $ request [ 'author' ] ) && get_c...
Check if a given request has access to create a comment
36,059
public function update_item_permissions_check ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ comment = get_comment ( $ id ) ; if ( $ comment && ! $ this -> check_edit_permission ( $ comment ) ) { return new WP_Error ( 'rest_cannot_edit' , __ ( 'Sorry, you can not edit this comment.' ) , array ( 'status' => rest_...
Check if a given request has access to update a comment
36,060
public function prepare_item_for_response ( $ comment , $ request ) { $ data = array ( 'id' => ( int ) $ comment -> comment_ID , 'post' => ( int ) $ comment -> comment_post_ID , 'parent' => ( int ) $ comment -> comment_parent , 'author' => ( int ) $ comment -> user_id , 'author_name' => $ comment -> comment_author , 'a...
Prepare a single comment output for response .
36,061
protected function normalize_query_param ( $ query_param ) { $ prefix = 'comment_' ; switch ( $ query_param ) { case 'id' : $ normalized = $ prefix . 'ID' ; break ; case 'post' : $ normalized = $ prefix . 'post_ID' ; break ; case 'parent' : $ normalized = $ prefix . 'parent' ; break ; case 'include' : $ normalized = 'c...
Prepend internal property prefix to query parameters to match our response fields .
36,062
protected function handle_status_param ( $ new_status , $ comment ) { $ old_status = wp_get_comment_status ( $ comment -> comment_ID ) ; if ( $ new_status === $ old_status ) { return false ; } switch ( $ new_status ) { case 'approved' : case 'approve' : case '1' : $ changed = wp_set_comment_status ( $ comment -> commen...
Set the comment_status of a given comment object when creating or updating a comment .
36,063
protected function check_read_permission ( $ comment ) { if ( ! empty ( $ comment -> comment_post_ID ) ) { $ post = get_post ( $ comment -> comment_post_ID ) ; if ( $ post ) { if ( $ this -> check_read_post_permission ( $ post ) && 1 === ( int ) $ comment -> comment_approved ) { return true ; } } } if ( 0 === get_curre...
Check if we can read a comment .
36,064
protected function check_edit_permission ( $ comment ) { if ( 0 === ( int ) get_current_user_id ( ) ) { return false ; } if ( ! current_user_can ( 'moderate_comments' ) ) { return false ; } return current_user_can ( 'edit_comment' , $ comment -> comment_ID ) ; }
Check if we can edit or delete a comment .
36,065
protected function get_terms_for_post ( $ prepared_args ) { $ query_result = get_the_terms ( $ prepared_args [ 'post' ] , $ this -> taxonomy ) ; if ( empty ( $ query_result ) ) { $ this -> total_terms = 0 ; return array ( ) ; } if ( ! in_array ( $ prepared_args [ 'orderby' ] , array ( 'name' , 'none' , 'include' ) , tr...
Gets the terms attached to a post .
36,066
protected function compare_terms ( $ left , $ right ) { $ col = $ this -> sort_column ; $ left_val = $ left -> $ col ; $ right_val = $ right -> $ col ; if ( is_int ( $ left_val ) && is_int ( $ right_val ) ) { return $ left_val - $ right_val ; } return strcmp ( $ left_val , $ right_val ) ; }
Comparison function for sorting terms by a column .
36,067
public function get_item_permissions_check ( $ request ) { $ tax_obj = get_taxonomy ( $ this -> taxonomy ) ; if ( ! $ tax_obj || ! $ this -> check_is_taxonomy_allowed ( $ this -> taxonomy ) ) { return false ; } if ( 'edit' === $ request [ 'context' ] && ! current_user_can ( $ tax_obj -> cap -> edit_terms ) ) { return n...
Checks if a request has access to read the specified term .
36,068
public function get_item ( $ request ) { $ term = get_term ( ( int ) $ request [ 'id' ] , $ this -> taxonomy ) ; if ( ! $ term || $ term -> taxonomy !== $ this -> taxonomy ) { return new WP_Error ( 'rest_term_invalid' , __ ( "Resource doesn't exist." ) , array ( 'status' => 404 ) ) ; } if ( is_wp_error ( $ term ) ) { r...
Gets a single term from a taxonomy .
36,069
public function create_item_permissions_check ( $ request ) { if ( ! $ this -> check_is_taxonomy_allowed ( $ this -> taxonomy ) ) { return false ; } $ taxonomy_obj = get_taxonomy ( $ this -> taxonomy ) ; if ( ! current_user_can ( $ taxonomy_obj -> cap -> manage_terms ) ) { return new WP_Error ( 'rest_cannot_create' , _...
Checks if a request has access to create a term .
36,070
public function create_item ( $ request ) { if ( isset ( $ request [ 'parent' ] ) ) { if ( ! is_taxonomy_hierarchical ( $ this -> taxonomy ) ) { return new WP_Error ( 'rest_taxonomy_not_hierarchical' , __ ( 'Can not set resource parent, taxonomy is not hierarchical.' ) , array ( 'status' => 400 ) ) ; } $ parent = get_t...
Creates a single term in a taxonomy .
36,071
public function update_item_permissions_check ( $ request ) { if ( ! $ this -> check_is_taxonomy_allowed ( $ this -> taxonomy ) ) { return false ; } $ term = get_term ( ( int ) $ request [ 'id' ] , $ this -> taxonomy ) ; if ( ! $ term ) { return new WP_Error ( 'rest_term_invalid' , __ ( "Resource doesn't exist." ) , ar...
Checks if a request has access to update the specified term .
36,072
public function update_item ( $ request ) { if ( isset ( $ request [ 'parent' ] ) ) { if ( ! is_taxonomy_hierarchical ( $ this -> taxonomy ) ) { return new WP_Error ( 'rest_taxonomy_not_hierarchical' , __ ( 'Can not set resource parent, taxonomy is not hierarchical.' ) , array ( 'status' => 400 ) ) ; } $ parent = get_t...
Updates a single term from a taxonomy .
36,073
public function delete_item ( $ request ) { $ force = isset ( $ request [ 'force' ] ) ? ( bool ) $ request [ 'force' ] : false ; if ( ! $ force ) { return new WP_Error ( 'rest_trash_not_supported' , __ ( 'Resource does not support trashing.' ) , array ( 'status' => 501 ) ) ; } $ term = get_term ( ( int ) $ request [ 'i...
Deletes a single term from a taxonomy .
36,074
public function prepare_item_for_database ( $ request ) { $ prepared_term = new stdClass ; $ schema = $ this -> get_item_schema ( ) ; if ( isset ( $ request [ 'name' ] ) && ! empty ( $ schema [ 'properties' ] [ 'name' ] ) ) { $ prepared_term -> name = $ request [ 'name' ] ; } if ( isset ( $ request [ 'slug' ] ) && ! em...
Prepares a single term for create or update .
36,075
public function prepare_item_for_response ( $ item , $ request ) { $ schema = $ this -> get_item_schema ( ) ; $ data = array ( ) ; if ( ! empty ( $ schema [ 'properties' ] [ 'id' ] ) ) { $ data [ 'id' ] = ( int ) $ item -> term_id ; } if ( ! empty ( $ schema [ 'properties' ] [ 'count' ] ) ) { $ data [ 'count' ] = ( int...
Prepares a single term output for response .
36,076
protected function prepare_links ( $ term ) { $ base = $ this -> namespace . '/' . $ this -> rest_base ; $ links = array ( 'self' => array ( 'href' => rest_url ( trailingslashit ( $ base ) . $ term -> term_id ) , ) , 'collection' => array ( 'href' => rest_url ( $ base ) , ) , 'about' => array ( 'href' => rest_url ( spr...
Prepares links for the request .
36,077
public function get_item_schema ( ) { $ schema = array ( '$schema' => 'http://json-schema.org/draft-04/schema#' , 'title' => 'post_tag' === $ this -> taxonomy ? 'tag' : $ this -> taxonomy , 'type' => 'object' , 'properties' => array ( 'id' => array ( 'description' => __ ( 'Unique identifier for the resource.' ) , 'type...
Gets the term s schema conforming to JSON Schema .
36,078
public function get_collection_params ( ) { $ query_params = parent :: get_collection_params ( ) ; $ taxonomy = get_taxonomy ( $ this -> taxonomy ) ; $ query_params [ 'context' ] [ 'default' ] = 'view' ; $ query_params [ 'exclude' ] = array ( 'description' => __ ( 'Ensure result set excludes specific ids.' ) , 'type' =...
Gets the query params for collections .
36,079
protected function check_is_taxonomy_allowed ( $ taxonomy ) { $ taxonomy_obj = get_taxonomy ( $ taxonomy ) ; if ( $ taxonomy_obj && ! empty ( $ taxonomy_obj -> show_in_rest ) ) { return true ; } return false ; }
Checks that the taxonomy is valid .
36,080
public function get_item_permissions_check ( $ request ) { $ post = $ this -> get_post ( ( int ) $ request [ 'id' ] ) ; if ( 'edit' === $ request [ 'context' ] && $ post && ! $ this -> check_update_permission ( $ post ) ) { return new WP_Error ( 'rest_forbidden_context' , __ ( 'Sorry, you are not allowed to edit this p...
Check if a given request has access to read a post .
36,081
protected function can_access_password_content ( $ post , $ request ) { if ( empty ( $ post -> post_password ) ) { return false ; } if ( 'edit' === $ request [ 'context' ] ) { return true ; } if ( empty ( $ request [ 'password' ] ) ) { return false ; } return hash_equals ( $ post -> post_password , $ request [ 'passwor...
Can the user access password - protected content?
36,082
public function get_item ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ post = $ this -> get_post ( $ id ) ; if ( empty ( $ id ) || empty ( $ post -> ID ) || $ this -> post_type !== $ post -> post_type ) { return new WP_Error ( 'rest_post_invalid_id' , __ ( 'Invalid post id.' ) , array ( 'status' => 404 ) ) ; } ...
Get a single post .
36,083
public function create_item_permissions_check ( $ request ) { $ post_type = get_post_type_object ( $ this -> post_type ) ; if ( ! empty ( $ request [ 'author' ] ) && get_current_user_id ( ) !== $ request [ 'author' ] && ! current_user_can ( $ post_type -> cap -> edit_others_posts ) ) { return new WP_Error ( 'rest_canno...
Check if a given request has access to create a post .
36,084
public function update_item_permissions_check ( $ request ) { $ post = $ this -> get_post ( $ request [ 'id' ] ) ; $ post_type = get_post_type_object ( $ this -> post_type ) ; if ( $ post && ! $ this -> check_update_permission ( $ post ) ) { return new WP_Error ( 'rest_cannot_edit' , __ ( 'Sorry, you are not allowed to...
Check if a given request has access to update a post .
36,085
public function delete_item_permissions_check ( $ request ) { $ post = $ this -> get_post ( $ request [ 'id' ] ) ; if ( $ post && ! $ this -> check_delete_permission ( $ post ) ) { return new WP_Error ( 'rest_cannot_delete' , __ ( 'Sorry, you are not allowed to delete posts.' ) , array ( 'status' => rest_authorization_...
Check if a given request has access to delete a post .
36,086
public function delete_item ( $ request ) { $ id = ( int ) $ request [ 'id' ] ; $ force = ( bool ) $ request [ 'force' ] ; $ post = $ this -> get_post ( $ id ) ; if ( empty ( $ id ) || empty ( $ post -> ID ) || $ this -> post_type !== $ post -> post_type ) { return new WP_Error ( 'rest_post_invalid_id' , __ ( 'Invalid ...
Delete a single post .
36,087
protected function get_allowed_query_vars ( $ request = null ) { global $ wp ; $ valid_vars = apply_filters ( 'query_vars' , $ wp -> public_query_vars ) ; $ post_type_obj = get_post_type_object ( $ this -> post_type ) ; if ( current_user_can ( $ post_type_obj -> cap -> edit_posts ) ) { $ private = apply_filters ( 'rest...
Get all the WP Query vars that are allowed for the API request .
36,088
protected function prepare_date_response ( $ date_gmt , $ date = null ) { if ( isset ( $ date ) ) { return mysql_to_rfc3339 ( $ date ) ; } if ( '0000-00-00 00:00:00' === $ date_gmt ) { return null ; } return mysql_to_rfc3339 ( $ date_gmt ) ; }
Check the post_date_gmt or modified_gmt and prepare any post or modified date for single post output .
36,089
protected function handle_status_param ( $ post_status , $ post_type ) { switch ( $ post_status ) { case 'draft' : case 'pending' : break ; case 'private' : if ( ! current_user_can ( $ post_type -> cap -> publish_posts ) ) { return new WP_Error ( 'rest_cannot_publish' , __ ( 'Sorry, you are not allowed to create privat...
Determine validity and normalize provided status param .
36,090
protected function handle_featured_media ( $ featured_media , $ post_id ) { $ featured_media = ( int ) $ featured_media ; if ( $ featured_media ) { $ result = set_post_thumbnail ( $ post_id , $ featured_media ) ; if ( $ result ) { return true ; } else { return new WP_Error ( 'rest_invalid_featured_media' , __ ( 'Invali...
Determine the featured media based on a request param .
36,091
public function handle_template ( $ template , $ post_id ) { if ( in_array ( $ template , array_keys ( wp_get_theme ( ) -> get_page_templates ( $ this -> get_post ( $ post_id ) ) ) , true ) ) { update_post_meta ( $ post_id , '_wp_page_template' , $ template ) ; } else { update_post_meta ( $ post_id , '_wp_page_template...
Set the template for a page .
36,092
protected function handle_terms ( $ post_id , $ request ) { $ taxonomies = wp_list_filter ( get_object_taxonomies ( $ this -> post_type , 'objects' ) , array ( 'show_in_rest' => true ) ) ; foreach ( $ taxonomies as $ taxonomy ) { $ base = ! empty ( $ taxonomy -> rest_base ) ? $ taxonomy -> rest_base : $ taxonomy -> nam...
Update the post s terms from a REST request .
36,093
protected function check_is_post_type_allowed ( $ post_type ) { if ( ! is_object ( $ post_type ) ) { $ post_type = get_post_type_object ( $ post_type ) ; } if ( ! empty ( $ post_type ) && ! empty ( $ post_type -> show_in_rest ) ) { return true ; } return false ; }
Check if a given post type should be viewed or managed .
36,094
public function check_read_permission ( $ post ) { $ post_type = get_post_type_object ( $ post -> post_type ) ; if ( ! $ this -> check_is_post_type_allowed ( $ post_type ) ) { return false ; } if ( 'publish' === $ post -> post_status || current_user_can ( $ post_type -> cap -> read_post , $ post -> ID ) ) { return true...
Check if we can read a post .
36,095
protected function check_update_permission ( $ post ) { $ post_type = get_post_type_object ( $ post -> post_type ) ; if ( ! $ this -> check_is_post_type_allowed ( $ post_type ) ) { return false ; } return current_user_can ( $ post_type -> cap -> edit_post , $ post -> ID ) ; }
Check if we can edit a post .
36,096
protected function check_create_permission ( $ post ) { $ post_type = get_post_type_object ( $ post -> post_type ) ; if ( ! $ this -> check_is_post_type_allowed ( $ post_type ) ) { return false ; } return current_user_can ( $ post_type -> cap -> create_posts ) ; }
Check if we can create a post .
36,097
protected function check_delete_permission ( $ post ) { $ post_type = get_post_type_object ( $ post -> post_type ) ; if ( ! $ this -> check_is_post_type_allowed ( $ post_type ) ) { return false ; } return current_user_can ( $ post_type -> cap -> delete_post , $ post -> ID ) ; }
Check if we can delete a post .
36,098
public function validate_user_can_query_private_statuses ( $ value , $ request , $ parameter ) { if ( 'publish' === $ value ) { return true ; } $ post_type_obj = get_post_type_object ( $ this -> post_type ) ; if ( current_user_can ( $ post_type_obj -> cap -> edit_posts ) ) { return true ; } return new WP_Error ( 'rest_...
Validate whether the user can query private statuses .
36,099
public function get_items_permissions_check ( $ request ) { if ( 'edit' === $ request [ 'context' ] ) { foreach ( get_post_types ( array ( ) , 'object' ) as $ post_type ) { if ( ! empty ( $ post_type -> show_in_rest ) && current_user_can ( $ post_type -> cap -> edit_posts ) ) { return true ; } } return new WP_Error ( '...
Check whether a given request has permission to read types .