Code Duplication    Length = 23-23 lines in 3 locations

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

@@ 101-123 (lines=23) @@
98
		// determine statuses
99
		$status = $args['status'];
100
		$status = ( $status ) ? explode( ',', $status ) : array( 'publish' );
101
		if ( is_user_logged_in() ) {
102
			$statuses_whitelist = array(
103
				'publish',
104
				'pending',
105
				'draft',
106
				'future',
107
				'private',
108
				'trash',
109
				'any',
110
			);
111
			$status = array_intersect( $status, $statuses_whitelist );
112
		} else {
113
			// logged-out users can see only published posts
114
			$statuses_whitelist = array( 'publish', 'any' );
115
			$status = array_intersect( $status, $statuses_whitelist );
116
117
			if ( empty( $status ) ) {
118
				// requested only protected statuses? nothing for you here
119
				return array( 'found' => 0, 'posts' => array() );
120
			}
121
			// clear it (AKA published only) because "any" includes protected
122
			$status = array();
123
		}
124
125
		// let's be explicit about defaulting to 'post'
126
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';

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

@@ 103-125 (lines=23) @@
100
101
		// determine statuses
102
		$status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' );
103
		if ( is_user_logged_in() ) {
104
			$statuses_whitelist = array(
105
				'publish',
106
				'pending',
107
				'draft',
108
				'future',
109
				'private',
110
				'trash',
111
				'any',
112
			);
113
			$status = array_intersect( $status, $statuses_whitelist );
114
		} else {
115
			// logged-out users can see only published posts
116
			$statuses_whitelist = array( 'publish', 'any' );
117
			$status = array_intersect( $status, $statuses_whitelist );
118
119
			if ( empty( $status ) ) {
120
				// requested only protected statuses? nothing for you here
121
				return array( 'found' => 0, 'posts' => array() );
122
			}
123
			// clear it (AKA published only) because "any" includes protected
124
			$status = array();
125
		}
126
127
		if ( isset( $args['type'] ) &&
128
			   ! in_array( $args['type'], array( 'post', 'revision', 'page', 'any' ) ) &&

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

@@ 126-148 (lines=23) @@
123
124
		// determine statuses
125
		$status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' );
126
		if ( is_user_logged_in() ) {
127
			$statuses_whitelist = array(
128
				'publish',
129
				'pending',
130
				'draft',
131
				'future',
132
				'private',
133
				'trash',
134
				'any',
135
			);
136
			$status = array_intersect( $status, $statuses_whitelist );
137
		} else {
138
			// logged-out users can see only published posts
139
			$statuses_whitelist = array( 'publish', 'any' );
140
			$status = array_intersect( $status, $statuses_whitelist );
141
142
			if ( empty( $status ) ) {
143
				// requested only protected statuses? nothing for you here
144
				return array( 'found' => 0, 'posts' => array() );
145
			}
146
			// clear it (AKA published only) because "any" includes protected
147
			$status = array();
148
		}
149
150
		$query = array(
151
			'posts_per_page' => $args['number'],