Making WordPress.org

Changeset 13174


Ignore:
Timestamp:
02/05/2024 10:07:26 PM (3 years ago)
Author:
coffee2code
Message:

Photo Directory, Uploads: Avoid use of an anonymous function as a callback.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/uploads.php

    r12809 r13174  
    296296                if ( is_page( self::SUBMIT_PAGE_SLUG ) && ! empty( $_GET['errors']['fu-disallowed-mime-type'] ) ) {
    297297                        // Hook as reasonably late as possible.
    298                         add_filter( 'the_content', function ( $content ) {
    299                                 add_filter( 'gettext', [ __CLASS__, 'overwrite_fu_strings' ], 10, 3 );
    300                                 return $content;
    301                         } );
     298                        add_filter( 'the_content', [ __CLASS__, '_overwrite_fu_strings' ] );
    302299
    303300                        // Unhook as early as possible.
    304301                        add_action( 'fu_additional_html', function () { remove_filter( 'gettext', [ __CLASS__, 'overwrite_fu_strings' ] ); } );
    305302                }
     303        }
     304
     305        /**
     306         * Hooks `overwrite_fu_strings()` to the 'gettext' filter.
     307         *
     308         * Note: This should only be used as a callback as late as possible and after checking that
     309         * context indicates a string rewrite is likely.
     310         *
     311         * @param string $content The content.
     312         * @return string The content, unchanged.
     313         */
     314        public static function _overwrite_fu_strings( $content ) {
     315                add_filter( 'gettext', [ __CLASS__, 'overwrite_fu_strings' ], 10, 3 );
     316                return $content;
    306317        }
    307318
Note: See TracChangeset for help on using the changeset viewer.