Make WordPress Core

Changeset 12041


Ignore:
Timestamp:
10/15/2009 05:27:45 PM (16 years ago)
Author:
markjaquith
Message:

Director of Whitespace rules default-filters.php with an iron fist

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-filters.php

    r12039 r12041  
    1414
    1515// Strip, trim, kses, special chars for string saves
    16 $filters = array('pre_term_name', 'pre_comment_author_name', 'pre_link_name', 'pre_link_target',
    17     'pre_link_rel', 'pre_user_display_name', 'pre_user_first_name', 'pre_user_last_name',
    18     'pre_user_nickname');
    19 foreach ( $filters as $filter ) {
    20     add_filter($filter, 'sanitize_text_field');
    21     add_filter($filter, 'wp_filter_kses');
    22     add_filter($filter, '_wp_specialchars', 30);
     16foreach ( 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 );
    2320}
    2421
    2522// Strip, kses, special chars for string display
    26 $filters = array('term_name', 'comment_author_name', 'link_name', 'link_target', 'link_rel', 'user_display_name', 'user_first_name', 'user_last_name', 'user_nickname');
    27 foreach ( $filters as $filter ) {
    28     add_filter($filter, 'sanitize_text_field');
    29     add_filter($filter, 'wp_filter_kses');
    30     add_filter($filter, '_wp_specialchars', 30);
     23foreach ( 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_filter_kses'       );
     26    add_filter( $filter, '_wp_specialchars', 30 );
    3127}
    3228
    3329// Kses only for textarea saves and displays
    34 $filters = array('pre_term_description', 'term_description', 'pre_link_description', 'link_description', 'pre_link_notes', 'link_notes', 'pre_user_description', 'user_description');
    35 foreach ( $filters as $filter ) {
    36     add_filter($filter, 'wp_filter_kses');
     30foreach ( array( 'pre_term_description', 'term_description', 'pre_link_description', 'link_description', 'pre_link_notes', 'link_notes', 'pre_user_description', 'user_description' ) as $filter ) {
     31    add_filter( $filter, 'wp_filter_kses' );
    3732}
    3833
    3934// Email saves
    40 $filters = array('pre_comment_author_email', 'pre_user_email');
    41 foreach ( $filters as $filter ) {
    42     add_filter($filter, 'trim');
    43     add_filter($filter, 'sanitize_email');
    44     add_filter($filter, 'wp_filter_kses');
     35foreach ( array( 'pre_comment_author_email', 'pre_user_email' ) as $filter ) {
     36    add_filter( $filter, 'trim'           );
     37    add_filter( $filter, 'sanitize_email' );
     38    add_filter( $filter, 'wp_filter_kses' );
    4539}
    4640
    4741// Email display
    48 $filters = array('comment_author_email', 'user_email');
    49 foreach ( $filters as $filter ) {
    50     add_filter($filter, 'sanitize_email');
    51     add_filter($filter, 'wp_filter_kses');
     42foreach ( array( 'comment_author_email', 'user_email' ) as $filter ) {
     43    add_filter( $filter, 'sanitize_email' );
     44    add_filter( $filter, 'wp_filter_kses' );
    5245}
    5346
    5447// Save URL
    55 $filters = array('pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
    56     'pre_link_rss');
    57 foreach ( $filters as $filter ) {
    58     add_filter($filter, 'wp_strip_all_tags');
    59     add_filter($filter, 'esc_url_raw');
    60     add_filter($filter, 'wp_filter_kses');
     48foreach ( array( 'pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
     49    'pre_link_rss' ) as $filter ) {
     50    add_filter( $filter, 'wp_strip_all_tags' );
     51    add_filter( $filter, 'esc_url_raw'       );
     52    add_filter( $filter, 'wp_filter_kses'    );
    6153}
    6254
    6355// Display URL
    64 $filters = array('user_url', 'link_url', 'link_image', 'link_rss', 'comment_url');
    65 foreach ( $filters as $filter ) {
    66     add_filter($filter, 'wp_strip_all_tags');
    67     add_filter($filter, 'esc_url');
    68     add_filter($filter, 'wp_filter_kses');
     56foreach ( array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url' ) as $filter ) {
     57    add_filter( $filter, 'wp_strip_all_tags' );
     58    add_filter( $filter, 'esc_url'           );
     59    add_filter( $filter, 'wp_filter_kses'    );
    6960}
    7061
    7162// Slugs
    72 $filters = array('pre_term_slug');
    73 foreach ( $filters as $filter ) {
    74     add_filter($filter, 'sanitize_title');
     63foreach ( array( 'pre_term_slug' ) as $filter ) {
     64    add_filter( $filter, 'sanitize_title' );
    7565}
    7666
    7767// Keys
    78 $filters = array('pre_post_type');
    79 foreach ( $filters as $filter ) {
    80     add_filter($filter, 'sanitize_user');
     68foreach ( array( 'pre_post_type' ) as $filter ) {
     69    add_filter( $filter, 'sanitize_user' );
    8170}
    8271
    8372// Places to balance tags on input
    84 $filters = array('content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content');
    85 foreach ( $filters as $filter ) {
    86     add_filter( $filter, 'balanceTags', 50);
     73foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
     74    add_filter( $filter, 'balanceTags', 50 );
    8775}
    8876
    8977// Format strings for display.
    90 $filters = array('comment_author', 'term_name', 'link_name', 'link_description',
    91     'link_notes', 'bloginfo', 'wp_title', 'widget_title');
    92 foreach ( $filters as $filter ) {
    93     add_filter($filter, 'wptexturize');
    94     add_filter($filter, 'convert_chars');
    95     add_filter($filter, 'esc_html');
     78foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) {
     79    add_filter( $filter, 'wptexturize'   );
     80    add_filter( $filter, 'convert_chars' );
     81    add_filter( $filter, 'esc_html'      );
    9682}
    9783
    9884// Format text area for display.
    99 $filters = array('term_description');
    100 foreach ( $filters as $filter ) {
    101     add_filter($filter, 'wptexturize');
    102     add_filter($filter, 'convert_chars');
    103     add_filter($filter, 'wpautop');
     85foreach ( array( 'term_description' ) as $filter ) {
     86    add_filter( $filter, 'wptexturize'   );
     87    add_filter( $filter, 'convert_chars' );
     88    add_filter( $filter, 'wpautop'       );
    10489}
    10590
    10691// Format for RSS
    107 $filters = array('term_name_rss');
    108 foreach ( $filters as $filter ) {
    109     add_filter($filter, 'convert_chars');
     92foreach ( array( 'term_name_rss' ) as $filter ) {
     93    add_filter( $filter, 'convert_chars' );
    11094}
    11195
    11296// Display filters
    113 add_filter('the_title', 'wptexturize');
    114 add_filter('the_title', 'convert_chars');
    115 add_filter('the_title', 'trim');
    116 
    117 add_filter('the_content', 'wptexturize');
    118 add_filter('the_content', 'convert_smilies');
    119 add_filter('the_content', 'convert_chars');
    120 add_filter('the_content', 'wpautop');
    121 add_filter('the_content', 'prepend_attachment');
    122 
    123 add_filter('the_excerpt', 'wptexturize');
    124 add_filter('the_excerpt', 'convert_smilies');
    125 add_filter('the_excerpt', 'convert_chars');
    126 add_filter('the_excerpt', 'wpautop');
    127 add_filter('get_the_excerpt', 'wp_trim_excerpt');
    128 
    129 add_filter('comment_text', 'wptexturize');
    130 add_filter('comment_text', 'convert_chars');
    131 add_filter('comment_text', 'make_clickable', 9);
    132 add_filter('comment_text', 'force_balance_tags', 25);
    133 add_filter('comment_text', 'convert_smilies', 20);
    134 add_filter('comment_text', 'wpautop', 30);
    135 
    136 add_filter('comment_excerpt', 'convert_chars');
    137 
    138 add_filter('list_cats', 'wptexturize');
    139 add_filter('single_post_title', 'wptexturize');
    140 
    141 add_filter('wp_sprintf', 'wp_sprintf_l', 10, 2);
     97add_filter( 'the_title', 'wptexturize'   );
     98add_filter( 'the_title', 'convert_chars' );
     99add_filter( 'the_title', 'trim'          );
     100
     101add_filter( 'the_content', 'wptexturize'        );
     102add_filter( 'the_content', 'convert_smilies'    );
     103add_filter( 'the_content', 'convert_chars'      );
     104add_filter( 'the_content', 'wpautop'            );
     105add_filter( 'the_content', 'prepend_attachment' );
     106
     107add_filter( 'the_excerpt',     'wptexturize'     );
     108add_filter( 'the_excerpt',     'convert_smilies' );
     109add_filter( 'the_excerpt',     'convert_chars'   );
     110add_filter( 'the_excerpt',     'wpautop'         );
     111add_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
     112
     113add_filter( 'comment_text', 'wptexturize'            );
     114add_filter( 'comment_text', 'convert_chars'          );
     115add_filter( 'comment_text', 'make_clickable',      9 );
     116add_filter( 'comment_text', 'force_balance_tags', 25 );
     117add_filter( 'comment_text', 'convert_smilies',    20 );
     118add_filter( 'comment_text', 'wpautop',            30 );
     119
     120add_filter( 'comment_excerpt', 'convert_chars' );
     121
     122add_filter( 'list_cats',         'wptexturize' );
     123add_filter( 'single_post_title', 'wptexturize' );
     124
     125add_filter( 'wp_sprintf', 'wp_sprintf_l', 10, 2 );
    142126
    143127// RSS filters
    144 add_filter('the_title_rss', 'strip_tags');
    145 add_filter('the_title_rss', 'ent2ncr', 8);
    146 add_filter('the_title_rss', 'esc_html');
    147 add_filter('the_content_rss', 'ent2ncr', 8);
    148 add_filter('the_excerpt_rss', 'convert_chars');
    149 add_filter('the_excerpt_rss', 'ent2ncr', 8);
    150 add_filter('comment_author_rss', 'ent2ncr', 8);
    151 add_filter('comment_text_rss', 'ent2ncr', 8);
    152 add_filter('comment_text_rss', 'esc_html');
    153 add_filter('bloginfo_rss', 'ent2ncr', 8);
    154 add_filter('the_author', 'ent2ncr', 8);
     128add_filter( 'the_title_rss',      'strip_tags'      );
     129add_filter( 'the_title_rss',      'ent2ncr',      8 );
     130add_filter( 'the_title_rss',      'esc_html'        );
     131add_filter( 'the_content_rss',    'ent2ncr',      8 );
     132add_filter( 'the_excerpt_rss',    'convert_chars'   );
     133add_filter( 'the_excerpt_rss',    'ent2ncr',      8 );
     134add_filter( 'comment_author_rss', 'ent2ncr',      8 );
     135add_filter( 'comment_text_rss',   'ent2ncr',      8 );
     136add_filter( 'comment_text_rss',   'esc_html'        );
     137add_filter( 'bloginfo_rss',       'ent2ncr',      8 );
     138add_filter( 'the_author',         'ent2ncr',      8 );
    155139
    156140// Misc filters
    157 add_filter('option_ping_sites', 'privacy_ping_filter');
    158 add_filter('option_blog_charset', '_wp_specialchars'); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
    159 add_filter('option_home', '_config_wp_home');
    160 add_filter('option_siteurl', '_config_wp_siteurl');
    161 add_filter('tiny_mce_before_init', '_mce_set_direction');
    162 add_filter('pre_kses', 'wp_pre_kses_less_than');
    163 add_filter('sanitize_title', 'sanitize_title_with_dashes');
    164 add_action('check_comment_flood', 'check_comment_flood_db', 10, 3);
    165 add_filter('comment_flood_filter', 'wp_throttle_comment_flood', 10, 3);
    166 add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
    167 add_filter('comment_email', 'antispambot');
    168 add_filter('option_tag_base', '_wp_filter_taxonomy_base');
    169 add_filter('option_category_base', '_wp_filter_taxonomy_base');
    170 add_filter( 'the_posts', '_close_comments_for_old_posts' );
    171 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 );
    172 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 );
    173 add_filter( 'editable_slug', 'urldecode' );
     141add_filter( 'option_ping_sites',    'privacy_ping_filter'                 );
     142add_filter( 'option_blog_charset',  '_wp_specialchars'                    ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
     143add_filter( 'option_home',          '_config_wp_home'                     );
     144add_filter( 'option_siteurl',       '_config_wp_siteurl'                  );
     145add_filter( 'tiny_mce_before_init', '_mce_set_direction'                  );
     146add_filter( 'pre_kses',             'wp_pre_kses_less_than'               );
     147add_filter( 'sanitize_title',       'sanitize_title_with_dashes'          );
     148add_action( 'check_comment_flood',  'check_comment_flood_db',       10, 3 );
     149add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood',    10, 3 );
     150add_filter( 'pre_comment_content',  'wp_rel_nofollow',              15    );
     151add_filter( 'comment_email',        'antispambot'                         );
     152add_filter( 'option_tag_base',      '_wp_filter_taxonomy_base'            );
     153add_filter( 'option_category_base', '_wp_filter_taxonomy_base'            );
     154add_filter( 'the_posts',            '_close_comments_for_old_posts'      );
     155add_filter( 'comments_open',        '_close_comments_for_old_post', 10, 2 );
     156add_filter( 'pings_open',           '_close_comments_for_old_post', 10, 2 );
     157add_filter( 'editable_slug',        'urldecode'                          );
    174158
    175159// Atom SSL support
    176 add_filter('atom_service_url','atom_service_url_filter');
     160add_filter( 'atom_service_url','atom_service_url_filter' );
    177161
    178162// Actions
    179 add_action('wp_head', 'wp_enqueue_scripts', 1);
    180 add_action('wp_head', 'feed_links_extra', 3);
    181 add_action('wp_head', 'rsd_link');
    182 add_action('wp_head', 'wlwmanifest_link');
    183 add_action('wp_head', 'index_rel_link');
    184 add_action('wp_head', 'parent_post_rel_link', 10, 0);
    185 add_action('wp_head', 'start_post_rel_link', 10, 0);
    186 add_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
    187 add_action('wp_head', 'locale_stylesheet');
    188 add_action('publish_future_post', 'check_and_publish_future_post', 10, 1);
    189 add_action('wp_head', 'noindex', 1);
    190 add_action('wp_head', 'wp_print_styles', 8);
    191 add_action('wp_head', 'wp_print_head_scripts', 9);
    192 add_action('wp_head', 'wp_generator');
    193 add_action('wp_head', 'rel_canonical');
    194 add_action('wp_footer', 'wp_print_footer_scripts');
    195 if(!defined('DOING_CRON'))
    196     add_action('sanitize_comment_cookies', 'wp_cron');
    197 add_action('do_feed_rdf', 'do_feed_rdf', 10, 1);
    198 add_action('do_feed_rss', 'do_feed_rss', 10, 1);
    199 add_action('do_feed_rss2', 'do_feed_rss2', 10, 1);
    200 add_action('do_feed_atom', 'do_feed_atom', 10, 1);
    201 add_action('do_pings', 'do_all_pings', 10, 1);
    202 add_action('do_robots', 'do_robots');
    203 add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
    204 add_action('admin_print_scripts', 'print_head_scripts', 20);
    205 add_action('admin_print_footer_scripts', 'print_footer_scripts', 20);
    206 add_action('admin_print_styles', 'print_admin_styles', 20);
    207 add_action('init', 'smilies_init', 5);
    208 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
    209 add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 );
    210 add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
    211 add_action( 'pre_post_update', 'wp_save_post_revision' );
    212 add_action('publish_post', '_publish_post_hook', 5, 1);
    213 add_action('future_post', '_future_post_hook', 5, 2);
    214 add_action('future_page', '_future_post_hook', 5, 2);
    215 add_action('save_post', '_save_post_hook', 5, 2);
    216 add_action('transition_post_status', '_transition_post_status', 5, 3);
    217 add_action('comment_form', 'wp_comment_form_unfiltered_html_nonce');
     163add_action( 'wp_head',             'wp_enqueue_scripts',             1    );
     164add_action( 'wp_head',             'feed_links_extra',               3    );
     165add_action( 'wp_head',             'rsd_link'                             );
     166add_action( 'wp_head',             'wlwmanifest_link'                     );
     167add_action( 'wp_head',             'index_rel_link'                       );
     168add_action( 'wp_head',             'parent_post_rel_link',          10, 0 );
     169add_action( 'wp_head',             'start_post_rel_link',           10, 0 );
     170add_action( 'wp_head',             'adjacent_posts_rel_link',       10, 0 );
     171add_action( 'wp_head',             'locale_stylesheet'                    );
     172add_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
     173add_action( 'wp_head',             'noindex',                        1    );
     174add_action( 'wp_head',             'wp_print_styles',                8    );
     175add_action( 'wp_head',             'wp_print_head_scripts',          9    );
     176add_action( 'wp_head',             'wp_generator'                         );
     177add_action( 'wp_head',             'rel_canonical'                        );
     178add_action( 'wp_footer',           'wp_print_footer_scripts'              );
     179
     180// WP Cron
     181if ( !defined( 'DOING_CRON' ) )
     182    add_action( 'sanitize_comment_cookies', 'wp_cron' );
     183
     184// 2 Actions 2 Furious
     185add_action( 'do_feed_rdf',                'do_feed_rdf',             10, 1 );
     186add_action( 'do_feed_rss',                'do_feed_rss',             10, 1 );
     187add_action( 'do_feed_rss2',               'do_feed_rss2',            10, 1 );
     188add_action( 'do_feed_atom',               'do_feed_atom',            10, 1 );
     189add_action( 'do_pings',                   'do_all_pings',            10, 1 );
     190add_action( 'do_robots',                  'do_robots'                      );
     191add_action( 'sanitize_comment_cookies',   'sanitize_comment_cookies'       );
     192add_action( 'admin_print_scripts',        'print_head_scripts',      20    );
     193add_action( 'admin_print_footer_scripts', 'print_footer_scripts',    20    );
     194add_action( 'admin_print_styles',         'print_admin_styles',      20    );
     195add_action( 'init',                       'smilies_init',             5    );
     196add_action( 'plugins_loaded',             'wp_maybe_load_widgets',    0    );
     197add_action( 'plugins_loaded',             'wp_maybe_load_embeds',     0    );
     198add_action( 'shutdown',                   'wp_ob_end_flush_all',      1    );
     199add_action( 'pre_post_update',            'wp_save_post_revision'          );
     200add_action( 'publish_post',               '_publish_post_hook',       5, 1 );
     201add_action( 'future_post',                '_future_post_hook',        5, 2 );
     202add_action( 'future_page',                '_future_post_hook',        5, 2 );
     203add_action( 'save_post',                  '_save_post_hook',          5, 2 );
     204add_action( 'transition_post_status',     '_transition_post_status',  5, 3 );
     205add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce'        );
     206
    218207// Post Image CSS class filtering
    219 add_action( 'begin_fetch_post_image_html', '_wp_post_image_class_filter_add' );
    220 add_action( 'end_fetch_post_image_html', '_wp_post_image_class_filter_remove' );
     208add_action( 'begin_fetch_post_image_html', '_wp_post_image_class_filter_add'    );
     209add_action( 'end_fetch_post_image_html',   '_wp_post_image_class_filter_remove' );
     210
    221211// Redirect Old Slugs
    222 add_action('template_redirect', 'wp_old_slug_redirect');
    223 add_action('edit_post', 'wp_check_for_changed_slugs');
    224 add_action('edit_form_advanced', 'wp_remember_old_slug');
    225 add_action('init', '_show_post_preview');
    226 
    227 add_filter('pre_option_gmt_offset','wp_timezone_override_offset');
    228 
    229 ?>
     212add_action( 'template_redirect',  'wp_old_slug_redirect'       );
     213add_action( 'edit_post',          'wp_check_for_changed_slugs' );
     214add_action( 'edit_form_advanced', 'wp_remember_old_slug'       );
     215add_action( 'init',               '_show_post_preview'         );
     216
     217// Timezone
     218add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );
Note: See TracChangeset for help on using the changeset viewer.