Example #1
0
 /**
  * Retrieves the avatar urls in various sizes based on a given email address.
  *
  * @since 4.4.0
  *
  * @see get_avatar_url()
  *
  * @param string $email Email address.
  * @return array $urls Gravatar url for each size.
  */
 function rest_get_avatar_urls($email)
 {
     $avatar_sizes = rest_get_avatar_sizes();
     $urls = array();
     foreach ($avatar_sizes as $size) {
         $urls[$size] = get_avatar_url($email, array('size' => $size));
     }
     return $urls;
 }
 /**
  * Get the Comment's schema, conforming to JSON Schema
  *
  * @return array
  */
 public function get_item_schema()
 {
     $avatar_properties = array();
     $avatar_sizes = rest_get_avatar_sizes();
     foreach ($avatar_sizes as $size) {
         $avatar_properties[$size] = array('description' => 'Avatar URL with image size of ' . $size . ' pixels.', 'type' => 'uri', 'context' => array('embed', 'view', 'edit'));
     }
     $schema = array('$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'comment', 'type' => 'object', 'properties' => array('id' => array('description' => 'Unique identifier for the object.', 'type' => 'integer', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'author' => array('description' => 'The id of the user object, if author was a user.', 'type' => 'integer', 'context' => array('view', 'edit', 'embed')), 'author_avatar_urls' => array('description' => 'Avatar URLs for the object author.', 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'readonly' => true, 'properties' => $avatar_properties), 'author_email' => array('description' => 'Email address for the object author.', 'type' => 'string', 'format' => 'email', 'context' => array('edit')), 'author_ip' => array('description' => 'IP address for the object author.', 'type' => 'string', 'context' => array('edit'), 'readonly' => true), 'author_name' => array('description' => 'Display name for the object author.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field', 'default' => '')), 'author_url' => array('description' => 'URL for the object author.', 'type' => 'string', 'format' => 'uri', 'context' => array('view', 'edit', 'embed')), 'author_user_agent' => array('description' => 'User agent for the object author.', 'type' => 'string', 'context' => array('edit'), 'readonly' => true), 'content' => array('description' => 'The content for the object.', 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'properties' => array('raw' => array('description' => 'Content for the object, as it exists in the database.', 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => 'Content for the object, transformed for display.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'))), 'arg_options' => array('sanitize_callback' => 'wp_filter_post_kses', 'default' => '')), 'date' => array('description' => 'The date the object was published.', 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit', 'embed')), 'date_gmt' => array('description' => 'The date the object was published as GMT.', 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit')), 'karma' => array('description' => 'Karma for the object.', 'type' => 'integer', 'context' => array('edit')), 'link' => array('description' => 'URL to the object.', 'type' => 'string', 'format' => 'uri', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'parent' => array('description' => 'The id for the parent of the object.', 'type' => 'integer', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('default' => 0)), 'post' => array('description' => 'The id of the associated post object.', 'type' => 'integer', 'context' => array('view', 'edit')), 'status' => array('description' => 'State of the object.', 'type' => 'string', 'context' => array('view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_key')), 'type' => array('description' => 'Type of Comment for the object.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('sanitize_callback' => 'sanitize_key', 'default' => ''))));
     return $this->add_additional_fields_schema($schema);
 }
 /**
  * Get the User's schema, conforming to JSON Schema
  *
  * @return array
  */
 public function get_item_schema()
 {
     $avatar_properties = array();
     $avatar_sizes = rest_get_avatar_sizes();
     foreach ($avatar_sizes as $size) {
         $avatar_properties[$size] = array('description' => 'Avatar URL with image size of ' . $size . ' pixels.', 'type' => 'uri', 'context' => array('embed', 'view', 'edit'));
     }
     global $wp_roles;
     $schema = array('$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'user', 'type' => 'object', 'properties' => array('id' => array('description' => 'Unique identifier for the object.', 'type' => 'integer', 'context' => array('embed', 'view', 'edit'), 'readonly' => true), 'username' => array('description' => 'Login name for the user.', 'type' => 'string', 'context' => array('edit'), 'required' => true, 'arg_options' => array('sanitize_callback' => 'sanitize_user')), 'name' => array('description' => 'Display name for the object.', 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'first_name' => array('description' => 'First name for the object.', 'type' => 'string', 'context' => array('view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'last_name' => array('description' => 'Last name for the object.', 'type' => 'string', 'context' => array('view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'email' => array('description' => 'The email address for the object.', 'type' => 'string', 'format' => 'email', 'context' => array('view', 'edit'), 'required' => true), 'url' => array('description' => 'URL of the object.', 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit'), 'readonly' => true), 'description' => array('description' => 'Description of the object.', 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => 'wp_filter_post_kses')), 'link' => array('description' => 'Author URL to the object.', 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit'), 'readonly' => true), 'avatar_urls' => array('description' => 'Avatar URLs for the object.', 'type' => 'object', 'context' => array('embed', 'view', 'edit'), 'readonly' => true, 'properties' => $avatar_properties), 'nickname' => array('description' => 'The nickname for the object.', 'type' => 'string', 'context' => array('view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'slug' => array('description' => 'An alphanumeric identifier for the object unique to its type.', 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_title')), 'registered_date' => array('description' => 'Registration date for the user.', 'type' => 'date-time', 'context' => array('view', 'edit'), 'readonly' => true), 'roles' => array('description' => 'Roles assigned to the user.', 'type' => 'array', 'context' => array('view', 'edit'), 'readonly' => true), 'role' => array('description' => 'Role assigned to the user.', 'type' => 'string', 'enum' => array_keys($wp_roles->role_objects)), 'capabilities' => array('description' => 'All capabilities assigned to the user.', 'type' => 'object', 'context' => array('view', 'edit')), 'extra_capabilities' => array('description' => 'Any extra capabilities assigned to the user.', 'type' => 'object', 'context' => array('edit'), 'readonly' => true)));
     return $this->add_additional_fields_schema($schema);
 }
 /**
  * Retrieves the user's schema, conforming to JSON Schema.
  *
  * @since 4.7.0
  * @access public
  *
  * @return array Item schema data.
  */
 public function get_item_schema()
 {
     $schema = array('$schema' => 'http://json-schema.org/schema#', 'title' => 'user', 'type' => 'object', 'properties' => array('id' => array('description' => __('Unique identifier for the resource.'), 'type' => 'integer', 'context' => array('embed', 'view', 'edit'), 'readonly' => true), 'username' => array('description' => __('Login name for the resource.'), 'type' => 'string', 'context' => array('edit'), 'required' => true, 'arg_options' => array('sanitize_callback' => 'sanitize_user')), 'name' => array('description' => __('Display name for the resource.'), 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'first_name' => array('description' => __('First name for the resource.'), 'type' => 'string', 'context' => array('edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'last_name' => array('description' => __('Last name for the resource.'), 'type' => 'string', 'context' => array('edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'email' => array('description' => __('The email address for the resource.'), 'type' => 'string', 'format' => 'email', 'context' => array('edit'), 'required' => true), 'url' => array('description' => __('URL of the resource.'), 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit')), 'description' => array('description' => __('Description of the resource.'), 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => 'wp_filter_post_kses')), 'link' => array('description' => __('Author URL to the resource.'), 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit'), 'readonly' => true), 'locale' => array('description' => __('Locale for the resource.'), 'type' => 'string', 'enum' => array_merge(array('', 'en_US'), get_available_languages()), 'context' => array('edit')), 'nickname' => array('description' => __('The nickname for the resource.'), 'type' => 'string', 'context' => array('edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'slug' => array('description' => __('An alphanumeric identifier for the resource.'), 'type' => 'string', 'context' => array('embed', 'view', 'edit'), 'arg_options' => array('sanitize_callback' => array($this, 'sanitize_slug'))), 'registered_date' => array('description' => __('Registration date for the resource.'), 'type' => 'string', 'format' => 'date-time', 'context' => array('edit'), 'readonly' => true), 'roles' => array('description' => __('Roles assigned to the resource.'), 'type' => 'array', 'items' => array('type' => 'string'), 'context' => array('edit')), 'password' => array('description' => __('Password for the resource (never included).'), 'type' => 'string', 'context' => array(), 'required' => true), 'capabilities' => array('description' => __('All capabilities assigned to the resource.'), 'type' => 'object', 'context' => array('edit'), 'readonly' => true), 'extra_capabilities' => array('description' => __('Any extra capabilities assigned to the resource.'), 'type' => 'object', 'context' => array('edit'), 'readonly' => true)));
     if (get_option('show_avatars')) {
         $avatar_properties = array();
         $avatar_sizes = rest_get_avatar_sizes();
         foreach ($avatar_sizes as $size) {
             $avatar_properties[$size] = array('description' => sprintf(__('Avatar URL with image size of %d pixels.'), $size), 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit'));
         }
         $schema['properties']['avatar_urls'] = array('description' => __('Avatar URLs for the resource.'), 'type' => 'object', 'context' => array('embed', 'view', 'edit'), 'readonly' => true, 'properties' => $avatar_properties);
     }
     $schema['properties']['meta'] = $this->meta->get_field_schema();
     return $this->add_additional_fields_schema($schema);
 }
 /**
  * Retrieves the comment's schema, conforming to JSON Schema.
  *
  * @since 4.7.0
  * @access public
  *
  * @return array
  */
 public function get_item_schema()
 {
     $schema = array('$schema' => 'http://json-schema.org/schema#', 'title' => 'comment', 'type' => 'object', 'properties' => array('id' => array('description' => __('Unique identifier for the object.'), 'type' => 'integer', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'author' => array('description' => __('The ID of the user object, if author was a user.'), 'type' => 'integer', 'context' => array('view', 'edit', 'embed')), 'author_email' => array('description' => __('Email address for the object author.'), 'type' => 'string', 'format' => 'email', 'context' => array('edit'), 'arg_options' => array('sanitize_callback' => array($this, 'check_comment_author_email'), 'validate_callback' => null)), 'author_ip' => array('description' => __('IP address for the object author.'), 'type' => 'string', 'format' => 'ip', 'context' => array('edit')), 'author_name' => array('description' => __('Display name for the object author.'), 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'author_url' => array('description' => __('URL for the object author.'), 'type' => 'string', 'format' => 'uri', 'context' => array('view', 'edit', 'embed')), 'author_user_agent' => array('description' => __('User agent for the object author.'), 'type' => 'string', 'context' => array('edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_text_field')), 'content' => array('description' => __('The content for the object.'), 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('sanitize_callback' => null), 'properties' => array('raw' => array('description' => __('Content for the object, as it exists in the database.'), 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => __('HTML content for the object, transformed for display.'), 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'readonly' => true))), 'date' => array('description' => __("The date the object was published, in the site's timezone."), 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit', 'embed')), 'date_gmt' => array('description' => __('The date the object was published, as GMT.'), 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit')), 'link' => array('description' => __('URL to the object.'), 'type' => 'string', 'format' => 'uri', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'parent' => array('description' => __('The ID for the parent of the object.'), 'type' => 'integer', 'context' => array('view', 'edit', 'embed'), 'default' => 0), 'post' => array('description' => __('The ID of the associated post object.'), 'type' => 'integer', 'context' => array('view', 'edit'), 'default' => 0), 'status' => array('description' => __('State of the object.'), 'type' => 'string', 'context' => array('view', 'edit'), 'arg_options' => array('sanitize_callback' => 'sanitize_key')), 'type' => array('description' => __('Type of Comment for the object.'), 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'readonly' => true)));
     if (get_option('show_avatars')) {
         $avatar_properties = array();
         $avatar_sizes = rest_get_avatar_sizes();
         foreach ($avatar_sizes as $size) {
             $avatar_properties[$size] = array('description' => sprintf(__('Avatar URL with image size of %d pixels.'), $size), 'type' => 'string', 'format' => 'uri', 'context' => array('embed', 'view', 'edit'));
         }
         $schema['properties']['author_avatar_urls'] = array('description' => __('Avatar URLs for the object author.'), 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'readonly' => true, 'properties' => $avatar_properties);
     }
     $schema['properties']['meta'] = $this->meta->get_field_schema();
     return $this->add_additional_fields_schema($schema);
 }