WordPress.org

Make WordPress Core

Ticket #8640: 8640.2.diff

File 8640.2.diff, 10.6 KB (added by ShaneF, 9 years ago)
  • 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 }
    2519
     20add_filters($filter, 'strip_tags');
     21add_filters($filter, 'trim');
     22add_filters($filter, 'wp_filter_kses');
     23add_filters($filter, 'wp_specialchars', 30);
     24
    2625// Kses only for textarea saves
    2726$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 }
     27add_filters($filter, 'wp_filter_kses');
    3128
    3229// Email
    3330$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 }
     31add_filters($filter, 'trim');
     32add_filters($filter, 'sanitize_email');
     33add_filters($filter, 'wp_filter_kses');
    3934
     35
    4036// Save URL
    4137$filters = array('pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
    4238        '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 }
     39add_filters($filter, 'strip_tags');
     40add_filters($filter, 'trim');
     41add_filters($filter, 'sanitize_url');
     42add_filters($filter, 'wp_filter_kses');
    4943
    5044// Display URL
    5145$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 }
     46add_filters($filter, 'strip_tags');
     47add_filters($filter, 'trim');
     48add_filters($filter, 'clean_url');
     49add_filters($filter, 'wp_filter_kses');
    5850
    5951// Slugs
    6052$filters = array('pre_term_slug');
    61 foreach ( $filters as $filter ) {
    62         add_filter($filter, 'sanitize_title');
    63 }
     53add_filters($filter, 'sanitize_title');
    6454
    6555// Keys
    6656$filters = array('pre_post_type');
    67 foreach ( $filters as $filter ) {
    68         add_filter($filter, 'sanitize_user');
    69 }
     57add_filters($filter, 'sanitize_user');
    7058
    7159// Places to balance tags on input
    7260$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 }
     61add_filters( $filter, 'balanceTags', 50);
    7662
    7763// Format strings for display.
    7864$filters = array('comment_author', 'term_name', 'link_name', 'link_description',
    7965        'link_notes', 'bloginfo', 'wp_title');
    80 foreach ( $filters as $filter ) {
    81         add_filter($filter, 'wptexturize');
    82         add_filter($filter, 'convert_chars');
    83         add_filter($filter, 'wp_specialchars');
    84 }
     66add_filters($filter, 'wptexturize');
     67add_filters($filter, 'convert_chars');
     68add_filters($filter, 'wp_specialchars');
    8569
    8670// Format text area for display.
    8771$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 }
     72add_filters($filter, 'wptexturize');
     73add_filters($filter, 'convert_chars');
     74add_filters($filter, 'wpautop');
    9375
    9476// Format for RSS
    9577$filters = array('term_name_rss');
    96 foreach ( $filters as $filter ) {
    97         add_filter($filter, 'convert_chars');
    98 }
     78add_filters($filter, 'convert_chars');
    9979
    10080// Display filters
    101 add_filter('the_title', 'wptexturize');
    102 add_filter('the_title', 'convert_chars');
    103 add_filter('the_title', 'trim');
     81$funcitons = array('wptexturize', 'convert_chars', 'trim');
     82add_filters_func('the_title', $funcitons);
    10483
    105 add_filter('the_content', 'wptexturize');
    106 add_filter('the_content', 'convert_smilies');
    107 add_filter('the_content', 'convert_chars');
    108 add_filter('the_content', 'wpautop');
    109 add_filter('the_content', 'prepend_attachment');
     84$functions = array('wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'prepend_attachment');
     85add_filters_func('the_content', $functions);
    11086
    111 add_filter('the_excerpt', 'wptexturize');
    112 add_filter('the_excerpt', 'convert_smilies');
    113 add_filter('the_excerpt', 'convert_chars');
    114 add_filter('the_excerpt', 'wpautop');
     87$functions = array('wptexturize', 'convert_smilies', 'convert_chars', 'wpautop');
     88add_filters_func('the_excerpt', $functions);
    11589add_filter('get_the_excerpt', 'wp_trim_excerpt');
    11690
    117 add_filter('comment_text', 'wptexturize');
    118 add_filter('comment_text', 'convert_chars');
     91$functions = array('wptexturize', 'convert_chars');
     92add_filters_func('comment_text', $functions);
    11993add_filter('comment_text', 'make_clickable', 9);
    12094add_filter('comment_text', 'force_balance_tags', 25);
    12195add_filter('comment_text', 'convert_smilies', 20);
     
    12397
    12498add_filter('comment_excerpt', 'convert_chars');
    12599
    126 add_filter('list_cats', 'wptexturize');
    127 add_filter('single_post_title', 'wptexturize');
     100$filters = array('list_cats', 'single_post_title');
     101add_filters($filters, 'wptexturize');
    128102
    129103add_filter('wp_sprintf', 'wp_sprintf_l', 10, 2);
    130104
  • 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_filters(array('example_filter1', 'example_filter2'), 'example_hook');
     80 * </code>
     81 *
     82 * @package WordPress
     83 * @subpackage Plugin
     84 * @since 2.8.0
     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 $tags 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 * Hooks multiple filters to a single function.
     105 *
     106 * <code>
     107 * function example_hook1($example) { echo $example; }
     108 * function example_hook2($example) { echo $example; }
     109 * add_filters_func('example_filter', array('example_hook1', 'example_hook2'));
     110 * </code>
     111 *
     112 * @package WordPress
     113 * @subpackage Plugin
     114 * @since 2.8.0
     115 * @global array $wp_filter Stores all of the filters added in the form of
     116 *      wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
     117 * @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.
     118 *
     119 * @param string $tag The names of the filters to hook the $functions to.
     120 * @param array of functions $functions The name of the functions to be called when the filter is applied.
     121 * @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.
     122 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
     123 * @return boolean true
     124 */
     125
     126function add_filters_func($tag, $functions, $priority = 10, $accepted_args = 1) {
     127        foreach ( (array) $functions as $function ) {
     128                add_filter($tag, $function, $priority, $accepted_args);
     129        }
     130        return true;
     131}
     132
     133
     134/**
    75135 * Check if any filter has been registered for a hook.
    76136 *
    77137 * @package WordPress
     
    273333}
    274334
    275335
     336
    276337/**
     338 * Hooks a function on to multiple actions.
     339 *
     340 * @uses add_filters() Adds an action. Parameter list and functionality are the same.
     341 *
     342 * @package WordPress
     343 * @subpackage Plugin
     344 * @since 1.8
     345 *
     346 * @param array of string $tag The names of the actions to which the $function_to_add is hooked.
     347 * @param callback $function_to_add The name of the function you wish to be called.
     348 * @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.
     349 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
     350 */
     351function add_actions($tags, $function_to_add, $priority = 10, $accepted_args = 1) {
     352        return add_filters($tags, $function_to_add, $priority, $accepted_args);
     353}
     354
     355/**
     356 * Hooks a function on to multiple actions.
     357 *
     358 * @uses add_filters_func() Adds an action. Parameter list and functionality are the same.
     359 *
     360 * @package WordPress
     361 * @subpackage Plugin
     362 * @since 2.8.0
     363 *
     364 * @param string $tag The names of the actions to which the $functions is hooked.
     365 * @param array of $functions The name of the functions you wish to be called.
     366 * @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.
     367 * @param int $accepted_args optional. The number of arguments the function accept (default 1).
     368 */
     369function add_actions_func($tag, $functions, $priority = 10, $accepted_args = 1) {
     370        return add_filters_func($tag, $functions, $priority, $accepted_args);
     371}
     372
     373
     374/**
    277375 * Execute functions hooked on a specific action hook.
    278376 *
    279377 * This function invokes all functions attached to action hook $tag. It is