summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php20
1 files changed, 19 insertions, 1 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php
index b3d9b98d..4dbe5fe5 100644
--- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php
@@ -329,6 +329,11 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_
if ( $reset_draft_date || $reset_scheduled_date ) {
$input['date_gmt'] = gmdate( 'Y-m-d H:i:s' );
}
+
+ // Untrash a post so that the proper hooks get called as well as the comments get untrashed.
+ if ( $this->should_untrash_post( $last_status, $new_status, $post ) ) {
+ $input = $this->untrash_post( $post, $input );
+ }
}
if ( function_exists( 'wpcom_switch_to_blog_locale' ) ) {
@@ -784,7 +789,6 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_
$meta = (object) $meta;
- // Custom meta description can only be set on sites that have a business subscription.
if ( Jetpack_SEO_Posts::DESCRIPTION_META_KEY == $meta->key && ! Jetpack_SEO_Utils::is_enabled_jetpack_seo() ) {
return new WP_Error( 'unauthorized', __( 'SEO tools are not enabled for this site.', 'jetpack' ), 403 );
}
@@ -992,6 +996,20 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_
return $_user->ID;
}
+ protected function should_untrash_post( $last_status, $new_status, $post ) {
+ return 'trash' === $last_status && 'trash' !== $new_status && isset( $post->ID );
+ }
+
+ protected function untrash_post( $post, $input ) {
+ wp_untrash_post( $post->ID );
+ $untrashed_post = get_post( $post->ID );
+ // Lets make sure that we use the reverted the slug.
+ if ( isset( $untrashed_post->post_name ) && $untrashed_post->post_name . '__trashed' === $input['slug'] ) {
+ unset( $input['slug'] );
+ }
+ return $input;
+ }
+
protected function should_load_theme_functions( $post_id = null ) {
if ( empty( $post_id ) ) {
$input = $this->input( true );