Code Duplication    Length = 7-7 lines in 3 locations

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

@@ 328-334 (lines=7) @@
325
			$input['date'] = date( 'Y-m-d H:i:s', $time_with_offset );
326
		}
327
328
		if ( ! empty( $author_id ) && get_current_user_id() != $author_id ) {
329
			if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
330
				return new WP_Error( 'unauthorized', "User is not allowed to publish others' posts.", 403 );
331
			} elseif ( ! user_can( $author_id, $post_type->cap->edit_posts ) ) {
332
				return new WP_Error( 'unauthorized', 'Assigned author cannot publish post.', 403 );
333
			}
334
		}
335
336
		if ( !is_post_type_hierarchical( $post_type->name ) && 'revision' !== $post_type->name ) {
337
			unset( $input['parent'] );

json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php 1 location

@@ 351-357 (lines=7) @@
348
			$input['date'] = date( 'Y-m-d H:i:s', $time_with_offset );
349
		}
350
351
		if ( ! empty( $author_id ) && get_current_user_id() != $author_id ) {
352
			if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
353
				return new WP_Error( 'unauthorized', "User is not allowed to publish others' posts.", 403 );
354
			} elseif ( ! user_can( $author_id, $post_type->cap->edit_posts ) ) {
355
				return new WP_Error( 'unauthorized', 'Assigned author cannot publish post.', 403 );
356
			}
357
		}
358
359
		if ( !is_post_type_hierarchical( $post_type->name ) && 'revision' !== $post_type->name ) {
360
			unset( $input['parent'] );

json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php 1 location

@@ 295-301 (lines=7) @@
292
			$input['date'] = date( 'Y-m-d H:i:s', $time_with_offset );
293
		}
294
295
		if ( ! empty( $author_id ) && get_current_user_id() != $author_id ) {
296
			if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
297
				return new WP_Error( 'unauthorized', "User is not allowed to publish others' posts.", 403 );
298
			} elseif ( ! user_can( $author_id, $post_type->cap->edit_posts ) ) {
299
				return new WP_Error( 'unauthorized', 'Assigned author cannot publish post.', 403 );
300
			}
301
		}
302
303
		if ( !is_post_type_hierarchical( $post_type->name ) && 'revision' !== $post_type->name ) {
304
			unset( $input['parent'] );