Make WordPress Core

Changeset 2184


Ignore:
Timestamp:
02/01/2005 06:20:54 AM (20 years ago)
Author:
rboren
Message:

Allow multiple args to be passed to apply_filters and do_action. Move some code into merge_filters. Use call_user_func_array so that args can be passed by reference. Provide a default for the second arg to do_action so that we do not have to put empty strings in the do_action calls. Bug 768. Hat tip: morganiq

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r2183 r2184  
    219219    } elseif ( !isset($wp_template_redirect) ) {
    220220        $wp_template_redirect = true;
    221         do_action('template_redirect', '');
     221        do_action('template_redirect');
    222222        if ( is_feed() ) {
    223223            include(ABSPATH . '/wp-feed.php');
  • trunk/wp-content/themes/classic/footer.php

    r2040 r2184  
    88</div>
    99
    10 <?php do_action('wp_footer', ''); ?>
     10<?php do_action('wp_footer'); ?>
    1111</body>
    1212</html>
  • trunk/wp-content/themes/default/footer.php

    r2089 r2184  
    1515<?php /* "Just what do you think you're doing Dave?" */ ?>
    1616
    17 <?php do_action('wp_footer', ''); ?>
     17        <?php do_action('wp_footer'); ?>
    1818
    1919</body>
  • trunk/wp-includes/classes.php

    r2179 r2184  
    11401140        $this->rules = $page_rewrite + $root_rewrite + $comments_rewrite + $search_rewrite + $category_rewrite + $author_rewrite + $date_rewrite + $post_rewrite;
    11411141
    1142         do_action('generate_rewrite_rules', '');
     1142        do_action('generate_rewrite_rules', array(&$this));
    11431143        $this->rules = apply_filters('rewrite_rules_array', $this->rules);
    11441144        return $this->rules;
  • trunk/wp-includes/functions-post.php

    r2166 r2184  
    385385    global $wpdb;
    386386
    387     do_action('wp_blacklist_check', '');
     387    do_action('wp_blacklist_check');
    388388
    389389    if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) {
     
    450450        $time_newcomment  = mysql2date('U', $now_gmt);
    451451        if ( ($time_newcomment - $time_lastcomment) < 15 ) {
    452             do_action('comment_flood_trigger', '');
     452            do_action('comment_flood_trigger');
    453453            die( __('Sorry, you can only post a new comment once every 15 seconds. Slow down cowboy.') );
    454454        }
  • trunk/wp-includes/functions.php

    r2183 r2184  
    871871// Filters: these are the core of WP's plugin architecture
    872872
    873 function apply_filters($tag, $string, $filter = true) {
     873function merge_filters($tag) {
    874874    global $wp_filter;
    875875    if (isset($wp_filter['all'])) {
     
    884884    }
    885885
     886    if (isset($wp_filter[$tag]))
     887        ksort($wp_filter[$tag]);
     888}
     889
     890function apply_filters($tag, $string) {
     891    global $wp_filter;
     892   
     893    $args = array($string) + array_slice(func_get_args(), 3);
     894   
     895    merge_filters($tag);
     896   
    886897    if (isset($wp_filter[$tag])) {
    887         ksort($wp_filter[$tag]);
    888898        foreach ($wp_filter[$tag] as $priority => $functions) {
    889899            if (!is_null($functions)) {
    890900                foreach($functions as $function) {
    891                     if ($filter)
    892                         $string = call_user_func($function, $string);
    893                     else
    894                         call_user_func($function, $string);
     901                    $string = call_user_func_array($function, $args);
    895902                }
    896903            }
     
    925932// The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content
    926933
    927 function do_action($tag, $string) {
    928     apply_filters($tag, $string, false);
    929     return $string;
     934function do_action($tag, $arg = '') {
     935    global $wp_filter;
     936
     937    if ( is_array($arg) )
     938        $args = $arg + array_slice(func_get_args(), 2);
     939    else
     940        $args = array($action) + array_slice(func_get_args(), 2);
     941   
     942    merge_filters($tag);
     943   
     944    if (isset($wp_filter[$tag])) {
     945        foreach ($wp_filter[$tag] as $priority => $functions) {
     946            if (!is_null($functions)) {
     947                foreach($functions as $function) {
     948                    $string = call_user_func_array($function, $args);
     949                }
     950            }
     951        }
     952    }
    930953}
    931954
     
    10651088
    10661089function wp_head() {
    1067     do_action('wp_head', '');
     1090    do_action('wp_head');
    10681091}
    10691092
  • trunk/wp-includes/template-functions-general.php

    r2142 r2184  
    5555
    5656function wp_meta() {
    57     do_action('wp_meta', 1);
     57    do_action('wp_meta');
    5858}
    5959
  • trunk/wp-settings.php

    r2171 r2184  
    121121
    122122function shutdown_action_hook() {
    123     do_action('shutdown', '');
     123    do_action('shutdown');
    124124}
    125125register_shutdown_function('shutdown_action_hook');
    126126
    127127// Everything is loaded.
    128 do_action('init', '');
     128do_action('init');
    129129?>
Note: See TracChangeset for help on using the changeset viewer.