Filter hook 'image_size_names_choose'

in WP Core File wp-includes/media.php at line 4599

View Source

image_size_names_choose

Filter Hook
Description
Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. Array of attachment details, or void if the parameter does not correspond to an attachment. (landscape or portrait). for the images sizes: thumbnail, medium, large, and full. }

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 4599

Hook Parameters

Type Name Description
int|WP_Post $attachment Attachment ID or object.

Usage Examples

Basic Usage
<?php
// Hook into image_size_names_choose
add_filter('image_size_names_choose', 'my_custom_filter', 10, 1);

function my_custom_filter($attachment) {
    // Your custom filtering logic here
    return $attachment;
}

Source Code Context

wp-includes/media.php:4599 - How this hook is used in WordPress core
<?php
4594  
4595  	if ( $meta && ( 'image' === $type || ! empty( $meta['sizes'] ) ) ) {
4596  		$sizes = array();
4597  
4598  		/** This filter is documented in wp-admin/includes/media.php */
4599  		$possible_sizes = apply_filters(
4600  			'image_size_names_choose',
4601  			array(
4602  				'thumbnail' => __( 'Thumbnail' ),
4603  				'medium'    => __( 'Medium' ),
4604  				'large'     => __( 'Large' ),

PHP Documentation

<?php
/**
 * Prepares an attachment post object for JS, where it is expected
 * to be JSON-encoded and fit into an Attachment model.
 *
 * @since 3.5.0
 *
 * @param int|WP_Post $attachment Attachment ID or object.
 * @return array|void {
 *     Array of attachment details, or void if the parameter does not correspond to an attachment.
 *
 *     @type string $alt                   Alt text of the attachment.
 *     @type string $author                ID of the attachment author, as a string.
 *     @type string $authorName            Name of the attachment author.
 *     @type string $caption               Caption for the attachment.
 *     @type array  $compat                Containing item and meta.
 *     @type string $context               Context, whether it's used as the site icon for example.
 *     @type int    $date                  Uploaded date, timestamp in milliseconds.
 *     @type string $dateFormatted         Formatted date (e.g. June 29, 2018).
 *     @type string $description           Description of the attachment.
 *     @type string $editLink              URL to the edit page for the attachment.
 *     @type string $filename              File name of the attachment.
 *     @type string $filesizeHumanReadable Filesize of the attachment in human readable format (e.g. 1 MB).
 *     @type int    $filesizeInBytes       Filesize of the attachment in bytes.
 *     @type int    $height                If the attachment is an image, represents the height of the image in pixels.
 *     @type string $icon                  Icon URL of the attachment (e.g. /wp-includes/images/media/archive.png).
 *     @type int    $id                    ID of the attachment.
 *     @type string $link                  URL to the attachment.
 *     @type int    $menuOrder             Menu order of the attachment post.
 *     @type array  $meta                  Meta data for the attachment.
 *     @type string $mime                  Mime type of the attachment (e.g. image/jpeg or application/zip).
 *     @type int    $modified              Last modified, timestamp in milliseconds.
 *     @type string $name                  Name, same as title of the attachment.
 *     @type array  $nonces                Nonces for update, delete and edit.
 *     @type string $orientation           If the attachment is an image, represents the image orientation
 *                                         (landscape or portrait).
 *     @type array  $sizes                 If the attachment is an image, contains an array of arrays
 *                                         for the images sizes: thumbnail, medium, large, and full.
 *     @type string $status                Post status of the attachment (usually 'inherit').
 *     @type string $subtype               Mime subtype of the attachment (usually the last part, e.g. jpeg or zip).
 *     @type string $title                 Title of the attachment (usually slugified file name without the extension).
 *     @type string $type                  Type of the attachment (usually first part of the mime type, e.g. image).
 *     @type int    $uploadedTo            Parent post to which the attachment was uploaded.
 *     @type string $uploadedToLink        URL to the edit page of the parent post of the attachment.
 *     @type string $uploadedToTitle       Post title of the parent of the attachment.
 *     @type string $url                   Direct URL to the attachment file (from wp-content).
 *     @type int    $width                 If the attachment is an image, represents the width of the image in pixels.
 * }
 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.