web/wp-includes/default-filters.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    11  *
    11  *
    12  * @package WordPress
    12  * @package WordPress
    13  */
    13  */
    14 
    14 
    15 // Strip, trim, kses, special chars for string saves
    15 // Strip, trim, kses, special chars for string saves
    16 $filters = array('pre_term_name', 'pre_comment_author_name', 'pre_link_name', 'pre_link_target',
    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 	'pre_link_rel', 'pre_user_display_name', 'pre_user_first_name', 'pre_user_last_name',
    17 	add_filter( $filter, 'sanitize_text_field'  );
    18 	'pre_user_nickname');
    18 	add_filter( $filter, 'wp_filter_kses'       );
    19 foreach ( $filters as $filter ) {
    19 	add_filter( $filter, '_wp_specialchars', 30 );
    20 	add_filter($filter, 'strip_tags');
    20 }
    21 	add_filter($filter, 'trim');
    21 
    22 	add_filter($filter, 'wp_filter_kses');
    22 // Strip, kses, special chars for string display
    23 	add_filter($filter, '_wp_specialchars', 30);
    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 );
    24 }
    27 }
    25 
    28 
    26 // Kses only for textarea saves
    29 // Kses only for textarea saves
    27 $filters = array('pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description');
    30 foreach ( array( 'pre_term_description', 'pre_link_description', 'pre_link_notes', 'pre_user_description' ) as $filter ) {
    28 foreach ( $filters as $filter ) {
    31 	add_filter( $filter, 'wp_filter_kses' );
    29 	add_filter($filter, 'wp_filter_kses');
    32 }
    30 }
    33 
    31 
    34 // Kses only for textarea saves displays
    32 // Email
    35 foreach ( array( 'term_description', 'link_description', 'link_notes', 'user_description' ) as $filter ) {
    33 $filters = array('pre_comment_author_email', 'pre_user_email');
    36 	add_filter( $filter, 'wp_kses_data' );
    34 foreach ( $filters as $filter ) {
    37 }
    35 	add_filter($filter, 'trim');
    38 
    36 	add_filter($filter, 'sanitize_email');
    39 // Email saves
    37 	add_filter($filter, 'wp_filter_kses');
    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 }
       
    45 
       
    46 // 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' );
    38 }
    50 }
    39 
    51 
    40 // Save URL
    52 // Save URL
    41 $filters = array('pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
    53 foreach ( array( 'pre_comment_author_url', 'pre_user_url', 'pre_link_url', 'pre_link_image',
    42 	'pre_link_rss');
    54 	'pre_link_rss' ) as $filter ) {
    43 foreach ( $filters as $filter ) {
    55 	add_filter( $filter, 'wp_strip_all_tags' );
    44 	add_filter($filter, 'strip_tags');
    56 	add_filter( $filter, 'esc_url_raw'       );
    45 	add_filter($filter, 'trim');
    57 	add_filter( $filter, 'wp_filter_kses'    );
    46 	add_filter($filter, 'esc_url_raw');
       
    47 	add_filter($filter, 'wp_filter_kses');
       
    48 }
    58 }
    49 
    59 
    50 // Display URL
    60 // Display URL
    51 $filters = array('user_url', 'link_url', 'link_image', 'link_rss', 'comment_url');
    61 foreach ( array( 'user_url', 'link_url', 'link_image', 'link_rss', 'comment_url' ) as $filter ) {
    52 foreach ( $filters as $filter ) {
    62 	add_filter( $filter, 'wp_strip_all_tags' );
    53 	add_filter($filter, 'strip_tags');
    63 	add_filter( $filter, 'esc_url'           );
    54 	add_filter($filter, 'trim');
    64 	add_filter( $filter, 'wp_kses_data'    );
    55 	add_filter($filter, 'esc_url');
       
    56 	add_filter($filter, 'wp_filter_kses');
       
    57 }
    65 }
    58 
    66 
    59 // Slugs
    67 // Slugs
    60 $filters = array('pre_term_slug');
    68 foreach ( array( 'pre_term_slug' ) as $filter ) {
    61 foreach ( $filters as $filter ) {
    69 	add_filter( $filter, 'sanitize_title' );
    62 	add_filter($filter, 'sanitize_title');
       
    63 }
    70 }
    64 
    71 
    65 // Keys
    72 // Keys
    66 $filters = array('pre_post_type');
    73 foreach ( array( 'pre_post_type' ) as $filter ) {
    67 foreach ( $filters as $filter ) {
    74 	add_filter( $filter, 'sanitize_user' );
    68 	add_filter($filter, 'sanitize_user');
       
    69 }
    75 }
    70 
    76 
    71 // Places to balance tags on input
    77 // Places to balance tags on input
    72 $filters = array('content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content');
    78 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
    73 foreach ( $filters as $filter ) {
    79 	add_filter( $filter, 'balanceTags', 50 );
    74 	add_filter( $filter, 'balanceTags', 50);
       
    75 }
    80 }
    76 
    81 
    77 // Format strings for display.
    82 // Format strings for display.
    78 $filters = array('comment_author', 'term_name', 'link_name', 'link_description',
    83 foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) {
    79 	'link_notes', 'bloginfo', 'wp_title', 'widget_title');
    84 	add_filter( $filter, 'wptexturize'   );
    80 foreach ( $filters as $filter ) {
    85 	add_filter( $filter, 'convert_chars' );
    81 	add_filter($filter, 'wptexturize');
    86 	add_filter( $filter, 'esc_html'      );
    82 	add_filter($filter, 'convert_chars');
       
    83 	add_filter($filter, 'esc_html');
       
    84 }
    87 }
    85 
    88 
    86 // Format text area for display.
    89 // Format text area for display.
    87 $filters = array('term_description');
    90 foreach ( array( 'term_description' ) as $filter ) {
    88 foreach ( $filters as $filter ) {
    91 	add_filter( $filter, 'wptexturize'      );
    89 	add_filter($filter, 'wptexturize');
    92 	add_filter( $filter, 'convert_chars'    );
    90 	add_filter($filter, 'convert_chars');
    93 	add_filter( $filter, 'wpautop'          );
    91 	add_filter($filter, 'wpautop');
    94 	add_filter( $filter, 'shortcode_unautop');
    92 }
    95 }
    93 
    96 
    94 // Format for RSS
    97 // Format for RSS
    95 $filters = array('term_name_rss');
    98 foreach ( array( 'term_name_rss' ) as $filter ) {
    96 foreach ( $filters as $filter ) {
    99 	add_filter( $filter, 'convert_chars' );
    97 	add_filter($filter, 'convert_chars');
       
    98 }
   100 }
    99 
   101 
   100 // Display filters
   102 // Display filters
   101 add_filter('the_title', 'wptexturize');
   103 add_filter( 'the_title', 'wptexturize'   );
   102 add_filter('the_title', 'convert_chars');
   104 add_filter( 'the_title', 'convert_chars' );
   103 add_filter('the_title', 'trim');
   105 add_filter( 'the_title', 'trim'          );
   104 
   106 
   105 add_filter('the_content', 'wptexturize');
   107 add_filter( 'the_content', 'wptexturize'        );
   106 add_filter('the_content', 'convert_smilies');
   108 add_filter( 'the_content', 'convert_smilies'    );
   107 add_filter('the_content', 'convert_chars');
   109 add_filter( 'the_content', 'convert_chars'      );
   108 add_filter('the_content', 'wpautop');
   110 add_filter( 'the_content', 'wpautop'            );
   109 add_filter('the_content', 'prepend_attachment');
   111 add_filter( 'the_content', 'shortcode_unautop'  );
   110 
   112 add_filter( 'the_content', 'prepend_attachment' );
   111 add_filter('the_excerpt', 'wptexturize');
   113 
   112 add_filter('the_excerpt', 'convert_smilies');
   114 add_filter( 'the_excerpt',     'wptexturize'      );
   113 add_filter('the_excerpt', 'convert_chars');
   115 add_filter( 'the_excerpt',     'convert_smilies'  );
   114 add_filter('the_excerpt', 'wpautop');
   116 add_filter( 'the_excerpt',     'convert_chars'    );
   115 add_filter('get_the_excerpt', 'wp_trim_excerpt');
   117 add_filter( 'the_excerpt',     'wpautop'          );
   116 
   118 add_filter( 'the_excerpt',     'shortcode_unautop');
   117 add_filter('comment_text', 'wptexturize');
   119 add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
   118 add_filter('comment_text', 'convert_chars');
   120 
   119 add_filter('comment_text', 'make_clickable', 9);
   121 add_filter( 'comment_text', 'wptexturize'            );
   120 add_filter('comment_text', 'force_balance_tags', 25);
   122 add_filter( 'comment_text', 'convert_chars'          );
   121 add_filter('comment_text', 'convert_smilies', 20);
   123 add_filter( 'comment_text', 'make_clickable',      9 );
   122 add_filter('comment_text', 'wpautop', 30);
   124 add_filter( 'comment_text', 'force_balance_tags', 25 );
   123 
   125 add_filter( 'comment_text', 'convert_smilies',    20 );
   124 add_filter('comment_excerpt', 'convert_chars');
   126 add_filter( 'comment_text', 'wpautop',            30 );
   125 
   127 
   126 add_filter('list_cats', 'wptexturize');
   128 add_filter( 'comment_excerpt', 'convert_chars' );
   127 add_filter('single_post_title', 'wptexturize');
   129 
   128 
   130 add_filter( 'list_cats',         'wptexturize' );
   129 add_filter('wp_sprintf', 'wp_sprintf_l', 10, 2);
   131 add_filter( 'single_post_title', 'wptexturize' );
       
   132 
       
   133 add_filter( 'wp_sprintf', 'wp_sprintf_l', 10, 2 );
   130 
   134 
   131 // RSS filters
   135 // RSS filters
   132 add_filter('the_title_rss', 'strip_tags');
   136 add_filter( 'the_title_rss',      'strip_tags'      );
   133 add_filter('the_title_rss', 'ent2ncr', 8);
   137 add_filter( 'the_title_rss',      'ent2ncr',      8 );
   134 add_filter('the_title_rss', 'esc_html');
   138 add_filter( 'the_title_rss',      'esc_html'        );
   135 add_filter('the_content_rss', 'ent2ncr', 8);
   139 add_filter( 'the_content_rss',    'ent2ncr',      8 );
   136 add_filter('the_excerpt_rss', 'convert_chars');
   140 add_filter( 'the_excerpt_rss',    'convert_chars'   );
   137 add_filter('the_excerpt_rss', 'ent2ncr', 8);
   141 add_filter( 'the_excerpt_rss',    'ent2ncr',      8 );
   138 add_filter('comment_author_rss', 'ent2ncr', 8);
   142 add_filter( 'comment_author_rss', 'ent2ncr',      8 );
   139 add_filter('comment_text_rss', 'ent2ncr', 8);
   143 add_filter( 'comment_text_rss',   'ent2ncr',      8 );
   140 add_filter('comment_text_rss', 'esc_html');
   144 add_filter( 'comment_text_rss',   'esc_html'        );
   141 add_filter('bloginfo_rss', 'ent2ncr', 8);
   145 add_filter( 'bloginfo_rss',       'ent2ncr',      8 );
   142 add_filter('the_author', 'ent2ncr', 8);
   146 add_filter( 'the_author',         'ent2ncr',      8 );
   143 
   147 
   144 // Misc filters
   148 // Misc filters
   145 add_filter('option_ping_sites', 'privacy_ping_filter');
   149 add_filter( 'option_ping_sites',    'privacy_ping_filter'                 );
   146 add_filter('option_blog_charset', '_wp_specialchars'); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
   150 add_filter( 'option_blog_charset',  '_wp_specialchars'                    ); // IMPORTANT: This must not be wp_specialchars() or esc_html() or it'll cause an infinite loop
   147 add_filter('option_home', '_config_wp_home');
   151 add_filter( 'option_home',          '_config_wp_home'                     );
   148 add_filter('option_siteurl', '_config_wp_siteurl');
   152 add_filter( 'option_siteurl',       '_config_wp_siteurl'                  );
   149 add_filter('tiny_mce_before_init', '_mce_set_direction');
   153 add_filter( 'tiny_mce_before_init', '_mce_set_direction'                  );
   150 add_filter('pre_kses', 'wp_pre_kses_less_than');
   154 add_filter( 'pre_kses',             'wp_pre_kses_less_than'               );
   151 add_filter('sanitize_title', 'sanitize_title_with_dashes');
   155 add_filter( 'sanitize_title',       'sanitize_title_with_dashes'          );
   152 add_action('check_comment_flood', 'check_comment_flood_db', 10, 3);
   156 add_action( 'check_comment_flood',  'check_comment_flood_db',       10, 3 );
   153 add_filter('comment_flood_filter', 'wp_throttle_comment_flood', 10, 3);
   157 add_filter( 'comment_flood_filter', 'wp_throttle_comment_flood',    10, 3 );
   154 add_filter('pre_comment_content', 'wp_rel_nofollow', 15);
   158 add_filter( 'pre_comment_content',  'wp_rel_nofollow',              15    );
   155 add_filter('comment_email', 'antispambot');
   159 add_filter( 'comment_email',        'antispambot'                         );
   156 add_filter('option_tag_base', '_wp_filter_taxonomy_base');
   160 add_filter( 'option_tag_base',      '_wp_filter_taxonomy_base'            );
   157 add_filter('option_category_base', '_wp_filter_taxonomy_base');
   161 add_filter( 'option_category_base', '_wp_filter_taxonomy_base'            );
   158 add_filter( 'the_posts', '_close_comments_for_old_posts' );
   162 add_filter( 'the_posts',            '_close_comments_for_old_posts'       );
   159 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 );
   163 add_filter( 'comments_open',        '_close_comments_for_old_post', 10, 2 );
   160 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 );
   164 add_filter( 'pings_open',           '_close_comments_for_old_post', 10, 2 );
   161 add_filter( 'editable_slug', 'urldecode' );
   165 add_filter( 'editable_slug',        'urldecode'                           );
   162 
   166 
   163 // Atom SSL support
   167 // Atom SSL support
   164 add_filter('atom_service_url','atom_service_url_filter');
   168 add_filter( 'atom_service_url','atom_service_url_filter' );
   165 
   169 
   166 // Actions
   170 // Actions
   167 add_action('wp_head', 'wp_enqueue_scripts', 1);
   171 add_action( 'wp_head',             'wp_enqueue_scripts',             1    );
   168 add_action('wp_head', 'feed_links_extra', 3);
   172 add_action( 'wp_head',             'feed_links_extra',               3    );
   169 add_action('wp_head', 'rsd_link');
   173 add_action( 'wp_head',             'rsd_link'                             );
   170 add_action('wp_head', 'wlwmanifest_link');
   174 add_action( 'wp_head',             'wlwmanifest_link'                     );
   171 add_action('wp_head', 'index_rel_link');
   175 add_action( 'wp_head',             'index_rel_link'                       );
   172 add_action('wp_head', 'parent_post_rel_link', 10, 0);
   176 add_action( 'wp_head',             'parent_post_rel_link',          10, 0 );
   173 add_action('wp_head', 'start_post_rel_link', 10, 0);
   177 add_action( 'wp_head',             'start_post_rel_link',           10, 0 );
   174 add_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
   178 add_action( 'wp_head',             'adjacent_posts_rel_link',       10, 0 );
   175 add_action('wp_head', 'locale_stylesheet');
   179 add_action( 'wp_head',             'locale_stylesheet'                    );
   176 add_action('publish_future_post', 'check_and_publish_future_post', 10, 1);
   180 add_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
   177 add_action('wp_head', 'noindex', 1);
   181 add_action( 'wp_head',             'noindex',                        1    );
   178 add_action('wp_head', 'wp_print_styles', 8);
   182 add_action( 'wp_head',             'wp_print_styles',                8    );
   179 add_action('wp_head', 'wp_print_head_scripts', 9);
   183 add_action( 'wp_head',             'wp_print_head_scripts',          9    );
   180 add_action('wp_head', 'wp_generator');
   184 add_action( 'wp_head',             'wp_generator'                         );
   181 add_action('wp_footer', 'wp_print_footer_scripts');
   185 add_action( 'wp_head',             'rel_canonical'                        );
   182 if(!defined('DOING_CRON'))
   186 add_action( 'wp_footer',           'wp_print_footer_scripts'              );
   183 	add_action('sanitize_comment_cookies', 'wp_cron');
   187 
   184 add_action('do_feed_rdf', 'do_feed_rdf', 10, 1);
   188 // WP Cron
   185 add_action('do_feed_rss', 'do_feed_rss', 10, 1);
   189 if ( !defined( 'DOING_CRON' ) )
   186 add_action('do_feed_rss2', 'do_feed_rss2', 10, 1);
   190 	add_action( 'sanitize_comment_cookies', 'wp_cron' );
   187 add_action('do_feed_atom', 'do_feed_atom', 10, 1);
   191 
   188 add_action('do_pings', 'do_all_pings', 10, 1);
   192 // 2 Actions 2 Furious
   189 add_action('do_robots', 'do_robots');
   193 add_action( 'do_feed_rdf',                'do_feed_rdf',             10, 1 );
   190 add_action('sanitize_comment_cookies', 'sanitize_comment_cookies');
   194 add_action( 'do_feed_rss',                'do_feed_rss',             10, 1 );
   191 add_action('admin_print_scripts', 'print_head_scripts', 20);
   195 add_action( 'do_feed_rss2',               'do_feed_rss2',            10, 1 );
   192 add_action('admin_print_footer_scripts', 'print_footer_scripts', 20);
   196 add_action( 'do_feed_atom',               'do_feed_atom',            10, 1 );
   193 add_action('admin_print_styles', 'print_admin_styles', 20);
   197 add_action( 'do_pings',                   'do_all_pings',            10, 1 );
   194 add_action('init', 'smilies_init', 5);
   198 add_action( 'do_robots',                  'do_robots'                      );
   195 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 );
   199 add_action( 'sanitize_comment_cookies',   'sanitize_comment_cookies'       );
   196 add_action( 'shutdown', 'wp_ob_end_flush_all', 1);
   200 add_action( 'admin_print_scripts',        'print_head_scripts',      20    );
   197 add_action( 'pre_post_update', 'wp_save_post_revision' );
   201 add_action( 'admin_print_footer_scripts', 'print_footer_scripts',    20    );
   198 add_action('publish_post', '_publish_post_hook', 5, 1);
   202 add_action( 'admin_print_styles',         'print_admin_styles',      20    );
   199 add_action('future_post', '_future_post_hook', 5, 2);
   203 add_action( 'init',                       'smilies_init',             5    );
   200 add_action('future_page', '_future_post_hook', 5, 2);
   204 add_action( 'plugins_loaded',             'wp_maybe_load_widgets',    0    );
   201 add_action('save_post', '_save_post_hook', 5, 2);
   205 add_action( 'plugins_loaded',             'wp_maybe_load_embeds',     0    );
   202 add_action('transition_post_status', '_transition_post_status', 5, 3);
   206 add_action( 'shutdown',                   'wp_ob_end_flush_all',      1    );
   203 add_action('comment_form', 'wp_comment_form_unfiltered_html_nonce');
   207 add_action( 'pre_post_update',            'wp_save_post_revision'          );
       
   208 add_action( 'publish_post',               '_publish_post_hook',       5, 1 );
       
   209 add_action( 'future_post',                '_future_post_hook',        5, 2 );
       
   210 add_action( 'future_page',                '_future_post_hook',        5, 2 );
       
   211 add_action( 'save_post',                  '_save_post_hook',          5, 2 );
       
   212 add_action( 'transition_post_status',     '_transition_post_status',  5, 3 );
       
   213 add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce'        );
       
   214 add_action( 'wp_scheduled_delete',        'wp_scheduled_delete' );
       
   215 
       
   216 // Post Thumbnail CSS class filtering
       
   217 add_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add'    );
       
   218 add_action( 'end_fetch_post_thumbnail_html',   '_wp_post_thumbnail_class_filter_remove' );
       
   219 
   204 // Redirect Old Slugs
   220 // Redirect Old Slugs
   205 add_action('template_redirect', 'wp_old_slug_redirect');
   221 add_action( 'template_redirect',  'wp_old_slug_redirect'       );
   206 add_action('edit_post', 'wp_check_for_changed_slugs');
   222 add_action( 'edit_post',          'wp_check_for_changed_slugs' );
   207 add_action('edit_form_advanced', 'wp_remember_old_slug');
   223 add_action( 'edit_form_advanced', 'wp_remember_old_slug'       );
   208 add_action('init', '_show_post_preview');
   224 add_action( 'init',               '_show_post_preview'         );
   209 
   225 
   210 add_filter('pre_option_gmt_offset','wp_timezone_override_offset');
   226 // Timezone
   211 
   227 add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );
   212 ?>