| @@ -255,9 +255,8 @@ | ||
| 255 | 255 | $id = $request->get_param( 'id' ); |
| 256 | 256 | |
| 257 | 257 | if ( current_user_can( 'edit_post', $id ) ) { |
| 258 | 258 | $post = get_post( $id ); |
| 259 | - | |
| 260 | 259 | return $this->transform( $post ); |
| 261 | 260 | } |
| 262 | 261 | |
| 263 | 262 | return []; |
| @@ -266,10 +265,18 @@ | ||
| 266 | 265 | /** |
| 267 | 266 | * Creates a single post. |
| 268 | 267 | */ |
| 269 | 268 | public function create_post( $request ) { |
| 270 | - $id = wp_insert_post( $request->get_params() ); | |
| 271 | 269 | |
| 270 | + $params = $request->get_params(); | |
| 271 | + if ( isset( $params['meta_input'] ) && is_array( $params['meta_input'] ) ) { | |
| 272 | + foreach ( $params['meta_input'] as $meta_key => $meta_value ) { | |
| 273 | + $params['meta_input'][ $meta_key ] = maybe_unserialize( $meta_value ); | |
| 274 | + } | |
| 275 | + } | |
| 276 | + | |
| 277 | + $id = wp_insert_post( $params ); | |
| 278 | + | |
| 272 | 279 | if ( ! $id || is_wp_error( $id ) ) { |
| 273 | 280 | return [ |
| 274 | 281 | 'error' => true, |
| 275 | 282 | ]; |
| @@ -297,9 +304,9 @@ | ||
| 297 | 304 | 'post_parent' => $post->post_parent, |
| 298 | 305 | 'post_password' => $post->post_password, |
| 299 | 306 | 'post_status' => 'draft', |
| 300 | 307 | /* translators: %s: post/page title */ |
| 301 | - 'post_title' => sprintf( _x( '%s - Copy', '%s stands for post/page title.', 'fl-assistant' ), $post->post_title ), | |
| 308 | + 'post_title' => sprintf( _x( '%s - Copy', '%s stands for post/page title.', 'assistant' ), $post->post_title ), | |
| 302 | 309 | 'post_type' => $post->post_type, |
| 303 | 310 | 'to_ping' => $post->to_ping, |
| 304 | 311 | 'menu_order' => $post->menu_order, |
| 305 | 312 | ]; |
| @@ -422,9 +429,11 @@ | ||
| 422 | 429 | /** |
| 423 | 430 | * Deletes a single post based on the specified ID. |
| 424 | 431 | */ |
| 425 | 432 | public function delete_post( $request ) { |
| 426 | - $id = $request->get_param( 'id' ); | |
| 433 | + $params = $request->get_params(); | |
| 434 | + $id = $params['id']; | |
| 435 | + $force = isset( $params['force'] ) && $params['force']; | |
| 427 | 436 | |
| 428 | 437 | if ( ! current_user_can( 'edit_post', $id ) ) { |
| 429 | 438 | return rest_ensure_response( |
| 430 | 439 | [ |
| @@ -432,9 +441,9 @@ | ||
| 432 | 441 | ] |
| 433 | 442 | ); |
| 434 | 443 | } |
| 435 | 444 | |
| 436 | - wp_delete_post( $id ); | |
| 445 | + wp_delete_post( $id, $force ); | |
| 437 | 446 | |
| 438 | 447 | return rest_ensure_response( |
| 439 | 448 | [ |
| 440 | 449 | 'success' => true, |