Make WordPress Core

Changeset 53228


Ignore:
Timestamp:
04/20/2022 08:11:34 AM (3 years ago)
Author:
audrasjb
Message:

Media: Remove attachment_fields_to_save filter and deprecate image_attachment_fields_to_save().

This filter prevented removing attachment titles. This changeset removes the filter and deprecates the related function since it is no longer used.

Props dromero20, desrosj, Junaidkbr, francina, antpb, audrasjb, aadilali, etaproducto, azouamauriac, Boniu91, SergeyBiryukov.
Fixes #39108.

Location:
trunk/src/wp-admin/includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/admin-filters.php

    r51266 r53228  
    3131add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
    3232add_filter( 'async_upload_file', 'get_media_item', 10, 2 );
    33 
    34 add_filter( 'attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2 );
    3533
    3634add_filter( 'media_upload_gallery', 'media_upload_gallery' );
  • trunk/src/wp-admin/includes/deprecated.php

    r53216 r53228  
    15681568    _deprecated_function( __FUNCTION__, '5.3.0' );
    15691569}
     1570
     1571/**
     1572 * Was used to filter input from media_upload_form_handler() and to assign a default
     1573 * post_title from the file name if none supplied.
     1574 *
     1575 * @since 2.5.0
     1576 * @deprecated 6.0.0
     1577 *
     1578 * @param array $post       The WP_Post attachment object converted to an array.
     1579 * @param array $attachment An array of attachment metadata.
     1580 * @return array Attachment post object converted to an array.
     1581 */
     1582function image_attachment_fields_to_save( $post, $attachment ) {
     1583    _deprecated_function( __FUNCTION__, '6.0.0' );
     1584
     1585    return $post;
     1586}
  • trunk/src/wp-admin/includes/media.php

    r53192 r53228  
    13201320    unset( $form_fields['image_url'] );
    13211321    return $form_fields;
    1322 }
    1323 
    1324 /**
    1325  * Filters input from media_upload_form_handler() and assigns a default
    1326  * post_title from the file name if none supplied.
    1327  *
    1328  * Illustrates the use of the {@see 'attachment_fields_to_save'} filter
    1329  * which can be used to add default values to any field before saving to DB.
    1330  *
    1331  * @since 2.5.0
    1332  *
    1333  * @param array $post       The WP_Post attachment object converted to an array.
    1334  * @param array $attachment An array of attachment metadata.
    1335  * @return array Filtered attachment post object.
    1336  */
    1337 function image_attachment_fields_to_save( $post, $attachment ) {
    1338     if ( 'image' === substr( $post['post_mime_type'], 0, 5 ) ) {
    1339         if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
    1340             $attachment_url                           = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
    1341             $post['post_title']                       = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
    1342             $post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
    1343         }
    1344     }
    1345 
    1346     return $post;
    13471322}
    13481323
Note: See TracChangeset for help on using the changeset viewer.