@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * Handler for updating custom field data. |
154 | 154 | * @since 2.2.0 |
155 | - * @param mixed $value The value of the field |
|
155 | + * @param mixed $values The value of the field |
|
156 | 156 | * @param object $object The object from the response |
157 | 157 | * @param string $field_id Name of field |
158 | 158 | * @return bool|int |
@@ -233,6 +233,9 @@ discard block |
||
233 | 233 | return $protected; |
234 | 234 | } |
235 | 235 | |
236 | + /** |
|
237 | + * @param string $field_id |
|
238 | + */ |
|
236 | 239 | public function field_can_update( $field_id ) { |
237 | 240 | |
238 | 241 | $field = $this->cmb->get_field( $field_id ); |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | |
121 | 121 | protected function declare_read_write_fields() { |
122 | 122 | foreach ( $this->cmb->prop( 'fields' ) as $field ) { |
123 | - $show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null; |
|
123 | + $show_in_rest = isset( $field[ 'show_in_rest' ] ) ? $field[ 'show_in_rest' ] : null; |
|
124 | 124 | |
125 | 125 | if ( false === $show_in_rest ) { |
126 | 126 | continue; |
127 | 127 | } |
128 | 128 | |
129 | 129 | if ( $this->can_read( $show_in_rest ) ) { |
130 | - $this->read_fields[] = $field['id']; |
|
130 | + $this->read_fields[ ] = $field[ 'id' ]; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | if ( $this->can_write( $show_in_rest ) ) { |
134 | - $this->write_fields[] = $field['id']; |
|
134 | + $this->write_fields[ ] = $field[ 'id' ]; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | } |
@@ -159,14 +159,14 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function get_restable_field_values( $object, $field_id, $request ) { |
161 | 161 | $values = array(); |
162 | - if ( ! isset( $object['id'] ) ) { |
|
162 | + if ( ! isset( $object[ 'id' ] ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | 166 | foreach ( self::$boxes as $cmb_id => $rest_box ) { |
167 | 167 | foreach ( $rest_box->read_fields as $field_id ) { |
168 | 168 | $field = $rest_box->cmb->get_field( $field_id ); |
169 | - $field->object_id = $object['id']; |
|
169 | + $field->object_id = $object[ 'id' ]; |
|
170 | 170 | |
171 | 171 | // TODO: test other object types (users, comments, etc) |
172 | 172 | if ( isset( $object->type ) ) { |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | |
208 | - $rest_box->cmb->object_id( $data['object_id'] ); |
|
209 | - $rest_box->cmb->object_type( $data['object_type'] ); |
|
208 | + $rest_box->cmb->object_id( $data[ 'object_id' ] ); |
|
209 | + $rest_box->cmb->object_type( $data[ 'object_type' ] ); |
|
210 | 210 | |
211 | 211 | // TODO: Test since refactor. |
212 | 212 | $updated[ $cmb_id ] = $rest_box->sanitize_box_values( $values ); |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | } elseif ( isset( $object->comment_ID ) ) { |
305 | 305 | $object_id = intval( $object->comment_ID ); |
306 | 306 | $object_type = 'comment'; |
307 | - } elseif ( is_array( $object ) && isset( $object['term_id'] ) ) { |
|
308 | - $object_id = intval( $object['term_id'] ); |
|
307 | + } elseif ( is_array( $object ) && isset( $object[ 'term_id' ] ) ) { |
|
308 | + $object_id = intval( $object[ 'term_id' ] ); |
|
309 | 309 | $object_type = 'term'; |
310 | 310 | } elseif ( isset( $object->term_id ) ) { |
311 | 311 | $object_id = intval( $object->term_id ); |
@@ -94,7 +94,6 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @since 2.2.0 |
96 | 96 | * |
97 | - * @param mixed $data |
|
98 | 97 | * @return array $data |
99 | 98 | */ |
100 | 99 | public function prepare_item( $post ) { |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | * @since 2.2.0 |
108 | 107 | * |
109 | 108 | * @param mixed $cb Callable function/method. |
110 | - * @return mixed Results of output buffer after calling function/method. |
|
109 | + * @return string Results of output buffer after calling function/method. |
|
111 | 110 | */ |
112 | 111 | public function get_cb_results( $cb ) { |
113 | 112 | $args = func_get_args(); |
@@ -142,6 +141,9 @@ discard block |
||
142 | 141 | return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this ); |
143 | 142 | } |
144 | 143 | |
144 | + /** |
|
145 | + * @param string $request_type |
|
146 | + */ |
|
145 | 147 | protected function initiate_rest_read_box( $request, $request_type ) { |
146 | 148 | $this->initiate_rest_box( $request, $request_type ); |
147 | 149 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array $data |
129 | 129 | */ |
130 | 130 | public function prepare_item_for_response( $data, $request = null ) { |
131 | - $data = $this->filter_response_by_context( $data, $this->request['context'] ); |
|
131 | + $data = $this->filter_response_by_context( $data, $this->request[ 'context' ] ); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Filter the prepared CMB2 item response. |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | |
171 | 171 | public function initiate_request( $request, $request_type ) { |
172 | 172 | $this->request = $request; |
173 | - $this->request['context'] = isset( $this->request['context'] ) && ! empty( $this->request['context'] ) |
|
174 | - ? $this->request['context'] |
|
173 | + $this->request[ 'context' ] = isset( $this->request[ 'context' ] ) && ! empty( $this->request[ 'context' ] ) |
|
174 | + ? $this->request[ 'context' ] |
|
175 | 175 | : 'view'; |
176 | 176 | |
177 | - if ( isset( $_REQUEST['object_id'] ) ) { |
|
178 | - $this->object_id = absint( $_REQUEST['object_id'] ); |
|
177 | + if ( isset( $_REQUEST[ 'object_id' ] ) ) { |
|
178 | + $this->object_id = absint( $_REQUEST[ 'object_id' ] ); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( isset( $_REQUEST['object_type'] ) ) { |
|
182 | - $this->object_type = absint( $_REQUEST['object_type'] ); |
|
181 | + if ( isset( $_REQUEST[ 'object_type' ] ) ) { |
|
182 | + $this->object_type = absint( $_REQUEST[ 'object_type' ] ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | self::$request_type = self::$request_type ? self::$request_type : $request_type; |
@@ -100,7 +100,6 @@ |
||
100 | 100 | * |
101 | 101 | * @since 2.2.0 |
102 | 102 | * |
103 | - * @param CMB2 $cmb |
|
104 | 103 | * @return array |
105 | 104 | */ |
106 | 105 | public function get_rest_box() { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | foreach ( CMB2_REST::$boxes as $this->rest_box ) { |
71 | 71 | if ( $this->rest_box->rest_read ) { |
72 | 72 | $rest_box = $this->get_rest_box(); |
73 | - $boxes_data[ $this->rest_box->cmb->cmb_id ] = $this->server->response_to_data( $rest_box, isset( $_GET['_embed'] ) ); |
|
73 | + $boxes_data[ $this->rest_box->cmb->cmb_id ] = $this->server->response_to_data( $rest_box, isset( $_GET[ '_embed' ] ) ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | |
111 | 111 | $boxes_data = $cmb->meta_box; |
112 | 112 | |
113 | - if ( isset( $_REQUEST['_rendered'] ) && '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
|
114 | - $boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
115 | - $boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
113 | + if ( isset( $_REQUEST[ '_rendered' ] ) && '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
|
114 | + $boxes_data[ 'form_open' ] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
115 | + $boxes_data[ 'form_close' ] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
116 | 116 | |
117 | 117 | global $wp_scripts, $wp_styles; |
118 | 118 | $before_css = $wp_styles->queue; |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | |
121 | 121 | CMB2_JS::enqueue(); |
122 | 122 | |
123 | - $boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
124 | - $boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
123 | + $boxes_data[ 'js_dependencies' ] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
124 | + $boxes_data[ 'css_dependencies' ] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // TODO: look into 'embed' parameter. |
128 | 128 | // http://demo.wp-api.org/wp-json/wp/v2/posts?_embed |
129 | - unset( $boxes_data['fields'] ); |
|
129 | + unset( $boxes_data[ 'fields' ] ); |
|
130 | 130 | // Handle callable properties. |
131 | - unset( $boxes_data['show_on_cb'] ); |
|
131 | + unset( $boxes_data[ 'show_on_cb' ] ); |
|
132 | 132 | |
133 | 133 | $response = rest_ensure_response( $boxes_data ); |
134 | 134 |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | |
68 | 68 | $fields = array(); |
69 | 69 | foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) { |
70 | - $field_id = $field['id']; |
|
70 | + $field_id = $field[ 'id' ]; |
|
71 | 71 | $rest_field = $this->get_rest_field( $field_id ); |
72 | 72 | |
73 | 73 | if ( ! is_wp_error( $rest_field ) ) { |
74 | - $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $_GET['_embed'] ) ); |
|
74 | + $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $_GET[ '_embed' ] ) ); |
|
75 | 75 | } else { |
76 | 76 | $fields[ $field_id ] = array( 'error' => $rest_field->get_error_message() ); |
77 | 77 | } |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if ( isset( $_REQUEST['_rendered'] ) ) { |
|
169 | - $field_data['rendered'] = $rendered; |
|
168 | + if ( isset( $_REQUEST[ '_rendered' ] ) ) { |
|
169 | + $field_data[ 'rendered' ] = $rendered; |
|
170 | 170 | } |
171 | 171 | |
172 | - $field_data['value'] = $field->get_data(); |
|
172 | + $field_data[ 'value' ] = $field->get_data(); |
|
173 | 173 | |
174 | 174 | return $field_data; |
175 | 175 | } |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | ); |
191 | 191 | |
192 | 192 | // TODO ? |
193 | - error_log( '$this->request[context]: '. print_r( $this->request['context'], true ) ); |
|
194 | - error_log( 'CMB2_REST_Controller::get_intial_route(): '. print_r( CMB2_REST_Controller::get_intial_route(), true ) ); |
|
195 | - error_log( '$match: '. print_r( 'box_read' === CMB2_REST_Controller::get_intial_request_type(), true ) ); |
|
193 | + error_log( '$this->request[context]: ' . print_r( $this->request[ 'context' ], true ) ); |
|
194 | + error_log( 'CMB2_REST_Controller::get_intial_route(): ' . print_r( CMB2_REST_Controller::get_intial_route(), true ) ); |
|
195 | + error_log( '$match: ' . print_r( 'box_read' === CMB2_REST_Controller::get_intial_request_type(), true ) ); |
|
196 | 196 | |
197 | 197 | |
198 | 198 | // Don't embed boxes when looking at boxes route. |
199 | 199 | if ( '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
200 | - $links['up']['embeddable'] = true; |
|
200 | + $links[ 'up' ][ 'embeddable' ] = true; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $links; |