Code Duplication    Length = 23-23 lines in 3 locations

json-endpoints/class.wpcom-json-api-list-posts-endpoint.php 1 location

@@ 42-64 (lines=23) @@
39
		// determine statuses
40
		$status = $args['status'];
41
		$status = ( $status ) ? explode( ',', $status ) : array( 'publish' );
42
		if ( is_user_logged_in() ) {
43
			$statuses_whitelist = array(
44
				'publish',
45
				'pending',
46
				'draft',
47
				'future',
48
				'private',
49
				'trash',
50
				'any',
51
			);
52
			$status = array_intersect( $status, $statuses_whitelist );
53
		} else {
54
			// logged-out users can see only published posts
55
			$statuses_whitelist = array( 'publish', 'any' );
56
			$status = array_intersect( $status, $statuses_whitelist );
57
58
			if ( empty( $status ) ) {
59
				// requested only protected statuses? nothing for you here
60
				return array( 'found' => 0, 'posts' => array() );
61
			}
62
			// clear it (AKA published only) because "any" includes protected
63
			$status = array();
64
		}
65
66
		// let's be explicit about defaulting to 'post'
67
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';

json-endpoints/class.wpcom-json-api-list-posts-v1-1-endpoint.php 1 location

@@ 47-69 (lines=23) @@
44
45
		// determine statuses
46
		$status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' );
47
		if ( is_user_logged_in() ) {
48
			$statuses_whitelist = array(
49
				'publish',
50
				'pending',
51
				'draft',
52
				'future',
53
				'private',
54
				'trash',
55
				'any',
56
			);
57
			$status = array_intersect( $status, $statuses_whitelist );
58
		} else {
59
			// logged-out users can see only published posts
60
			$statuses_whitelist = array( 'publish', 'any' );
61
			$status = array_intersect( $status, $statuses_whitelist );
62
63
			if ( empty( $status ) ) {
64
				// requested only protected statuses? nothing for you here
65
				return array( 'found' => 0, 'posts' => array() );
66
			}
67
			// clear it (AKA published only) because "any" includes protected
68
			$status = array();
69
		}
70
71
		if ( isset( $args['type'] ) &&
72
			   ! in_array( $args['type'], array( 'post', 'revision', 'page', 'any' ) ) &&

json-endpoints/class.wpcom-json-api-list-posts-v1-2-endpoint.php 1 location

@@ 75-97 (lines=23) @@
72
73
		// determine statuses
74
		$status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' );
75
		if ( is_user_logged_in() ) {
76
			$statuses_whitelist = array(
77
				'publish',
78
				'pending',
79
				'draft',
80
				'future',
81
				'private',
82
				'trash',
83
				'any',
84
			);
85
			$status = array_intersect( $status, $statuses_whitelist );
86
		} else {
87
			// logged-out users can see only published posts
88
			$statuses_whitelist = array( 'publish', 'any' );
89
			$status = array_intersect( $status, $statuses_whitelist );
90
91
			if ( empty( $status ) ) {
92
				// requested only protected statuses? nothing for you here
93
				return array( 'found' => 0, 'posts' => array() );
94
			}
95
			// clear it (AKA published only) because "any" includes protected
96
			$status = array();
97
		}
98
99
		$query = array(
100
			'posts_per_page' => $args['number'],