Code Duplication    Length = 37-37 lines in 2 locations

json-endpoints/class.wpcom-json-api-update-post-endpoint.php 1 location

@@ 830-866 (lines=37) @@
827
	}
828
829
	// /sites/%s/posts/%d/delete -> $blog_id, $post_id
830
	function delete_post( $path, $blog_id, $post_id ) {
831
		$post = get_post( $post_id );
832
		if ( !$post || is_wp_error( $post ) ) {
833
			return new WP_Error( 'unknown_post', 'Unknown post', 404 );
834
		}
835
836
		if ( ! $this->is_post_type_allowed( $post->post_type ) ) {
837
			return new WP_Error( 'unknown_post_type', 'Unknown post type', 404 );
838
		}
839
840
		if ( !current_user_can( 'delete_post', $post->ID ) ) {
841
			return new WP_Error( 'unauthorized', 'User cannot delete posts', 403 );
842
		}
843
844
		$args  = $this->query_args();
845
		$return = $this->get_post_by( 'ID', $post->ID, $args['context'] );
846
		if ( !$return || is_wp_error( $return ) ) {
847
			return $return;
848
		}
849
850
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
851
		do_action( 'wpcom_json_api_objects', 'posts' );
852
853
		// we need to call wp_trash_post so that untrash will work correctly for all post types
854
		if ( 'trash' === $post->post_status )
855
			wp_delete_post( $post->ID );
856
		else
857
			wp_trash_post( $post->ID );
858
859
		$status = get_post_status( $post->ID );
860
		if ( false === $status ) {
861
			$return['status'] = 'deleted';
862
			return $return;
863
		}
864
865
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
866
	}
867
868
	// /sites/%s/posts/%d/restore -> $blog_id, $post_id
869
	function restore_post( $path, $blog_id, $post_id ) {

json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php 1 location

@@ 898-934 (lines=37) @@
895
	}
896
897
	// /sites/%s/posts/%d/delete -> $blog_id, $post_id
898
	function delete_post( $path, $blog_id, $post_id ) {
899
		$post = get_post( $post_id );
900
		if ( !$post || is_wp_error( $post ) ) {
901
			return new WP_Error( 'unknown_post', 'Unknown post', 404 );
902
		}
903
904
		if ( ! $this->is_post_type_allowed( $post->post_type ) ) {
905
			return new WP_Error( 'unknown_post_type', 'Unknown post type', 404 );
906
		}
907
908
		if ( !current_user_can( 'delete_post', $post->ID ) ) {
909
			return new WP_Error( 'unauthorized', 'User cannot delete posts', 403 );
910
		}
911
912
		$args  = $this->query_args();
913
		$return = $this->get_post_by( 'ID', $post->ID, $args['context'] );
914
		if ( !$return || is_wp_error( $return ) ) {
915
			return $return;
916
		}
917
918
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
919
		do_action( 'wpcom_json_api_objects', 'posts' );
920
921
		// we need to call wp_trash_post so that untrash will work correctly for all post types
922
		if ( 'trash' === $post->post_status )
923
			wp_delete_post( $post->ID );
924
		else
925
			wp_trash_post( $post->ID );
926
927
		$status = get_post_status( $post->ID );
928
		if ( false === $status ) {
929
			$return['status'] = 'deleted';
930
			return $return;
931
		}
932
933
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
934
	}
935
936
	// /sites/%s/posts/%d/restore -> $blog_id, $post_id
937
	function restore_post( $path, $blog_id, $post_id ) {