Make WordPress Core

Ticket #14280: 14280.diff

File 14280.diff, 10.5 KB (added by sivel, 15 years ago)
  • wp-includes/default-filters.php

     
    1313 */
    1414
    1515// Strip, trim, kses, special chars for string saves
    16 foreach ( array( 'pre_term_name', 'pre_comment_author_name', 'pre_link_name', 'pre_link_target', 'pre_link_rel', 'pre_user_display_name', 'pre_user_first_name', 'pre_user_last_name', 'pre_user_nickname' ) as $filter ) {
    17         add_filter( $filter, 'sanitize_text_field'  );
    18         add_filter( $filter, 'wp_filter_kses'       );
    19         add_filter( $filter, '_wp_specialchars', 30 );
    20 }
     16$filters = array( 'pre_term_name', 'pre_comment_author_name', 'pre_link_name', 'pre_link_target', 'pre_link_rel', 'pre_user_display_name', 'pre_user_first_name', 'pre_user_last_name', 'pre_user_nickname' );
     17add_filter( $filters, 'sanitize_text_field'  );
     18add_filter( $filters, 'wp_filter_kses'       );
     19add_filter( $filters, '_wp_specialchars', 30 );
    2120
    2221// Strip, kses, special chars for string display
    23 foreach ( array( 'term_name', 'comment_author_name', 'link_name', 'link_target', 'link_rel', 'user_display_name', 'user_first_name', 'user_last_name', 'user_nickname' ) as $filter ) {
    24         add_filter( $filter, 'sanitize_text_field'  );
    25         add_filter( $filter, 'wp_kses_data'       );
    26         add_filter( $filter, '_wp_specialchars', 30 );
    27 }
     22$filters = array( 'term_name', 'comment_author_name', 'link_name', 'link_target', 'link_rel', 'user_display_name', 'user_first_name', 'user_last_name', 'user_nickname' );
     23add_filter( $filters, 'sanitize_text_field'  );
     24add_filter( $filters, 'wp_kses_data'       );
     25add_filter( $filters, '_wp_specialchars', 30 );
    2826
    2927// Kses only for textarea saves
    30 foreach ( array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' ) as $filter ) {
    31         add_filter( $filter, 'wp_filter_kses' );
    32 }
     28$filters = array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' );
     29add_filter( $filters, 'wp_filter_kses' );
    3330
    3431// Kses only for textarea saves displays
    35 foreach ( array( 'term_description', 'link_description', 'link_notes', 'user_description' ) as $filter ) {
    36         add_filter( $filter, 'wp_kses_data' );
    37 }
     32$filters = array( 'term_description', 'link_description', 'link_notes', 'user_description' );
     33add_filter( $filters, 'wp_kses_data' );
    3834
    3935// Email saves
    40 foreach ( array( 'pre_comment_author_email', 'pre_user_email' ) as $filter ) {
    41         add_filter( $filter, 'trim'           );
    42         add_filter( $filter, 'sanitize_email' );
    43         add_filter( $filter, 'wp_filter_kses' );
    44 }
     36$filters = array( 'pre_comment_author_email', 'pre_user_email' );
     37add_filter( $filters, 'trim'           );
     38add_filter( $filters, 'sanitize_email' );
     39add_filter( $filters, 'wp_filter_kses' );
    4540
    4641// Email display
    47 foreach ( array( 'comment_author_email', 'user_email' ) as $filter ) {
    48         add_filter( $filter, 'sanitize_email' );
    49         add_filter( $filter, 'wp_kses_data' );
    50 }
     42$filters = array( 'comment_author_email', 'user_email' );
     43add_filter( $filters, 'sanitize_email' );
     44add_filter( $filters, 'wp_kses_data' );
    5145
    5246// Save URL
    53 foreach ( array( 'pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
    54         'pre_link_rss' ) as $filter ) {
    55         add_filter( $filter, 'wp_strip_all_tags' );
    56         add_filter( $filter, 'esc_url_raw'       );
    57         add_filter( $filter, 'wp_filter_kses'    );
    58 }
     47$filters = array( 'pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image', 'pre_link_rss' );
     48add_filter( $filters, 'wp_strip_all_tags' );
     49add_filter( $filters, 'esc_url_raw'       );
     50add_filter( $filters, 'wp_filter_kses'    );
    5951
    6052// Display URL
    61 foreach ( array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url' ) as $filter ) {
    62         add_filter( $filter, 'wp_strip_all_tags' );
    63         add_filter( $filter, 'esc_url'           );
    64         add_filter( $filter, 'wp_kses_data'    );
    65 }
     53$filters = array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url' );
     54add_filter( $filters, 'wp_strip_all_tags' );
     55add_filter( $filters, 'esc_url'           );
     56add_filter( $filters, 'wp_kses_data'    );
    6657
    6758// Slugs
    68 foreach ( array( 'pre_term_slug' ) as $filter ) {
    69         add_filter( $filter, 'sanitize_title' );
    70 }
     59$filters = array( 'pre_term_slug' );
     60add_filter( $filters, 'sanitize_title' );
    7161
    7262// Keys
    73 foreach ( array( 'pre_post_type' ) as $filter ) {
    74         add_filter( $filter, 'sanitize_user' );
    75 }
     63$filters = array( 'pre_post_type' );
     64add_filter( $filters, 'sanitize_user' );
    7665
    7766// Places to balance tags on input
    78 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    79         add_filter( $filter, 'balanceTags', 50 );
    80 }
     67$filters = array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' );
     68add_filter( $filters, 'balanceTags', 50 );
    8169
    8270// Format strings for display.
    83 foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) {
    84         add_filter( $filter, 'wptexturize'   );
    85         add_filter( $filter, 'convert_chars' );
    86         add_filter( $filter, 'esc_html'      );
    87 }
     71$filters = array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' );
     72add_filter( $filters, 'wptexturize'   );
     73add_filter( $filters, 'convert_chars' );
     74add_filter( $filters, 'esc_html'      );
    8875
    8976// Format WordPress
    90 foreach ( array( 'the_content', 'the_title', 'comment_text' ) as $filter )
    91         add_filter( $filter, 'capital_P_dangit', 11 );
     77$filters = array( 'the_content', 'the_title', 'comment_text' );
     78add_filter( $filters, 'capital_P_dangit', 11 );
    9279
    9380// Format titles
    94 foreach ( array( 'single_post_title', 'single_cat_title', 'single_tag_title', 'single_month_title', 'nav_menu_attr_title', 'nav_menu_description' ) as $filter ) {
    95         add_filter( $filter, 'wptexturize' );
    96         add_filter( $filter, 'strip_tags'  );
    97 }
     81$filters = array( 'single_post_title', 'single_cat_title', 'single_tag_title', 'single_month_title', 'nav_menu_attr_title', 'nav_menu_description' );
     82add_filter( $filters, 'wptexturize' );
     83add_filter( $filters, 'strip_tags'  );
    9884
    9985// Format text area for display.
    100 foreach ( array( 'term_description' ) as $filter ) {
    101         add_filter( $filter, 'wptexturize'      );
    102         add_filter( $filter, 'convert_chars'    );
    103         add_filter( $filter, 'wpautop'          );
    104         add_filter( $filter, 'shortcode_unautop');
    105 }
     86$filters = array( 'term_description' );
     87add_filter( $filters, 'wptexturize'      );
     88add_filter( $filters, 'convert_chars'    );
     89add_filter( $filters, 'wpautop'          );
     90add_filter( $filters, 'shortcode_unautop');
    10691
    10792// Format for RSS
    108 foreach ( array( 'term_name_rss' ) as $filter ) {
    109         add_filter( $filter, 'convert_chars' );
    110 }
     93$filters = array( 'term_name_rss' );
     94add_filter( $filters, 'convert_chars' );
    11195
    11296// Display filters
    11397add_filter( 'the_title', 'wptexturize'   );
     
    200184add_action( 'template_redirect',   'wp_shortlink_header',           11, 0 );
    201185
    202186// Feed Generator Tags
    203 foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {
    204         add_action( $action, 'the_generator' );
    205 }
     187$actions = array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' );
     188add_action( $actions, 'the_generator' );
    206189
    207190// WP Cron
    208191if ( !defined( 'DOING_CRON' ) )
     
    253236add_action( 'admin_init', 'register_admin_color_schemes', 1);
    254237add_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
    255238
     239unset( $filters, $actions );
    256240?>
  • wp-includes/plugin.php

     
    5656 *      wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)']']
    5757 * @global array $merged_filters Tracks the tags that need to be merged for later. If the hook is added, it doesn't need to run through that process.
    5858 *
    59  * @param string $tag The name of the filter to hook the $function_to_add to.
     59 * @param mixed $tags The name of the filter(s) to hook the $function_to_add to, can either be a string or array of strings.
    6060 * @param callback $function_to_add The name of the function to be called when the filter is applied.
    6161 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    6262 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
    6363 * @return boolean true
    6464 */
    65 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
     65function add_filter($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
    6666        global $wp_filter, $merged_filters;
    67 
    68         $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
    69         $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
    70         unset( $merged_filters[ $tag ] );
     67        foreach ( (array) $tags as $tag ) {
     68                $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
     69                $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
     70                unset( $merged_filters[ $tag ] );
     71        }
    7172        return true;
    7273}
    7374
     
    316317 * @subpackage Plugin
    317318 * @since 1.2
    318319 *
    319  * @param string $tag The name of the action to which the $function_to_add is hooked.
     320 * @param mixed $tags The name of the action(s) to which the $function_to_add is hooked, can either be a string or array of strings.
    320321 * @param callback $function_to_add The name of the function you wish to be called.
    321322 * @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
    322323 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
    323324 */
    324 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    325         return add_filter($tag, $function_to_add, $priority, $accepted_args);
     325function add_action($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
     326        return add_filter($tags, $function_to_add, $priority, $accepted_args);
    326327}
    327328
    328329