Edit File by line
/home/barbar84/www/wp-inclu...
File: media.php
*
[3500] Fix | Delete
* @param int|array|object $attachment Attachment ID, data array, or data object.
[3501] Fix | Delete
* @param string $output Output type. 'names' to return an array of taxonomy names,
[3502] Fix | Delete
* or 'objects' to return an array of taxonomy objects.
[3503] Fix | Delete
* Default is 'names'.
[3504] Fix | Delete
* @return string[]|WP_Taxonomy[] List of taxonomies or taxonomy names. Empty array on failure.
[3505] Fix | Delete
*/
[3506] Fix | Delete
function get_attachment_taxonomies( $attachment, $output = 'names' ) {
[3507] Fix | Delete
if ( is_int( $attachment ) ) {
[3508] Fix | Delete
$attachment = get_post( $attachment );
[3509] Fix | Delete
} elseif ( is_array( $attachment ) ) {
[3510] Fix | Delete
$attachment = (object) $attachment;
[3511] Fix | Delete
}
[3512] Fix | Delete
[3513] Fix | Delete
if ( ! is_object( $attachment ) ) {
[3514] Fix | Delete
return array();
[3515] Fix | Delete
}
[3516] Fix | Delete
[3517] Fix | Delete
$file = get_attached_file( $attachment->ID );
[3518] Fix | Delete
$filename = wp_basename( $file );
[3519] Fix | Delete
[3520] Fix | Delete
$objects = array( 'attachment' );
[3521] Fix | Delete
[3522] Fix | Delete
if ( false !== strpos( $filename, '.' ) ) {
[3523] Fix | Delete
$objects[] = 'attachment:' . substr( $filename, strrpos( $filename, '.' ) + 1 );
[3524] Fix | Delete
}
[3525] Fix | Delete
[3526] Fix | Delete
if ( ! empty( $attachment->post_mime_type ) ) {
[3527] Fix | Delete
$objects[] = 'attachment:' . $attachment->post_mime_type;
[3528] Fix | Delete
[3529] Fix | Delete
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
[3530] Fix | Delete
foreach ( explode( '/', $attachment->post_mime_type ) as $token ) {
[3531] Fix | Delete
if ( ! empty( $token ) ) {
[3532] Fix | Delete
$objects[] = "attachment:$token";
[3533] Fix | Delete
}
[3534] Fix | Delete
}
[3535] Fix | Delete
}
[3536] Fix | Delete
}
[3537] Fix | Delete
[3538] Fix | Delete
$taxonomies = array();
[3539] Fix | Delete
[3540] Fix | Delete
foreach ( $objects as $object ) {
[3541] Fix | Delete
$taxes = get_object_taxonomies( $object, $output );
[3542] Fix | Delete
[3543] Fix | Delete
if ( $taxes ) {
[3544] Fix | Delete
$taxonomies = array_merge( $taxonomies, $taxes );
[3545] Fix | Delete
}
[3546] Fix | Delete
}
[3547] Fix | Delete
[3548] Fix | Delete
if ( 'names' === $output ) {
[3549] Fix | Delete
$taxonomies = array_unique( $taxonomies );
[3550] Fix | Delete
}
[3551] Fix | Delete
[3552] Fix | Delete
return $taxonomies;
[3553] Fix | Delete
}
[3554] Fix | Delete
[3555] Fix | Delete
/**
[3556] Fix | Delete
* Retrieves all of the taxonomies that are registered for attachments.
[3557] Fix | Delete
*
[3558] Fix | Delete
* Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
[3559] Fix | Delete
*
[3560] Fix | Delete
* @since 3.5.0
[3561] Fix | Delete
*
[3562] Fix | Delete
* @see get_taxonomies()
[3563] Fix | Delete
*
[3564] Fix | Delete
* @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
[3565] Fix | Delete
* Default 'names'.
[3566] Fix | Delete
* @return string[]|WP_Taxonomy[] Array of names or objects of registered taxonomies for attachments.
[3567] Fix | Delete
*/
[3568] Fix | Delete
function get_taxonomies_for_attachments( $output = 'names' ) {
[3569] Fix | Delete
$taxonomies = array();
[3570] Fix | Delete
[3571] Fix | Delete
foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
[3572] Fix | Delete
foreach ( $taxonomy->object_type as $object_type ) {
[3573] Fix | Delete
if ( 'attachment' === $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
[3574] Fix | Delete
if ( 'names' === $output ) {
[3575] Fix | Delete
$taxonomies[] = $taxonomy->name;
[3576] Fix | Delete
} else {
[3577] Fix | Delete
$taxonomies[ $taxonomy->name ] = $taxonomy;
[3578] Fix | Delete
}
[3579] Fix | Delete
break;
[3580] Fix | Delete
}
[3581] Fix | Delete
}
[3582] Fix | Delete
}
[3583] Fix | Delete
[3584] Fix | Delete
return $taxonomies;
[3585] Fix | Delete
}
[3586] Fix | Delete
[3587] Fix | Delete
/**
[3588] Fix | Delete
* Determines whether the value is an acceptable type for GD image functions.
[3589] Fix | Delete
*
[3590] Fix | Delete
* In PHP 8.0, the GD extension uses GdImage objects for its data structures.
[3591] Fix | Delete
* This function checks if the passed value is either a resource of type `gd`
[3592] Fix | Delete
* or a GdImage object instance. Any other type will return false.
[3593] Fix | Delete
*
[3594] Fix | Delete
* @since 5.6.0
[3595] Fix | Delete
*
[3596] Fix | Delete
* @param resource|GdImage|false $image A value to check the type for.
[3597] Fix | Delete
* @return bool True if $image is either a GD image resource or GdImage instance,
[3598] Fix | Delete
* false otherwise.
[3599] Fix | Delete
*/
[3600] Fix | Delete
function is_gd_image( $image ) {
[3601] Fix | Delete
if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
[3602] Fix | Delete
|| is_object( $image ) && $image instanceof GdImage
[3603] Fix | Delete
) {
[3604] Fix | Delete
return true;
[3605] Fix | Delete
}
[3606] Fix | Delete
[3607] Fix | Delete
return false;
[3608] Fix | Delete
}
[3609] Fix | Delete
[3610] Fix | Delete
/**
[3611] Fix | Delete
* Create new GD image resource with transparency support
[3612] Fix | Delete
*
[3613] Fix | Delete
* @todo Deprecate if possible.
[3614] Fix | Delete
*
[3615] Fix | Delete
* @since 2.9.0
[3616] Fix | Delete
*
[3617] Fix | Delete
* @param int $width Image width in pixels.
[3618] Fix | Delete
* @param int $height Image height in pixels.
[3619] Fix | Delete
* @return resource|GdImage|false The GD image resource or GdImage instance on success.
[3620] Fix | Delete
* False on failure.
[3621] Fix | Delete
*/
[3622] Fix | Delete
function wp_imagecreatetruecolor( $width, $height ) {
[3623] Fix | Delete
$img = imagecreatetruecolor( $width, $height );
[3624] Fix | Delete
[3625] Fix | Delete
if ( is_gd_image( $img )
[3626] Fix | Delete
&& function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
[3627] Fix | Delete
) {
[3628] Fix | Delete
imagealphablending( $img, false );
[3629] Fix | Delete
imagesavealpha( $img, true );
[3630] Fix | Delete
}
[3631] Fix | Delete
[3632] Fix | Delete
return $img;
[3633] Fix | Delete
}
[3634] Fix | Delete
[3635] Fix | Delete
/**
[3636] Fix | Delete
* Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.
[3637] Fix | Delete
*
[3638] Fix | Delete
* @since 2.9.0
[3639] Fix | Delete
*
[3640] Fix | Delete
* @see wp_constrain_dimensions()
[3641] Fix | Delete
*
[3642] Fix | Delete
* @param int $example_width The width of an example embed.
[3643] Fix | Delete
* @param int $example_height The height of an example embed.
[3644] Fix | Delete
* @param int $max_width The maximum allowed width.
[3645] Fix | Delete
* @param int $max_height The maximum allowed height.
[3646] Fix | Delete
* @return int[] {
[3647] Fix | Delete
* An array of maximum width and height values.
[3648] Fix | Delete
*
[3649] Fix | Delete
* @type int $0 The maximum width in pixels.
[3650] Fix | Delete
* @type int $1 The maximum height in pixels.
[3651] Fix | Delete
* }
[3652] Fix | Delete
*/
[3653] Fix | Delete
function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
[3654] Fix | Delete
$example_width = (int) $example_width;
[3655] Fix | Delete
$example_height = (int) $example_height;
[3656] Fix | Delete
$max_width = (int) $max_width;
[3657] Fix | Delete
$max_height = (int) $max_height;
[3658] Fix | Delete
[3659] Fix | Delete
return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
[3660] Fix | Delete
}
[3661] Fix | Delete
[3662] Fix | Delete
/**
[3663] Fix | Delete
* Determines the maximum upload size allowed in php.ini.
[3664] Fix | Delete
*
[3665] Fix | Delete
* @since 2.5.0
[3666] Fix | Delete
*
[3667] Fix | Delete
* @return int Allowed upload size.
[3668] Fix | Delete
*/
[3669] Fix | Delete
function wp_max_upload_size() {
[3670] Fix | Delete
$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
[3671] Fix | Delete
$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
[3672] Fix | Delete
[3673] Fix | Delete
/**
[3674] Fix | Delete
* Filters the maximum upload size allowed in php.ini.
[3675] Fix | Delete
*
[3676] Fix | Delete
* @since 2.5.0
[3677] Fix | Delete
*
[3678] Fix | Delete
* @param int $size Max upload size limit in bytes.
[3679] Fix | Delete
* @param int $u_bytes Maximum upload filesize in bytes.
[3680] Fix | Delete
* @param int $p_bytes Maximum size of POST data in bytes.
[3681] Fix | Delete
*/
[3682] Fix | Delete
return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
[3683] Fix | Delete
}
[3684] Fix | Delete
[3685] Fix | Delete
/**
[3686] Fix | Delete
* Returns a WP_Image_Editor instance and loads file into it.
[3687] Fix | Delete
*
[3688] Fix | Delete
* @since 3.5.0
[3689] Fix | Delete
*
[3690] Fix | Delete
* @param string $path Path to the file to load.
[3691] Fix | Delete
* @param array $args Optional. Additional arguments for retrieving the image editor.
[3692] Fix | Delete
* Default empty array.
[3693] Fix | Delete
* @return WP_Image_Editor|WP_Error The WP_Image_Editor object on success,
[3694] Fix | Delete
* a WP_Error object otherwise.
[3695] Fix | Delete
*/
[3696] Fix | Delete
function wp_get_image_editor( $path, $args = array() ) {
[3697] Fix | Delete
$args['path'] = $path;
[3698] Fix | Delete
[3699] Fix | Delete
if ( ! isset( $args['mime_type'] ) ) {
[3700] Fix | Delete
$file_info = wp_check_filetype( $args['path'] );
[3701] Fix | Delete
[3702] Fix | Delete
// If $file_info['type'] is false, then we let the editor attempt to
[3703] Fix | Delete
// figure out the file type, rather than forcing a failure based on extension.
[3704] Fix | Delete
if ( isset( $file_info ) && $file_info['type'] ) {
[3705] Fix | Delete
$args['mime_type'] = $file_info['type'];
[3706] Fix | Delete
}
[3707] Fix | Delete
}
[3708] Fix | Delete
[3709] Fix | Delete
$implementation = _wp_image_editor_choose( $args );
[3710] Fix | Delete
[3711] Fix | Delete
if ( $implementation ) {
[3712] Fix | Delete
$editor = new $implementation( $path );
[3713] Fix | Delete
$loaded = $editor->load();
[3714] Fix | Delete
[3715] Fix | Delete
if ( is_wp_error( $loaded ) ) {
[3716] Fix | Delete
return $loaded;
[3717] Fix | Delete
}
[3718] Fix | Delete
[3719] Fix | Delete
return $editor;
[3720] Fix | Delete
}
[3721] Fix | Delete
[3722] Fix | Delete
return new WP_Error( 'image_no_editor', __( 'No editor could be selected.' ) );
[3723] Fix | Delete
}
[3724] Fix | Delete
[3725] Fix | Delete
/**
[3726] Fix | Delete
* Tests whether there is an editor that supports a given mime type or methods.
[3727] Fix | Delete
*
[3728] Fix | Delete
* @since 3.5.0
[3729] Fix | Delete
*
[3730] Fix | Delete
* @param string|array $args Optional. Array of arguments to retrieve the image editor supports.
[3731] Fix | Delete
* Default empty array.
[3732] Fix | Delete
* @return bool True if an eligible editor is found; false otherwise.
[3733] Fix | Delete
*/
[3734] Fix | Delete
function wp_image_editor_supports( $args = array() ) {
[3735] Fix | Delete
return (bool) _wp_image_editor_choose( $args );
[3736] Fix | Delete
}
[3737] Fix | Delete
[3738] Fix | Delete
/**
[3739] Fix | Delete
* Tests which editors are capable of supporting the request.
[3740] Fix | Delete
*
[3741] Fix | Delete
* @ignore
[3742] Fix | Delete
* @since 3.5.0
[3743] Fix | Delete
*
[3744] Fix | Delete
* @param array $args Optional. Array of arguments for choosing a capable editor. Default empty array.
[3745] Fix | Delete
* @return string|false Class name for the first editor that claims to support the request.
[3746] Fix | Delete
* False if no editor claims to support the request.
[3747] Fix | Delete
*/
[3748] Fix | Delete
function _wp_image_editor_choose( $args = array() ) {
[3749] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
[3750] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
[3751] Fix | Delete
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
[3752] Fix | Delete
/**
[3753] Fix | Delete
* Filters the list of image editing library classes.
[3754] Fix | Delete
*
[3755] Fix | Delete
* @since 3.5.0
[3756] Fix | Delete
*
[3757] Fix | Delete
* @param string[] $image_editors Array of available image editor class names. Defaults are
[3758] Fix | Delete
* 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD'.
[3759] Fix | Delete
*/
[3760] Fix | Delete
$implementations = apply_filters( 'wp_image_editors', array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
[3761] Fix | Delete
[3762] Fix | Delete
foreach ( $implementations as $implementation ) {
[3763] Fix | Delete
if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) {
[3764] Fix | Delete
continue;
[3765] Fix | Delete
}
[3766] Fix | Delete
[3767] Fix | Delete
if ( isset( $args['mime_type'] ) &&
[3768] Fix | Delete
! call_user_func(
[3769] Fix | Delete
array( $implementation, 'supports_mime_type' ),
[3770] Fix | Delete
$args['mime_type']
[3771] Fix | Delete
) ) {
[3772] Fix | Delete
continue;
[3773] Fix | Delete
}
[3774] Fix | Delete
[3775] Fix | Delete
if ( isset( $args['methods'] ) &&
[3776] Fix | Delete
array_diff( $args['methods'], get_class_methods( $implementation ) ) ) {
[3777] Fix | Delete
[3778] Fix | Delete
continue;
[3779] Fix | Delete
}
[3780] Fix | Delete
[3781] Fix | Delete
return $implementation;
[3782] Fix | Delete
}
[3783] Fix | Delete
[3784] Fix | Delete
return false;
[3785] Fix | Delete
}
[3786] Fix | Delete
[3787] Fix | Delete
/**
[3788] Fix | Delete
* Prints default Plupload arguments.
[3789] Fix | Delete
*
[3790] Fix | Delete
* @since 3.4.0
[3791] Fix | Delete
*/
[3792] Fix | Delete
function wp_plupload_default_settings() {
[3793] Fix | Delete
$wp_scripts = wp_scripts();
[3794] Fix | Delete
[3795] Fix | Delete
$data = $wp_scripts->get_data( 'wp-plupload', 'data' );
[3796] Fix | Delete
if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) {
[3797] Fix | Delete
return;
[3798] Fix | Delete
}
[3799] Fix | Delete
[3800] Fix | Delete
$max_upload_size = wp_max_upload_size();
[3801] Fix | Delete
$allowed_extensions = array_keys( get_allowed_mime_types() );
[3802] Fix | Delete
$extensions = array();
[3803] Fix | Delete
foreach ( $allowed_extensions as $extension ) {
[3804] Fix | Delete
$extensions = array_merge( $extensions, explode( '|', $extension ) );
[3805] Fix | Delete
}
[3806] Fix | Delete
[3807] Fix | Delete
/*
[3808] Fix | Delete
* Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
[3809] Fix | Delete
* and the `flash_swf_url` and `silverlight_xap_url` are not used.
[3810] Fix | Delete
*/
[3811] Fix | Delete
$defaults = array(
[3812] Fix | Delete
'file_data_name' => 'async-upload', // Key passed to $_FILE.
[3813] Fix | Delete
'url' => admin_url( 'async-upload.php', 'relative' ),
[3814] Fix | Delete
'filters' => array(
[3815] Fix | Delete
'max_file_size' => $max_upload_size . 'b',
[3816] Fix | Delete
'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ),
[3817] Fix | Delete
),
[3818] Fix | Delete
);
[3819] Fix | Delete
[3820] Fix | Delete
/*
[3821] Fix | Delete
* Currently only iOS Safari supports multiple files uploading,
[3822] Fix | Delete
* but iOS 7.x has a bug that prevents uploading of videos when enabled.
[3823] Fix | Delete
* See #29602.
[3824] Fix | Delete
*/
[3825] Fix | Delete
if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
[3826] Fix | Delete
strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
[3827] Fix | Delete
[3828] Fix | Delete
$defaults['multi_selection'] = false;
[3829] Fix | Delete
}
[3830] Fix | Delete
[3831] Fix | Delete
/**
[3832] Fix | Delete
* Filters the Plupload default settings.
[3833] Fix | Delete
*
[3834] Fix | Delete
* @since 3.4.0
[3835] Fix | Delete
*
[3836] Fix | Delete
* @param array $defaults Default Plupload settings array.
[3837] Fix | Delete
*/
[3838] Fix | Delete
$defaults = apply_filters( 'plupload_default_settings', $defaults );
[3839] Fix | Delete
[3840] Fix | Delete
$params = array(
[3841] Fix | Delete
'action' => 'upload-attachment',
[3842] Fix | Delete
);
[3843] Fix | Delete
[3844] Fix | Delete
/**
[3845] Fix | Delete
* Filters the Plupload default parameters.
[3846] Fix | Delete
*
[3847] Fix | Delete
* @since 3.4.0
[3848] Fix | Delete
*
[3849] Fix | Delete
* @param array $params Default Plupload parameters array.
[3850] Fix | Delete
*/
[3851] Fix | Delete
$params = apply_filters( 'plupload_default_params', $params );
[3852] Fix | Delete
[3853] Fix | Delete
$params['_wpnonce'] = wp_create_nonce( 'media-form' );
[3854] Fix | Delete
[3855] Fix | Delete
$defaults['multipart_params'] = $params;
[3856] Fix | Delete
[3857] Fix | Delete
$settings = array(
[3858] Fix | Delete
'defaults' => $defaults,
[3859] Fix | Delete
'browser' => array(
[3860] Fix | Delete
'mobile' => wp_is_mobile(),
[3861] Fix | Delete
'supported' => _device_can_upload(),
[3862] Fix | Delete
),
[3863] Fix | Delete
'limitExceeded' => is_multisite() && ! is_upload_space_available(),
[3864] Fix | Delete
);
[3865] Fix | Delete
[3866] Fix | Delete
$script = 'var _wpPluploadSettings = ' . wp_json_encode( $settings ) . ';';
[3867] Fix | Delete
[3868] Fix | Delete
if ( $data ) {
[3869] Fix | Delete
$script = "$data\n$script";
[3870] Fix | Delete
}
[3871] Fix | Delete
[3872] Fix | Delete
$wp_scripts->add_data( 'wp-plupload', 'data', $script );
[3873] Fix | Delete
}
[3874] Fix | Delete
[3875] Fix | Delete
/**
[3876] Fix | Delete
* Prepares an attachment post object for JS, where it is expected
[3877] Fix | Delete
* to be JSON-encoded and fit into an Attachment model.
[3878] Fix | Delete
*
[3879] Fix | Delete
* @since 3.5.0
[3880] Fix | Delete
*
[3881] Fix | Delete
* @param int|WP_Post $attachment Attachment ID or object.
[3882] Fix | Delete
* @return array|void {
[3883] Fix | Delete
* Array of attachment details, or void if the parameter does not correspond to an attachment.
[3884] Fix | Delete
*
[3885] Fix | Delete
* @type string $alt Alt text of the attachment.
[3886] Fix | Delete
* @type string $author ID of the attachment author, as a string.
[3887] Fix | Delete
* @type string $authorName Name of the attachment author.
[3888] Fix | Delete
* @type string $caption Caption for the attachment.
[3889] Fix | Delete
* @type array $compat Containing item and meta.
[3890] Fix | Delete
* @type string $context Context, whether it's used as the site icon for example.
[3891] Fix | Delete
* @type int $date Uploaded date, timestamp in milliseconds.
[3892] Fix | Delete
* @type string $dateFormatted Formatted date (e.g. June 29, 2018).
[3893] Fix | Delete
* @type string $description Description of the attachment.
[3894] Fix | Delete
* @type string $editLink URL to the edit page for the attachment.
[3895] Fix | Delete
* @type string $filename File name of the attachment.
[3896] Fix | Delete
* @type string $filesizeHumanReadable Filesize of the attachment in human readable format (e.g. 1 MB).
[3897] Fix | Delete
* @type int $filesizeInBytes Filesize of the attachment in bytes.
[3898] Fix | Delete
* @type int $height If the attachment is an image, represents the height of the image in pixels.
[3899] Fix | Delete
* @type string $icon Icon URL of the attachment (e.g. /wp-includes/images/media/archive.png).
[3900] Fix | Delete
* @type int $id ID of the attachment.
[3901] Fix | Delete
* @type string $link URL to the attachment.
[3902] Fix | Delete
* @type int $menuOrder Menu order of the attachment post.
[3903] Fix | Delete
* @type array $meta Meta data for the attachment.
[3904] Fix | Delete
* @type string $mime Mime type of the attachment (e.g. image/jpeg or application/zip).
[3905] Fix | Delete
* @type int $modified Last modified, timestamp in milliseconds.
[3906] Fix | Delete
* @type string $name Name, same as title of the attachment.
[3907] Fix | Delete
* @type array $nonces Nonces for update, delete and edit.
[3908] Fix | Delete
* @type string $orientation If the attachment is an image, represents the image orientation
[3909] Fix | Delete
* (landscape or portrait).
[3910] Fix | Delete
* @type array $sizes If the attachment is an image, contains an array of arrays
[3911] Fix | Delete
* for the images sizes: thumbnail, medium, large, and full.
[3912] Fix | Delete
* @type string $status Post status of the attachment (usually 'inherit').
[3913] Fix | Delete
* @type string $subtype Mime subtype of the attachment (usually the last part, e.g. jpeg or zip).
[3914] Fix | Delete
* @type string $title Title of the attachment (usually slugified file name without the extension).
[3915] Fix | Delete
* @type string $type Type of the attachment (usually first part of the mime type, e.g. image).
[3916] Fix | Delete
* @type int $uploadedTo Parent post to which the attachment was uploaded.
[3917] Fix | Delete
* @type string $uploadedToLink URL to the edit page of the parent post of the attachment.
[3918] Fix | Delete
* @type string $uploadedToTitle Post title of the parent of the attachment.
[3919] Fix | Delete
* @type string $url Direct URL to the attachment file (from wp-content).
[3920] Fix | Delete
* @type int $width If the attachment is an image, represents the width of the image in pixels.
[3921] Fix | Delete
* }
[3922] Fix | Delete
*
[3923] Fix | Delete
*/
[3924] Fix | Delete
function wp_prepare_attachment_for_js( $attachment ) {
[3925] Fix | Delete
$attachment = get_post( $attachment );
[3926] Fix | Delete
[3927] Fix | Delete
if ( ! $attachment ) {
[3928] Fix | Delete
return;
[3929] Fix | Delete
}
[3930] Fix | Delete
[3931] Fix | Delete
if ( 'attachment' !== $attachment->post_type ) {
[3932] Fix | Delete
return;
[3933] Fix | Delete
}
[3934] Fix | Delete
[3935] Fix | Delete
$meta = wp_get_attachment_metadata( $attachment->ID );
[3936] Fix | Delete
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
[3937] Fix | Delete
list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
[3938] Fix | Delete
} else {
[3939] Fix | Delete
list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
[3940] Fix | Delete
}
[3941] Fix | Delete
[3942] Fix | Delete
$attachment_url = wp_get_attachment_url( $attachment->ID );
[3943] Fix | Delete
$base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
[3944] Fix | Delete
[3945] Fix | Delete
$response = array(
[3946] Fix | Delete
'id' => $attachment->ID,
[3947] Fix | Delete
'title' => $attachment->post_title,
[3948] Fix | Delete
'filename' => wp_basename( get_attached_file( $attachment->ID ) ),
[3949] Fix | Delete
'url' => $attachment_url,
[3950] Fix | Delete
'link' => get_attachment_link( $attachment->ID ),
[3951] Fix | Delete
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
[3952] Fix | Delete
'author' => $attachment->post_author,
[3953] Fix | Delete
'description' => $attachment->post_content,
[3954] Fix | Delete
'caption' => $attachment->post_excerpt,
[3955] Fix | Delete
'name' => $attachment->post_name,
[3956] Fix | Delete
'status' => $attachment->post_status,
[3957] Fix | Delete
'uploadedTo' => $attachment->post_parent,
[3958] Fix | Delete
'date' => strtotime( $attachment->post_date_gmt ) * 1000,
[3959] Fix | Delete
'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,
[3960] Fix | Delete
'menuOrder' => $attachment->menu_order,
[3961] Fix | Delete
'mime' => $attachment->post_mime_type,
[3962] Fix | Delete
'type' => $type,
[3963] Fix | Delete
'subtype' => $subtype,
[3964] Fix | Delete
'icon' => wp_mime_type_icon( $attachment->ID ),
[3965] Fix | Delete
'dateFormatted' => mysql2date( __( 'F j, Y' ), $attachment->post_date ),
[3966] Fix | Delete
'nonces' => array(
[3967] Fix | Delete
'update' => false,
[3968] Fix | Delete
'delete' => false,
[3969] Fix | Delete
'edit' => false,
[3970] Fix | Delete
),
[3971] Fix | Delete
'editLink' => false,
[3972] Fix | Delete
'meta' => false,
[3973] Fix | Delete
);
[3974] Fix | Delete
[3975] Fix | Delete
$author = new WP_User( $attachment->post_author );
[3976] Fix | Delete
[3977] Fix | Delete
if ( $author->exists() ) {
[3978] Fix | Delete
$author_name = $author->display_name ? $author->display_name : $author->nickname;
[3979] Fix | Delete
$response['authorName'] = html_entity_decode( $author_name, ENT_QUOTES, get_bloginfo( 'charset' ) );
[3980] Fix | Delete
$response['authorLink'] = get_edit_user_link( $author->ID );
[3981] Fix | Delete
} else {
[3982] Fix | Delete
$response['authorName'] = __( '(no author)' );
[3983] Fix | Delete
}
[3984] Fix | Delete
[3985] Fix | Delete
if ( $attachment->post_parent ) {
[3986] Fix | Delete
$post_parent = get_post( $attachment->post_parent );
[3987] Fix | Delete
if ( $post_parent ) {
[3988] Fix | Delete
$response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
[3989] Fix | Delete
$response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' );
[3990] Fix | Delete
}
[3991] Fix | Delete
}
[3992] Fix | Delete
[3993] Fix | Delete
$attached_file = get_attached_file( $attachment->ID );
[3994] Fix | Delete
[3995] Fix | Delete
if ( isset( $meta['filesize'] ) ) {
[3996] Fix | Delete
$bytes = $meta['filesize'];
[3997] Fix | Delete
} elseif ( file_exists( $attached_file ) ) {
[3998] Fix | Delete
$bytes = filesize( $attached_file );
[3999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function