WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months ago

#49002 closed enhancement (duplicate)

class-wp-hooks.php -> function apply_filters() -> Add source code: Check if callable function or method exists.

Reported by: sjoerdlinders Owned by:
Milestone: Priority: normal
Severity: trivial Version: 5.3.1
Component: Plugins Keywords: has-patch
Focuses: Cc:

Description

<?php

        public function apply_filters( $value, $args ) {
                if ( ! $this->callbacks ) {
                        return $value;
                }

                $nesting_level = $this->nesting_level++;

                $this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
                $num_args = php5_count( $args );

                do {
                        $this->current_priority[ $nesting_level ] = $priority = current( $this->iterations[ $nesting_level ] );

                        foreach ( $this->callbacks[ $priority ] as $the_ ) {
                                if( ! $this->doing_action ) {
                                        $args[ 0 ] = $value;
                                }

<Add:line1>                     // Check if callable function or method exists.
<Add:line2>                     if ( !is_callable( $the_['function'] ) ) continue;

                                // Avoid the array_slice if possible.
                                if ( $the_['accepted_args'] == 0 ) {
                                        $value = call_user_func_array( $the_['function'], array() );
                                } elseif ( $the_['accepted_args'] >= $num_args ) {
                                        $value = call_user_func_array( $the_['function'], $args );
                                } else {
                                        $value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int)$the_['accepted_args'] ) );
                                }
                        }
                } while ( false !== next( $this->iterations[ $nesting_level ] ) );

                unset( $this->iterations[ $nesting_level ] );
                unset( $this->current_priority[ $nesting_level ] );

                $this->nesting_level--;

                return $value;
        }


Change History (1)

#1 @SergeyBiryukov
2 months ago

  • Component changed from Site Health to Plugins
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the ticket, we're already tracking this enhancement in #38116.

Note: See TracTickets for help on using tickets.