| @@ -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,26 @@ | ||
| 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() ); | |
| 269 | + global $wpdb; | |
| 271 | 270 | |
| 271 | + $params = $request->get_params(); | |
| 272 | + $meta_inputs = isset( $params['meta_input'] ) ? $params['meta_input'] : []; | |
| 273 | + unset( $params['meta_input'] ); | |
| 274 | + $id = wp_insert_post( $params ); | |
| 275 | + | |
| 276 | + if ( isset( $meta_inputs ) && is_array( $meta_inputs ) && ! empty( $meta_inputs ) ) { | |
| 277 | + | |
| 278 | + foreach ( $meta_inputs as $meta_key => $meta_value ) { | |
| 279 | + $meta_key = sanitize_key( $meta_key ); | |
| 280 | + if ( null !== $meta_value ) { | |
| 281 | + $meta_value = addslashes( $meta_value ); | |
| 282 | + } | |
| 283 | + $wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) values ({$id}, '{$meta_key}', '{$meta_value}')" ); | |
| 284 | + } | |
| 285 | + } | |
| 286 | + | |
| 272 | 287 | if ( ! $id || is_wp_error( $id ) ) { |
| 273 | 288 | return [ |
| 274 | 289 | 'error' => true, |
| 275 | 290 | ]; |
| @@ -297,9 +312,9 @@ | ||
| 297 | 312 | 'post_parent' => $post->post_parent, |
| 298 | 313 | 'post_password' => $post->post_password, |
| 299 | 314 | 'post_status' => 'draft', |
| 300 | 315 | /* translators: %s: post/page title */ |
| 301 | - 'post_title' => sprintf( _x( '%s - Copy', '%s stands for post/page title.', 'fl-assistant' ), $post->post_title ), | |
| 316 | + 'post_title' => sprintf( _x( '%s - Copy', '%s stands for post/page title.', 'assistant' ), $post->post_title ), | |
| 302 | 317 | 'post_type' => $post->post_type, |
| 303 | 318 | 'to_ping' => $post->to_ping, |
| 304 | 319 | 'menu_order' => $post->menu_order, |
| 305 | 320 | ]; |
| @@ -422,9 +437,11 @@ | ||
| 422 | 437 | /** |
| 423 | 438 | * Deletes a single post based on the specified ID. |
| 424 | 439 | */ |
| 425 | 440 | public function delete_post( $request ) { |
| 426 | - $id = $request->get_param( 'id' ); | |
| 441 | + $params = $request->get_params(); | |
| 442 | + $id = $params['id']; | |
| 443 | + $force = isset( $params['force'] ) && $params['force']; | |
| 427 | 444 | |
| 428 | 445 | if ( ! current_user_can( 'edit_post', $id ) ) { |
| 429 | 446 | return rest_ensure_response( |
| 430 | 447 | [ |
| @@ -432,9 +449,9 @@ | ||
| 432 | 449 | ] |
| 433 | 450 | ); |
| 434 | 451 | } |
| 435 | 452 | |
| 436 | - wp_delete_post( $id ); | |
| 453 | + wp_delete_post( $id, $force ); | |
| 437 | 454 | |
| 438 | 455 | return rest_ensure_response( |
| 439 | 456 | [ |
| 440 | 457 | 'success' => true, |