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

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

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

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