| 1 |
<?php |
| 2 |
/** |
| 3 |
* Pages REST route |
| 4 |
* |
| 5 |
* @package automattic/jetpack-import |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Import\Endpoints; |
| 9 |
|
| 10 |
use WP_Error; |
| 11 |
use WP_REST_Request; |
| 12 |
use WP_REST_Response; |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit( 0 ); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Class Page |
| 20 |
*/ |
| 21 |
class Page extends Post { |
| 22 |
|
| 23 |
/** |
| 24 |
* Constructor. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
parent::__construct( 'page' ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Creates a single page. |
| 32 |
* |
| 33 |
* @param WP_REST_Request $request Full details about the request. |
| 34 |
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
| 35 |
*/ |
| 36 |
public function create_item( $request ) { |
| 37 |
// Set the WP_IMPORTING constant to prevent sync notifications |
| 38 |
$this->set_importing(); |
| 39 |
|
| 40 |
if ( ! empty( $request['parent'] ) ) { |
| 41 |
$pages = \get_pages( $this->get_import_db_query( $request['parent'] ) ); |
| 42 |
|
| 43 |
// Overwrite the page parent page ID. |
| 44 |
$request['parent'] = is_array( $pages ) && count( $pages ) ? $pages[0]->ID : 0; |
| 45 |
} |
| 46 |
|
| 47 |
$response = parent::create_item( $request ); |
| 48 |
|
| 49 |
return $this->add_import_id_metadata( $request, $response ); |
| 50 |
} |
| 51 |
} |
| 52 |
|