wp/wp-admin/includes/class-wp-site-icon.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    18 	 * The minimum size of the site icon.
    18 	 * The minimum size of the site icon.
    19 	 *
    19 	 *
    20 	 * @since 4.3.0
    20 	 * @since 4.3.0
    21 	 * @var int
    21 	 * @var int
    22 	 */
    22 	 */
    23 	public $min_size  = 512;
    23 	public $min_size = 512;
    24 
    24 
    25 	/**
    25 	/**
    26 	 * The size to which to crop the image so that we can display it in the UI nicely.
    26 	 * The size to which to crop the image so that we can display it in the UI nicely.
    27 	 *
    27 	 *
    28 	 * @since 4.3.0
    28 	 * @since 4.3.0
    32 
    32 
    33 	/**
    33 	/**
    34 	 * List of site icon sizes.
    34 	 * List of site icon sizes.
    35 	 *
    35 	 *
    36 	 * @since 4.3.0
    36 	 * @since 4.3.0
    37 	 * @var array
    37 	 * @var int[]
    38 	 */
    38 	 */
    39 	public $site_icon_sizes = array(
    39 	public $site_icon_sizes = array(
    40 		/*
    40 		/*
    41 		 * Square, medium sized tiles for IE11+.
    41 		 * Square, medium sized tiles for IE11+.
    42 		 *
    42 		 *
    83 	 * @return array Attachment object.
    83 	 * @return array Attachment object.
    84 	 */
    84 	 */
    85 	public function create_attachment_object( $cropped, $parent_attachment_id ) {
    85 	public function create_attachment_object( $cropped, $parent_attachment_id ) {
    86 		$parent     = get_post( $parent_attachment_id );
    86 		$parent     = get_post( $parent_attachment_id );
    87 		$parent_url = wp_get_attachment_url( $parent->ID );
    87 		$parent_url = wp_get_attachment_url( $parent->ID );
    88 		$url        = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
    88 		$url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
    89 
    89 
    90 		$size       = @getimagesize( $cropped );
    90 		$size       = @getimagesize( $cropped );
    91 		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
    91 		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
    92 
    92 
    93 		$object = array(
    93 		$object = array(
    94 			'ID'             => $parent_attachment_id,
    94 			'ID'             => $parent_attachment_id,
    95 			'post_title'     => basename( $cropped ),
    95 			'post_title'     => wp_basename( $cropped ),
    96 			'post_content'   => $url,
    96 			'post_content'   => $url,
    97 			'post_mime_type' => $image_type,
    97 			'post_mime_type' => $image_type,
    98 			'guid'           => $url,
    98 			'guid'           => $url,
    99 			'context'        => 'site-icon'
    99 			'context'        => 'site-icon',
   100 		);
   100 		);
   101 
   101 
   102 		return $object;
   102 		return $object;
   103 	}
   103 	}
   104 
   104 
   129 
   129 
   130 		return $attachment_id;
   130 		return $attachment_id;
   131 	}
   131 	}
   132 
   132 
   133 	/**
   133 	/**
   134 	 * Adds additional sizes to be made when creating the site_icon images.
   134 	 * Adds additional sizes to be made when creating the site icon images.
   135 	 *
   135 	 *
   136 	 * @since 4.3.0
   136 	 * @since 4.3.0
   137 	 *
   137 	 *
   138 	 * @param array $sizes List of additional sizes.
   138 	 * @param array[] $sizes Array of arrays containing information for additional sizes.
   139 	 * @return array Additional image sizes.
   139 	 * @return array[] Array of arrays containing additional image sizes.
   140 	 */
   140 	 */
   141 	public function additional_sizes( $sizes = array() ) {
   141 	public function additional_sizes( $sizes = array() ) {
   142 		$only_crop_sizes = array();
   142 		$only_crop_sizes = array();
   143 
   143 
   144 		/**
   144 		/**
   145 		 * Filters the different dimensions that a site icon is saved in.
   145 		 * Filters the different dimensions that a site icon is saved in.
   146 		 *
   146 		 *
   147 		 * @since 4.3.0
   147 		 * @since 4.3.0
   148 		 *
   148 		 *
   149 		 * @param array $site_icon_sizes Sizes available for the Site Icon.
   149 		 * @param int[] $site_icon_sizes Array of sizes available for the Site Icon.
   150 		 */
   150 		 */
   151 		$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
   151 		$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
   152 
   152 
   153 		// Use a natural sort of numbers.
   153 		// Use a natural sort of numbers.
   154 		natsort( $this->site_icon_sizes );
   154 		natsort( $this->site_icon_sizes );
   177 	/**
   177 	/**
   178 	 * Adds Site Icon sizes to the array of image sizes on demand.
   178 	 * Adds Site Icon sizes to the array of image sizes on demand.
   179 	 *
   179 	 *
   180 	 * @since 4.3.0
   180 	 * @since 4.3.0
   181 	 *
   181 	 *
   182 	 * @param array $sizes List of image sizes.
   182 	 * @param string[] $sizes Array of image size names.
   183 	 * @return array List of intermediate image sizes.
   183 	 * @return string[] Array of image size names.
   184 	 */
   184 	 */
   185 	public function intermediate_image_sizes( $sizes = array() ) {
   185 	public function intermediate_image_sizes( $sizes = array() ) {
   186 		/** This filter is documented in wp-admin/includes/class-wp-site-icon.php */
   186 		/** This filter is documented in wp-admin/includes/class-wp-site-icon.php */
   187 		$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
   187 		$this->site_icon_sizes = apply_filters( 'site_icon_image_sizes', $this->site_icon_sizes );
   188 		foreach ( $this->site_icon_sizes as $size ) {
   188 		foreach ( $this->site_icon_sizes as $size ) {