~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-hook.php

  • Committer: Barry Price
  • Date: 2019-02-22 03:51:26 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: barry.price@canonical.com-20190222035126-o28k38qs8jfyjsxt
Merge WP5.1 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
         * @param int      $accepted_args   The number of arguments the function accepts.
72
72
         */
73
73
        public function add_filter( $tag, $function_to_add, $priority, $accepted_args ) {
74
 
                $idx = _wp_filter_build_unique_id( $tag, $function_to_add, $priority );
 
74
                $idx              = _wp_filter_build_unique_id( $tag, $function_to_add, $priority );
75
75
                $priority_existed = isset( $this->callbacks[ $priority ] );
76
76
 
77
77
                $this->callbacks[ $priority ][ $idx ] = array(
78
 
                        'function' => $function_to_add,
79
 
                        'accepted_args' => $accepted_args
 
78
                        'function'      => $function_to_add,
 
79
                        'accepted_args' => $accepted_args,
80
80
                );
81
81
 
82
82
                // if we're adding a new priority to the list, put them back in sorted order
243
243
 
244
244
                if ( false === $priority ) {
245
245
                        $this->callbacks = array();
246
 
                } else if ( isset( $this->callbacks[ $priority ] ) ) {
 
246
                } elseif ( isset( $this->callbacks[ $priority ] ) ) {
247
247
                        unset( $this->callbacks[ $priority ] );
248
248
                }
249
249
 
269
269
                $nesting_level = $this->nesting_level++;
270
270
 
271
271
                $this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
272
 
                $num_args = count( $args );
 
272
                $num_args                           = count( $args );
273
273
 
274
274
                do {
275
275
                        $this->current_priority[ $nesting_level ] = $priority = current( $this->iterations[ $nesting_level ] );
276
276
 
277
277
                        foreach ( $this->callbacks[ $priority ] as $the_ ) {
278
 
                                if( ! $this->doing_action ) {
279
 
                                        $args[ 0 ] = $value;
 
278
                                if ( ! $this->doing_action ) {
 
279
                                        $args[0] = $value;
280
280
                                }
281
281
 
282
282
                                // Avoid the array_slice if possible.
285
285
                                } elseif ( $the_['accepted_args'] >= $num_args ) {
286
286
                                        $value = call_user_func_array( $the_['function'], $args );
287
287
                                } else {
288
 
                                        $value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int)$the_['accepted_args'] ) );
 
288
                                        $value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int) $the_['accepted_args'] ) );
289
289
                                }
290
290
                        }
291
291
                } while ( false !== next( $this->iterations[ $nesting_level ] ) );
323
323
         * @param array $args Arguments to pass to the hook callbacks. Passed by reference.
324
324
         */
325
325
        public function do_all_hook( &$args ) {
326
 
                $nesting_level = $this->nesting_level++;
 
326
                $nesting_level                      = $this->nesting_level++;
327
327
                $this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
328
328
 
329
329
                do {
356
356
         * Normalizes filters set up before WordPress has initialized to WP_Hook objects.
357
357
         *
358
358
         * @since 4.7.0
359
 
         * @static
360
359
         *
361
360
         * @param array $filters Filters to normalize.
362
361
         * @return WP_Hook[] Array of normalized filters.