Skip to content

Commit

Permalink
Import: setting WP_IMPORTING to true when doing an import (#40563)
Browse files Browse the repository at this point in the history
* Setting WP_IMPORTING while import
  • Loading branch information
ouikhuan authored Dec 11, 2024
1 parent cb69d68 commit fac4d21
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/packages/import/changelog/fix-wp-import-issue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Import: setting WP_IMPORTING when doing an import
2 changes: 2 additions & 0 deletions projects/packages/import/src/endpoints/class-attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function register_routes() {
* @return WP_REST_Response|WP_Error Response object on success, WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();
$file_info = $this->get_file_info( $request );
$attachment = $this->get_attachment_by_file_info( $file_info );
if ( $attachment ) {
Expand Down
2 changes: 2 additions & 0 deletions projects/packages/import/src/endpoints/class-comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function __construct() {
* @return WP_REST_Response|WP_Error Response object on success, or error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();
// Resolve comment post ID.
if ( ! empty( $request['post'] ) ) {
$posts = \get_posts( $this->get_import_db_query( $request['post'] ) );
Expand Down
2 changes: 2 additions & 0 deletions projects/packages/import/src/endpoints/class-custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function __construct() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();
$args = array(
'stylesheet' => $request['title'],
);
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-global-style.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public function add_additional_fields_schema( $schema ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

if ( ! class_exists( 'WP_Theme_JSON_Resolver' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-theme-json-resolver.php';
}
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-menu-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public function add_additional_fields_schema( $schema ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

if ( ! empty( $request['menus'] ) ) {
$menu_id = \term_exists( $request['menus'], 'nav_menu' );

Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function __construct() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

$response = parent::create_item( $request );

// Ensure that the HTTP status is a valid one.
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public function __construct() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

if ( ! empty( $request['parent'] ) ) {
$pages = \get_pages( $this->get_import_db_query( $request['parent'] ) );

Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function add_additional_fields_schema( $schema ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

// Skip if the post already exists.
$post_id = \post_exists(
$request['title'],
Expand Down
3 changes: 3 additions & 0 deletions projects/packages/import/src/endpoints/class-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function __construct() {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
// Set the WP_IMPORTING constant to prevent sync notifications
$this->set_importing();

$response = parent::create_item( $request );

return $this->add_import_id_metadata( $request, $response );
Expand Down
9 changes: 9 additions & 0 deletions projects/packages/import/src/endpoints/trait-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ protected function ensure_http_status( $response, $error_code, $status ) {

return $response;
}

/**
* Set the importing constant.
*/
public function set_importing() {
if ( ! defined( 'WP_IMPORTING' ) ) {
define( 'WP_IMPORTING', true );
}
}
}
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/fix-wp-import-issue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Import: setting WP_IMPORTING when doing an import

0 comments on commit fac4d21

Please sign in to comment.