equal
deleted
inserted
replaced
49 'callback' => array( $this, 'get_item' ), |
49 'callback' => array( $this, 'get_item' ), |
50 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
50 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
51 'args' => array( |
51 'args' => array( |
52 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
52 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
53 'attributes' => array( |
53 'attributes' => array( |
54 'description' => __( 'Attributes for the block' ), |
54 'description' => __( 'Attributes for the block.' ), |
55 'type' => 'object', |
55 'type' => 'object', |
56 'default' => array(), |
56 'default' => array(), |
57 'validate_callback' => static function ( $value, $request ) { |
57 'validate_callback' => static function ( $value, $request ) { |
58 $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); |
58 $block = WP_Block_Type_Registry::get_instance()->get_registered( $request['name'] ); |
59 |
59 |
107 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
107 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
108 */ |
108 */ |
109 public function get_item_permissions_check( $request ) { |
109 public function get_item_permissions_check( $request ) { |
110 global $post; |
110 global $post; |
111 |
111 |
112 $post_id = isset( $request['post_id'] ) ? intval( $request['post_id'] ) : 0; |
112 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
113 |
113 |
114 if ( 0 < $post_id ) { |
114 if ( 0 < $post_id ) { |
115 $post = get_post( $post_id ); |
115 $post = get_post( $post_id ); |
116 |
116 |
117 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
117 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
147 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
147 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
148 */ |
148 */ |
149 public function get_item( $request ) { |
149 public function get_item( $request ) { |
150 global $post; |
150 global $post; |
151 |
151 |
152 $post_id = isset( $request['post_id'] ) ? intval( $request['post_id'] ) : 0; |
152 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
153 |
153 |
154 if ( 0 < $post_id ) { |
154 if ( 0 < $post_id ) { |
155 $post = get_post( $post_id ); |
155 $post = get_post( $post_id ); |
156 |
156 |
157 // Set up postdata since this will be needed if post_id was set. |
157 // Set up postdata since this will be needed if post_id was set. |