thorization' => 'Bearer YOUR_API_TOKEN', ), ), ) ); new WPCOM_JSON_API_Update_Post_v1_1_Endpoint( array( 'description' => 'Restore a post or page from the trash to its previous status.', 'group' => 'posts', 'stat' => 'posts:1:restore', 'min_version' => '1.1', 'max_version' => '1.1', 'method' => 'POST', 'path' => '/sites/%s/posts/%d/restore', 'path_labels' => array( '$site' => '(int|string) Site ID or domain', '$post_ID' => '(int) The post ID', ), 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/posts/$post_ID/restore/', 'example_request_data' => array( 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN', ), ), ) ); // phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid /** * Update post v1.1 endpoint class. */ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_Endpoint { /** * WPCOM_JSON_API_Update_Post_v1_1_Endpoint constructor. * * @param array $args Args. */ public function __construct( $args ) { parent::__construct( $args ); if ( $this->api->ends_with( $this->path, '/delete' ) ) { $this->post_object_format['status']['deleted'] = 'The post has been deleted permanently.'; } } /** * Update post API v1.1 callback. * * /sites/%s/posts/new -> $blog_id * /sites/%s/posts/%d -> $blog_id, $post_id * /sites/%s/posts/%d/delete -> $blog_id, $post_id * /sites/%s/posts/%d/restore -> $blog_id, $post_id * * @param string $path API path. * @param int $blog_id Blog ID. * @param int $post_id Post ID. * * @return array|bool|WP_Error */ public function callback( $path = '', $blog_id = 0, $post_id = 0 ) { $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); if ( is_wp_error( $blog_id ) ) { return $blog_id; } if ( $this->api->ends_with( $path, '/delete' ) ) { return $this->delete_post( $path, $blog_id, $post_id ); } elseif ( $this->api->ends_with( $path, '/restore' ) ) { return $this->restore_post( $path, $blog_id, $post_id ); } else { return $this->write_post( $path, $blog_id, $post_id ); } } /** * Create or update a post. * * /sites/%s/posts/new -> $blog_id * /sites/%s/posts/%d -> $blog_id, $post_id * * @param string $path API path. * @param int $blog_id Blog ID. * @param int $post_id Post ID. */ public function write_post( $path, $blog_id, $post_id ) { $delete_featured_image = null; $media_results = array(); $post = null; global $wpdb; $new = $this->api->ends_with( $path, '/new' ); $args = $this->query_args(); // unhook publicize, it's hooked again later -- without this, skipping services is impossible. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { remove_action( 'save_post', array( $GLOBALS['publicize_ui']->publicize, 'async_publicize_post' ), 100, 2 ); add_action( 'rest_api_inserted_post', array( $GLOBALS['publicize_ui']->publicize, 'async_publicize_post' ) ); if ( $this->should_load_theme_functions( $post_id ) ) { $this->load_theme_functions(); } } if ( $new ) { $input = $this->input( true ); // 'future' is an alias for 'publish' for now if ( 'future' === $input['status'] ) { $input['status'] = 'publish'; } // default to post. if ( empty( $input['type'] ) ) { $input['type'] = 'post'; } if ( 'revision' === $input['type'] ) { if ( ! isset( $input['parent'] ) ) { return new WP_Error( 'invalid_input', 'Invalid request input', 400 ); } $input['status'] = 'inherit'; // force inherit for revision t Blog Posts -

Blog Posts

Front Commercial real estate development site

High Potential Markets

Do you know the 5-Step Process for Quickly Finding High Potential Markets? There are sites, old buildings needing demo and redevelopment, government tax credits, and

Read More »
Erin-EJR-Group

Erin Jackson of EJR Group

Her position at EJR Group is to help cut through the complexities of development by organizing critical development information into a built reality. Questions +

Read More »
jim-EJR-Group-partner

Jim Roachelle of EJR Group

His decades of work in private development and helping clients navigate government at the local, state, and federal level uniquely positions EJR Group to help

Read More »
Construction site with bull dozer and text space

Tips for Staying Ahead in Construction

Tips to Stay Ahead in Construction Add More contingency to your budget than you think you should Everything takes longer, from entitlements/permitting, appraisals, and securing construction loans

Read More »
LinkedIn
Twitter