Code Duplication    Length = 33-33 lines in 2 locations

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

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

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

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