Code Duplication    Length = 21-22 lines in 2 locations

lib/endpoints/class-wp-rest-comments-controller.php 1 location

@@ 927-947 (lines=21) @@
924
			),
925
		);
926
927
		if ( get_option( 'show_avatars' ) ) {
928
			$avatar_properties = array();
929
930
			$avatar_sizes = rest_get_avatar_sizes();
931
			foreach ( $avatar_sizes as $size ) {
932
				$avatar_properties[ $size ] = array(
933
					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ),
934
					'type'        => 'string',
935
					'format'      => 'uri',
936
					'context'     => array( 'embed', 'view', 'edit' ),
937
				);
938
			}
939
940
			$schema['properties']['author_avatar_urls'] = array(
941
				'description'   => __( 'Avatar URLs for the object author.' ),
942
				'type'          => 'object',
943
				'context'       => array( 'view', 'edit', 'embed' ),
944
				'readonly'      => true,
945
				'properties'    => $avatar_properties,
946
			);
947
		}
948
949
		return $this->add_additional_fields_schema( $schema );
950
	}

lib/endpoints/class-wp-rest-users-controller.php 1 location

@@ 849-870 (lines=22) @@
846
			),
847
		);
848
849
		if ( get_option( 'show_avatars' ) ) {
850
			$avatar_properties = array();
851
852
			$avatar_sizes = rest_get_avatar_sizes();
853
			foreach ( $avatar_sizes as $size ) {
854
				$avatar_properties[ $size ] = array(
855
					'description' => sprintf( __( 'Avatar URL with image size of %d pixels.' ), $size ),
856
					'type'        => 'string',
857
					'format'      => 'uri',
858
					'context'     => array( 'embed', 'view', 'edit' ),
859
				);
860
			}
861
862
			$schema['properties']['avatar_urls']  = array(
863
				'description' => __( 'Avatar URLs for the resource.' ),
864
				'type'        => 'object',
865
				'context'     => array( 'embed', 'view', 'edit' ),
866
				'readonly'    => true,
867
				'properties'  => $avatar_properties,
868
			);
869
870
		}
871
872
		return $this->add_additional_fields_schema( $schema );
873
	}