equal
deleted
inserted
replaced
101 /** |
101 /** |
102 * Checks if a given request has access to read blocks. |
102 * Checks if a given request has access to read blocks. |
103 * |
103 * |
104 * @since 5.0.0 |
104 * @since 5.0.0 |
105 * |
105 * |
|
106 * @global WP_Post $post Global post object. |
|
107 * |
106 * @param WP_REST_Request $request Request. |
108 * @param WP_REST_Request $request Request. |
107 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
109 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
108 */ |
110 */ |
109 public function get_item_permissions_check( $request ) { |
111 public function get_item_permissions_check( $request ) { |
110 global $post; |
112 global $post; |
111 |
113 |
112 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
114 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
113 |
115 |
114 if ( 0 < $post_id ) { |
116 if ( $post_id > 0 ) { |
115 $post = get_post( $post_id ); |
117 $post = get_post( $post_id ); |
116 |
118 |
117 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
119 if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { |
118 return new WP_Error( |
120 return new WP_Error( |
119 'block_cannot_read', |
121 'block_cannot_read', |
141 /** |
143 /** |
142 * Returns block output from block's registered render_callback. |
144 * Returns block output from block's registered render_callback. |
143 * |
145 * |
144 * @since 5.0.0 |
146 * @since 5.0.0 |
145 * |
147 * |
|
148 * @global WP_Post $post Global post object. |
|
149 * |
146 * @param WP_REST_Request $request Full details about the request. |
150 * @param WP_REST_Request $request Full details about the request. |
147 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
151 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
148 */ |
152 */ |
149 public function get_item( $request ) { |
153 public function get_item( $request ) { |
150 global $post; |
154 global $post; |
151 |
155 |
152 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
156 $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0; |
153 |
157 |
154 if ( 0 < $post_id ) { |
158 if ( $post_id > 0 ) { |
155 $post = get_post( $post_id ); |
159 $post = get_post( $post_id ); |
156 |
160 |
157 // Set up postdata since this will be needed if post_id was set. |
161 // Set up postdata since this will be needed if post_id was set. |
158 setup_postdata( $post ); |
162 setup_postdata( $post ); |
159 } |
163 } |