1 <?php |
1 <?php |
2 /** |
2 /** |
3 * Sets up the default filters and actions for most |
3 * Sets up the default filters and actions for most |
4 * of the WordPress hooks. |
4 * of the WordPress hooks. |
|
5 * |
|
6 * This file is loaded very early in the bootstrap which |
|
7 * means many functions are not yet available and site |
|
8 * information such as if this is multisite is unknown. |
|
9 * Before using functions besides `add_filter` and |
|
10 * `add_action`, verify things will work as expected. |
5 * |
11 * |
6 * If you need to remove a default hook, this file will |
12 * If you need to remove a default hook, this file will |
7 * give you the priority to use for removing the hook. |
13 * give you the priority to use for removing the hook. |
8 * |
14 * |
9 * Not all of the default hooks are found in this file. |
15 * Not all of the default hooks are found in this file. |
15 * to a more appropriate file instead. |
21 * to a more appropriate file instead. |
16 * |
22 * |
17 * @package WordPress |
23 * @package WordPress |
18 */ |
24 */ |
19 |
25 |
|
26 // Don't load directly. |
|
27 if ( ! defined( 'ABSPATH' ) ) { |
|
28 die( '-1' ); |
|
29 } |
|
30 |
20 // Strip, trim, kses, special chars for string saves. |
31 // Strip, trim, kses, special chars for string saves. |
21 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 ) { |
32 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 ) { |
22 add_filter( $filter, 'sanitize_text_field' ); |
33 add_filter( $filter, 'sanitize_text_field' ); |
23 add_filter( $filter, 'wp_filter_kses' ); |
34 add_filter( $filter, 'wp_filter_kses' ); |
24 add_filter( $filter, '_wp_specialchars', 30 ); |
35 add_filter( $filter, '_wp_specialchars', 30 ); |
145 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) { |
156 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) { |
146 add_filter( $filter, 'convert_invalid_entities' ); |
157 add_filter( $filter, 'convert_invalid_entities' ); |
147 add_filter( $filter, 'balanceTags', 50 ); |
158 add_filter( $filter, 'balanceTags', 50 ); |
148 } |
159 } |
149 |
160 |
150 // Add proper rel values for links with target. |
|
151 add_action( 'init', 'wp_init_targeted_link_rel_filters' ); |
|
152 |
|
153 // Format strings for display. |
161 // Format strings for display. |
154 foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'document_title', 'widget_title' ) as $filter ) { |
162 foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'document_title', 'widget_title' ) as $filter ) { |
155 add_filter( $filter, 'wptexturize' ); |
163 add_filter( $filter, 'wptexturize' ); |
156 add_filter( $filter, 'convert_chars' ); |
164 add_filter( $filter, 'convert_chars' ); |
157 add_filter( $filter, 'esc_html' ); |
165 add_filter( $filter, 'esc_html' ); |
187 // Display filters. |
195 // Display filters. |
188 add_filter( 'the_title', 'wptexturize' ); |
196 add_filter( 'the_title', 'wptexturize' ); |
189 add_filter( 'the_title', 'convert_chars' ); |
197 add_filter( 'the_title', 'convert_chars' ); |
190 add_filter( 'the_title', 'trim' ); |
198 add_filter( 'the_title', 'trim' ); |
191 |
199 |
|
200 add_filter( 'the_content', 'apply_block_hooks_to_content_from_post_object', 8 ); // BEFORE do_blocks(). |
192 add_filter( 'the_content', 'do_blocks', 9 ); |
201 add_filter( 'the_content', 'do_blocks', 9 ); |
193 add_filter( 'the_content', 'wptexturize' ); |
202 add_filter( 'the_content', 'wptexturize' ); |
194 add_filter( 'the_content', 'convert_smilies', 20 ); |
203 add_filter( 'the_content', 'convert_smilies', 20 ); |
195 add_filter( 'the_content', 'wpautop' ); |
204 add_filter( 'the_content', 'wpautop' ); |
196 add_filter( 'the_content', 'shortcode_unautop' ); |
205 add_filter( 'the_content', 'shortcode_unautop' ); |
347 add_action( 'wp_head', 'wp_generator' ); |
356 add_action( 'wp_head', 'wp_generator' ); |
348 add_action( 'wp_head', 'rel_canonical' ); |
357 add_action( 'wp_head', 'rel_canonical' ); |
349 add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); |
358 add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 ); |
350 add_action( 'wp_head', 'wp_custom_css_cb', 101 ); |
359 add_action( 'wp_head', 'wp_custom_css_cb', 101 ); |
351 add_action( 'wp_head', 'wp_site_icon', 99 ); |
360 add_action( 'wp_head', 'wp_site_icon', 99 ); |
|
361 add_action( 'wp_footer', 'wp_print_speculation_rules' ); |
352 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); |
362 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); |
353 add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); |
363 add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); |
354 add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); |
364 add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); |
355 add_action( 'init', '_register_core_block_patterns_and_categories' ); |
365 add_action( 'init', '_register_core_block_patterns_and_categories' ); |
356 add_action( 'init', 'check_theme_switched', 99 ); |
366 add_action( 'init', 'check_theme_switched', 99 ); |
360 add_action( 'after_switch_theme', '_wp_menus_changed' ); |
370 add_action( 'after_switch_theme', '_wp_menus_changed' ); |
361 add_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
371 add_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
362 add_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' ); |
372 add_action( 'wp_enqueue_scripts', 'wp_enqueue_emoji_styles' ); |
363 add_action( 'wp_print_styles', 'print_emoji_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_emoji_styles(). |
373 add_action( 'wp_print_styles', 'print_emoji_styles' ); // Retained for backwards-compatibility. Unhooked by wp_enqueue_emoji_styles(). |
364 |
374 |
365 if ( isset( $_GET['replytocom'] ) ) { |
375 if ( |
|
376 // Comment reply link. |
|
377 isset( $_GET['replytocom'] ) |
|
378 || |
|
379 // Unapproved comment preview. |
|
380 ( isset( $_GET['unapproved'] ) && isset( $_GET['moderation-hash'] ) ) |
|
381 ) { |
366 add_filter( 'wp_robots', 'wp_robots_no_robots' ); |
382 add_filter( 'wp_robots', 'wp_robots_no_robots' ); |
367 } |
383 } |
368 |
384 |
369 // Login actions. |
385 // Login actions. |
370 add_action( 'login_head', 'wp_robots', 1 ); |
386 add_action( 'login_head', 'wp_robots', 1 ); |
372 add_action( 'login_head', 'wp_print_head_scripts', 9 ); |
388 add_action( 'login_head', 'wp_print_head_scripts', 9 ); |
373 add_action( 'login_head', 'print_admin_styles', 9 ); |
389 add_action( 'login_head', 'print_admin_styles', 9 ); |
374 add_action( 'login_head', 'wp_site_icon', 99 ); |
390 add_action( 'login_head', 'wp_site_icon', 99 ); |
375 add_action( 'login_footer', 'wp_print_footer_scripts', 20 ); |
391 add_action( 'login_footer', 'wp_print_footer_scripts', 20 ); |
376 add_action( 'login_init', 'send_frame_options_header', 10, 0 ); |
392 add_action( 'login_init', 'send_frame_options_header', 10, 0 ); |
|
393 add_action( 'login_init', 'wp_admin_headers' ); |
377 |
394 |
378 // Feed generator tags. |
395 // Feed generator tags. |
379 foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) { |
396 foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) { |
380 add_action( $action, 'the_generator' ); |
397 add_action( $action, 'the_generator' ); |
381 } |
398 } |
532 add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_dependent_auto_drafts', 20, 3 ); |
549 add_action( 'transition_post_status', '_wp_keep_alive_customize_changeset_dependent_auto_drafts', 20, 3 ); |
533 |
550 |
534 // Block Theme Previews. |
551 // Block Theme Previews. |
535 add_action( 'plugins_loaded', 'wp_initialize_theme_preview_hooks', 1 ); |
552 add_action( 'plugins_loaded', 'wp_initialize_theme_preview_hooks', 1 ); |
536 |
553 |
|
554 // Site preview for Classic Theme. |
|
555 add_action( 'init', 'wp_initialize_site_preview_hooks', 1 ); |
|
556 |
537 // Calendar widget cache. |
557 // Calendar widget cache. |
538 add_action( 'save_post', 'delete_get_calendar_cache' ); |
558 add_action( 'save_post', 'delete_get_calendar_cache' ); |
539 add_action( 'delete_post', 'delete_get_calendar_cache' ); |
559 add_action( 'delete_post', 'delete_get_calendar_cache' ); |
540 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' ); |
560 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' ); |
541 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' ); |
561 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' ); |
562 add_action( 'set_current_user', 'kses_init' ); |
582 add_action( 'set_current_user', 'kses_init' ); |
563 |
583 |
564 // Script Loader. |
584 // Script Loader. |
565 add_action( 'wp_default_scripts', 'wp_default_scripts' ); |
585 add_action( 'wp_default_scripts', 'wp_default_scripts' ); |
566 add_action( 'wp_default_scripts', 'wp_default_packages' ); |
586 add_action( 'wp_default_scripts', 'wp_default_packages' ); |
|
587 add_action( 'wp_default_scripts', 'wp_default_script_modules' ); |
567 |
588 |
568 add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); |
589 add_action( 'wp_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); |
569 add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); |
590 add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); |
570 add_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' ); |
591 add_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' ); |
571 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); |
592 add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 ); |
572 add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); |
593 add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); |
|
594 add_action( 'enqueue_block_assets', 'wp_enqueue_classic_theme_styles' ); |
573 add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); |
595 add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); |
574 add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 ); |
596 add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 ); |
575 /* |
597 /* |
576 * `wp_enqueue_registered_block_scripts_and_styles` is bound to both |
598 * `wp_enqueue_registered_block_scripts_and_styles` is bound to both |
577 * `enqueue_block_editor_assets` and `enqueue_block_assets` hooks |
599 * `enqueue_block_editor_assets` and `enqueue_block_assets` hooks |
592 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); |
614 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); |
593 add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); |
615 add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); |
594 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); |
616 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); |
595 add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); |
617 add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); |
596 add_action( 'admin_head', 'wp_check_widget_editor_deps' ); |
618 add_action( 'admin_head', 'wp_check_widget_editor_deps' ); |
597 add_filter( 'block_editor_settings_all', 'wp_add_editor_classic_theme_styles' ); |
|
598 |
619 |
599 // Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. |
620 // Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. |
600 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); |
621 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); |
601 add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); |
622 add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); |
602 |
623 |
603 // Global styles custom CSS. |
|
604 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles_custom_css' ); |
|
605 |
|
606 // Block supports, and other styles parsed and stored in the Style Engine. |
624 // Block supports, and other styles parsed and stored in the Style Engine. |
607 add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' ); |
625 add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' ); |
608 add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 ); |
626 add_action( 'wp_footer', 'wp_enqueue_stored_styles', 1 ); |
609 |
627 |
610 add_action( 'wp_default_styles', 'wp_default_styles' ); |
628 add_action( 'wp_default_styles', 'wp_default_styles' ); |
611 add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); |
629 add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); |
612 |
630 |
|
631 add_action( 'wp_head', 'wp_print_auto_sizes_contain_css_fix', 1 ); |
613 add_action( 'wp_head', 'wp_maybe_inline_styles', 1 ); // Run for styles enqueued in <head>. |
632 add_action( 'wp_head', 'wp_maybe_inline_styles', 1 ); // Run for styles enqueued in <head>. |
614 add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer. |
633 add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer. |
615 |
634 |
616 /* |
635 /* |
617 * Block specific actions and filters. |
636 * Block specific actions and filters. |
755 |
774 |
756 // Add ignoredHookedBlocks metadata attribute to the template and template part post types. |
775 // Add ignoredHookedBlocks metadata attribute to the template and template part post types. |
757 add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' ); |
776 add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' ); |
758 add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' ); |
777 add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' ); |
759 |
778 |
760 // Update ignoredHookedBlocks postmeta for wp_navigation post type. |
779 // Update ignoredHookedBlocks postmeta for some post types. |
|
780 add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' ); |
|
781 add_filter( 'rest_pre_insert_post', 'update_ignored_hooked_blocks_postmeta' ); |
|
782 add_filter( 'rest_pre_insert_wp_block', 'update_ignored_hooked_blocks_postmeta' ); |
761 add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' ); |
783 add_filter( 'rest_pre_insert_wp_navigation', 'update_ignored_hooked_blocks_postmeta' ); |
762 |
784 |
763 // Inject hooked blocks into the wp_navigation post type REST response. |
785 // Inject hooked blocks into the Posts endpoint REST response for some given post types. |
|
786 add_filter( 'rest_prepare_page', 'insert_hooked_blocks_into_rest_response', 10, 2 ); |
|
787 add_filter( 'rest_prepare_post', 'insert_hooked_blocks_into_rest_response', 10, 2 ); |
|
788 add_filter( 'rest_prepare_wp_block', 'insert_hooked_blocks_into_rest_response', 10, 2 ); |
764 add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 ); |
789 add_filter( 'rest_prepare_wp_navigation', 'insert_hooked_blocks_into_rest_response', 10, 2 ); |
765 |
790 |
766 unset( $filter, $action ); |
791 unset( $filter, $action ); |