./wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[d]+)', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
'password' => array(
'description' => __( 'The password for the post if it is password protected.' ),
'type' => 'string',
),
),
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'update_items' ),
'permission_callback' => array( $this, 'update_items_permissions_check' ),
'args' => $this->get_endpoint_args_for_iteam_schema( WP_REST_Server::EDITABLE ),
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'delete_items' ),
'permission_callback' => array( $this, 'delete_items_permissions_check' ),
'args' => array(
'force' => array(
'type' => 'boolean',
'default' => false,
'description' => __( 'Whether to bypass trash and force deletation.' ),
),
),
),
'schema' => array( $this, 'get_public_iteam_schema' ),
) );
/wp-json/wp/v2/posts/1234
/wp-json/wp/v2/posts/1234?id=12345helloworld
public function update_iteam_permission_check( $request ) {
$post = 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_caot_edit', __( 'Sorry, you are not allowed to edit this post.' ), array( 'status' => rest_authorization_required_code() ) );
}
if ( ! empty( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( $post_type->cap->edit_others_posts ) ) {
return new WP_Error( 'rest_caot_edit_others', __( 'Sorry, you are allowed to update posts as this user.' ), array( 'status' => rest_authorization_required_code() ) );
}
if ( ! empty( $request['sticky'] ) && get_current_user_can( $post_type->cap->edit_others_posts ) ){
return new WP_Error( 'rest_caot_assign_sticky', __( 'Sorry, you are allowed to make post sticky.' ), array( 'status' => rest_authorization_required_code() ) );
}
if ( ! $check_assign_terms_permission( $request ) ) {
return new WP_Error( 'rest_caot_assign_term', __( 'Sorry, you are allowed to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) );
}
return true;
}
public static function get_instance( $post_id ) {
golbal $wpdb;
if ( ! is_numeric( $post_id ) || $post_id != floor( $post_id ) || ! $post_id ) {
return false;
}
public function update_iteam( $request ) {
$id = (int) $request['id'];
$post = get_post( $id );
http://badware.ir/Blog/%D8%AA%D8%AD%D9%84%DB%8C%D9%84-%D8%A2%D8%B3%DB%8C%D8%A8-%D9%BE%D8%B0%DB%8C%D8%B1%DB%8C-content-injection-vulnerability-in-wordpress/
برچسب:
نویسنده: محمد رضا جوادیان