← All changes
|
jetpack_vendor/automattic/jetpack-import/src/endpoints/class-post.php
+14
-6
12.9.5
→
16.3-beta
View file →
| @@ -7,9 +7,16 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Import\Endpoints; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Sync\Settings; |
| 11 | +use WP_Error; | |
| 12 | +use WP_REST_Request; | |
| 13 | +use WP_REST_Response; | |
| 11 | 14 | |
| 15 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 16 | + exit( 0 ); | |
| 17 | +} | |
| 18 | + | |
| 12 | 19 | if ( ! function_exists( 'post_exists' ) ) { |
| 13 | 20 | require_once ABSPATH . 'wp-admin/includes/post.php'; |
| 14 | 21 | } |
| 15 | 22 | |
| @@ -70,8 +77,11 @@ | ||
| 70 | 77 | * @param WP_REST_Request $request Full details about the request. |
| 71 | 78 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
| 72 | 79 | */ |
| 73 | 80 | public function create_item( $request ) { |
| 81 | + // Set the WP_IMPORTING constant to prevent sync notifications | |
| 82 | + $this->set_importing(); | |
| 83 | + | |
| 74 | 84 | // Skip if the post already exists. |
| 75 | 85 | $post_id = \post_exists( |
| 76 | 86 | $request['title'], |
| 77 | 87 | '', |
| @@ -80,9 +90,9 @@ | ||
| 80 | 90 | $request['status'] |
| 81 | 91 | ); |
| 82 | 92 | |
| 83 | 93 | if ( $post_id ) { |
| 84 | - return new \WP_Error( | |
| 94 | + return new WP_Error( | |
| 85 | 95 | 'post_exists', |
| 86 | 96 | __( 'Cannot create existing post.', 'jetpack-import' ), |
| 87 | 97 | array( |
| 88 | 98 | 'status' => 409, |
| @@ -220,18 +230,16 @@ | ||
| 220 | 230 | * @param array $metas An array of metas to filter. |
| 221 | 231 | * @return array The filtered array of meta keys. |
| 222 | 232 | */ |
| 223 | 233 | private function filter_post_meta_keys( $metas ) { |
| 224 | - // Define an array of keys to exclude from the filtered array | |
| 225 | - $excluded_keys = array(); | |
| 226 | 234 | // Convert array of keys to a plain array of key strings |
| 227 | - $meta_keys = array_unique( array_values( array_keys( $metas ) ) ); | |
| 235 | + $meta_keys = array_unique( array_keys( $metas ) ); | |
| 228 | 236 | // // Filter the array by removing the excluded keys and any keys that include '_oembed' |
| 229 | 237 | $filtered_keys = array_filter( |
| 230 | 238 | $meta_keys, |
| 231 | - function ( $key ) use ( $excluded_keys ) { | |
| 239 | + function ( $key ) { | |
| 232 | 240 | // We also don't want to include any oembed post meta because it gets created after a post created |
| 233 | - return ! in_array( $key, $excluded_keys, true ) && ! str_contains( $key, '_oembed' ); | |
| 241 | + return ! str_contains( $key, '_oembed' ); | |
| 234 | 242 | } |
| 235 | 243 | ); |
| 236 | 244 | // Return the filtered array |
| 237 | 245 | return $filtered_keys; |