WordPress.org

Make WordPress Core

Ticket #8640: 8640.3.diff

File 8640.3.diff, 6.8 KB (added by Denis-de-Bernardy, 5 years ago)

same as 8640.diff, except that the filters actually get used in the default-filters.php file.

  • wp-includes/default-filters.php

     
    1616$filters = array('pre_term_name', 'pre_comment_author_name', 'pre_link_name', 'pre_link_target', 
    1717        'pre_link_rel', 'pre_user_display_name', 'pre_user_first_name', 'pre_user_last_name', 
    1818        'pre_user_nickname'); 
    19 foreach ( $filters as $filter ) { 
    20         add_filter($filter, 'strip_tags'); 
    21         add_filter($filter, 'trim'); 
    22         add_filter($filter, 'wp_filter_kses'); 
    23         add_filter($filter, 'wp_specialchars', 30); 
    24 } 
     19add_filters($filters, 'strip_tags'); 
     20add_filters($filters, 'trim'); 
     21add_filters($filters, 'wp_filter_kses'); 
     22add_filters($filters, 'wp_specialchars', 30); 
    2523 
    2624// Kses only for textarea saves 
    2725$filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description'); 
    28 foreach ( $filters as $filter ) { 
    29         add_filter($filter, 'wp_filter_kses'); 
    30 } 
     26add_filters($filters, 'wp_filter_kses'); 
    3127 
    3228// Email 
    3329$filters = array('pre_comment_author_email', 'pre_user_email'); 
    34 foreach ( $filters as $filter ) { 
    35         add_filter($filter, 'trim'); 
    36         add_filter($filter, 'sanitize_email'); 
    37         add_filter($filter, 'wp_filter_kses'); 
    38 } 
     30add_filters($filters, 'trim'); 
     31add_filters($filters, 'sanitize_email'); 
     32add_filters($filters, 'wp_filter_kses'); 
    3933 
    4034// Save URL 
    4135$filters = array('pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image', 
    4236        'pre_link_rss'); 
    43 foreach ( $filters as $filter ) { 
    44         add_filter($filter, 'strip_tags'); 
    45         add_filter($filter, 'trim'); 
    46         add_filter($filter, 'sanitize_url'); 
    47         add_filter($filter, 'wp_filter_kses'); 
    48 } 
     37add_filters($filters, 'strip_tags'); 
     38add_filters($filters, 'trim'); 
     39add_filters($filters, 'sanitize_url'); 
     40add_filters($filters, 'wp_filter_kses'); 
    4941 
    5042// Display URL 
    5143$filters = array('user_url', 'link_url', 'link_image', 'link_rss', 'comment_url'); 
    52 foreach ( $filters as $filter ) { 
    53         add_filter($filter, 'strip_tags'); 
    54         add_filter($filter, 'trim'); 
    55         add_filter($filter, 'clean_url'); 
    56         add_filter($filter, 'wp_filter_kses'); 
    57 } 
     44add_filters($filters, 'strip_tags'); 
     45add_filters($filters, 'trim'); 
     46add_filters($filters, 'clean_url'); 
     47add_filters($filters, 'wp_filter_kses'); 
    5848 
    5949// Slugs 
    6050$filters = array('pre_term_slug'); 
    61 foreach ( $filters as $filter ) { 
    62         add_filter($filter, 'sanitize_title'); 
    63 } 
     51add_filters($filters, 'sanitize_title'); 
    6452 
    6553// Keys 
    6654$filters = array('pre_post_type'); 
    67 foreach ( $filters as $filter ) { 
    68         add_filter($filter, 'sanitize_user'); 
    69 } 
     55add_filters($filters, 'sanitize_user'); 
    7056 
    7157// Places to balance tags on input 
    7258$filters = array('content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content'); 
    73 foreach ( $filters as $filter ) { 
    74         add_filter( $filter, 'balanceTags', 50); 
    75 } 
     59add_filters($filters, 'balanceTags', 50); 
    7660 
    7761// Format strings for display. 
    7862$filters = array('comment_author', 'term_name', 'link_name', 'link_description', 
    7963        'link_notes', 'bloginfo', 'wp_title', 'widget_title'); 
    80 foreach ( $filters as $filter ) { 
    81         add_filter($filter, 'wptexturize'); 
    82         add_filter($filter, 'convert_chars'); 
    83         add_filter($filter, 'wp_specialchars'); 
    84 } 
     64add_filters($filters, 'wptexturize'); 
     65add_filters($filters, 'convert_chars'); 
     66add_filters($filters, 'wp_specialchars'); 
    8567 
    8668// Format text area for display. 
    8769$filters = array('term_description'); 
    88 foreach ( $filters as $filter ) { 
    89         add_filter($filter, 'wptexturize'); 
    90         add_filter($filter, 'convert_chars'); 
    91         add_filter($filter, 'wpautop'); 
    92 } 
     70add_filters($filters, 'wptexturize'); 
     71add_filters($filters, 'convert_chars'); 
     72add_filters($filters, 'wpautop'); 
    9373 
    9474// Format for RSS 
    9575$filters = array('term_name_rss'); 
    96 foreach ( $filters as $filter ) { 
    97         add_filter($filter, 'convert_chars'); 
    98 } 
     76add_filters($filters, 'convert_chars'); 
    9977 
    10078// Display filters 
    10179add_filter('the_title', 'wptexturize'); 
     
    209187 
    210188add_filter('pre_option_gmt_offset','wp_timezone_override_offset'); 
    211189 
    212 ?> 
     190?> 
     191 No newline at end of file 
  • wp-includes/plugin.php

     
    7272} 
    7373 
    7474/** 
     75 * Hooks multiple functions to a specific filter action. 
     76 * 
     77 * <code> 
     78 * function example_hook($example) { echo $example; } 
     79 * add_filter(array('example_filter1', 'example_filter2'), 'example_hook'); 
     80 * </code> 
     81 * 
     82 * @package WordPress 
     83 * @subpackage Plugin 
     84 * @since 2.8 
     85 * @global array $wp_filter Stores all of the filters added in the form of 
     86 *      wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]'] 
     87 * @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. 
     88 * 
     89 * @param array of string $tag The names of the filters to hook the $function_to_add to. 
     90 * @param callback $function_to_add The name of the function to be called when the filter is applied. 
     91 * @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. 
     92 * @param int $accepted_args optional. The number of arguments the function accept (default 1). 
     93 * @return boolean true 
     94 */ 
     95 
     96function add_filters($tags, $function_to_add, $priority = 10, $accepted_args = 1) { 
     97        foreach ( (array) $tags as $tag ) { 
     98                add_filter($tag, $function_to_add, $priority, $accepted_args); 
     99        } 
     100        return true; 
     101} 
     102 
     103 
     104/** 
    75105 * Check if any filter has been registered for a hook. 
    76106 * 
    77107 * @package WordPress 
     
    273303} 
    274304 
    275305 
     306 
    276307/** 
     308 * Hooks a function on to multiple actions. 
     309 * 
     310 * @uses add_filters() Adds an action. Parameter list and functionality are the same. 
     311 * 
     312 * @package WordPress 
     313 * @subpackage Plugin 
     314 * @since 1.8 
     315 * 
     316 * @param array of string $tag The names of the actions to which the $function_to_add is hooked. 
     317 * @param callback $function_to_add The name of the function you wish to be called. 
     318 * @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. 
     319 * @param int $accepted_args optional. The number of arguments the function accept (default 1). 
     320 */ 
     321function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) { 
     322        return add_filters($tags, $function_to_add, $priority, $accepted_args); 
     323} 
     324 
     325 
     326/** 
    277327 * Execute functions hooked on a specific action hook. 
    278328 * 
    279329 * This function invokes all functions attached to action hook $tag. It is