Code Duplication    Length = 33-33 lines in 2 locations

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

@@ 630-662 (lines=33) @@
627
	}
628
629
	// /sites/%s/posts/%d/delete -> $blog_id, $post_id
630
	function delete_post( $path, $blog_id, $post_id ) {
631
		$post = get_post( $post_id );
632
		if ( !$post || is_wp_error( $post ) ) {
633
			return new WP_Error( 'unknown_post', 'Unknown post', 404 );
634
		}
635
636
		if ( ! $this->is_post_type_allowed( $post->post_type ) ) {
637
			return new WP_Error( 'unknown_post_type', 'Unknown post type', 404 );
638
		}
639
640
		if ( !current_user_can( 'delete_post', $post->ID ) ) {
641
			return new WP_Error( 'unauthorized', 'User cannot delete posts', 403 );
642
		}
643
644
		$args  = $this->query_args();
645
		$return = $this->get_post_by( 'ID', $post->ID, $args['context'] );
646
		if ( !$return || is_wp_error( $return ) ) {
647
			return $return;
648
		}
649
650
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
651
		do_action( 'wpcom_json_api_objects', 'posts' );
652
653
		wp_delete_post( $post->ID );
654
655
		$status = get_post_status( $post->ID );
656
		if ( false === $status ) {
657
			$return['status'] = 'deleted';
658
			return $return;
659
		}
660
661
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
662
	}
663
664
	// /sites/%s/posts/%d/restore -> $blog_id, $post_id
665
	function restore_post( $path, $blog_id, $post_id ) {

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

@@ 619-651 (lines=33) @@
616
	}
617
618
	// /sites/%s/posts/%d/delete -> $blog_id, $post_id
619
	function delete_post( $path, $blog_id, $post_id ) {
620
		$post = get_post( $post_id );
621
		if ( !$post || is_wp_error( $post ) ) {
622
			return new WP_Error( 'unknown_post', 'Unknown post', 404 );
623
		}
624
625
		if ( ! $this->is_post_type_allowed( $post->post_type ) ) {
626
			return new WP_Error( 'unknown_post_type', 'Unknown post type', 404 );
627
		}
628
629
		if ( !current_user_can( 'delete_post', $post->ID ) ) {
630
			return new WP_Error( 'unauthorized', 'User cannot delete posts', 403 );
631
		}
632
633
		$args  = $this->query_args();
634
		$return = $this->get_post_by( 'ID', $post->ID, $args['context'] );
635
		if ( !$return || is_wp_error( $return ) ) {
636
			return $return;
637
		}
638
639
		/** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
640
		do_action( 'wpcom_json_api_objects', 'posts' );
641
642
		wp_delete_post( $post->ID );
643
644
		$status = get_post_status( $post->ID );
645
		if ( false === $status ) {
646
			$return['status'] = 'deleted';
647
			return $return;
648
		}
649
650
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
651
	}
652
653
	// /sites/%s/posts/%d/restore -> $blog_id, $post_id
654
	function restore_post( $path, $blog_id, $post_id ) {