Code Duplication    Length = 34-34 lines in 2 locations

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

@@ 36-69 (lines=34) @@
33
	)
34
) );
35
36
class WPCOM_JSON_API_Bulk_Delete_Post_Endpoint extends WPCOM_JSON_API_Update_Post_v1_1_Endpoint {
37
	// /sites/%s/posts/delete
38
	// The unused $object parameter is for making the method signature compatible with its parent class method.
39
	function callback( $path = '', $blog_id = 0, $object = null ) {
40
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
41
		if ( is_wp_error( $blog_id ) ) {
42
			return $blog_id;
43
		}
44
45
		$input = $this->input();
46
47
		if ( is_array( $input['post_ids'] ) ) {
48
			$post_ids = (array) $input['post_ids'];
49
		} else if ( ! empty( $input['post_ids'] ) ) {
50
			$post_ids = explode( ',', $input['post_ids'] );
51
		} else {
52
			$post_ids = array();
53
		}
54
55
		if ( count( $post_ids ) < 1 ) {
56
			return new WP_Error( 'empty_post_ids', 'The request must include post_ids' );
57
		}
58
59
		$result = array(
60
			'results' => array(),
61
		);
62
63
		foreach( $post_ids as $post_id ) {
64
			$result['results'][ $post_id ] = $this->delete_post( $path, $blog_id, $post_id );
65
		}
66
67
		return $result;
68
	}
69
}
70

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

@@ 36-69 (lines=34) @@
33
	)
34
) );
35
36
class WPCOM_JSON_API_Bulk_Restore_Post_Endpoint extends WPCOM_JSON_API_Update_Post_v1_1_Endpoint {
37
	// /sites/%s/posts/restore
38
	// The unused $object parameter is for making the method signature compatible with its parent class method.
39
	function callback( $path = '', $blog_id = 0, $object = null ) {
40
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) );
41
		if ( is_wp_error( $blog_id ) ) {
42
			return $blog_id;
43
		}
44
45
		$input = $this->input();
46
47
		if ( is_array( $input['post_ids'] ) ) {
48
			$post_ids = (array) $input['post_ids'];
49
		} else if ( ! empty( $input['post_ids'] ) ) {
50
			$post_ids = explode( ',', $input['post_ids'] );
51
		} else {
52
			$post_ids = array();
53
		}
54
55
		if ( count( $post_ids ) < 1 ) {
56
			return new WP_Error( 'empty_post_ids', 'The request must include post_ids' );
57
		}
58
59
		$result = array(
60
			'results' => array(),
61
		);
62
63
		foreach( $post_ids as $post_id ) {
64
			$result['results'][ $post_id ] = $this->restore_post( $path, $blog_id, $post_id );
65
		}
66
67
		return $result;
68
	}
69
}
70