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-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'],

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

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