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 * |
5 * |
6 * If you need to remove a default hook, this file will |
6 * If you need to remove a default hook, this file will |
7 * give you the priority for which to use to remove the |
7 * give you the priority to use for removing the hook. |
8 * hook. |
|
9 * |
8 * |
10 * Not all of the default hooks are found in default-filters.php |
9 * Not all of the default hooks are found in this file. |
|
10 * For instance, administration-related hooks are located in |
|
11 * wp-admin/includes/admin-filters.php. |
|
12 * |
|
13 * If a hook should only be called from a specific context |
|
14 * (admin area, multisite environment…), please move it |
|
15 * to a more appropriate file instead. |
11 * |
16 * |
12 * @package WordPress |
17 * @package WordPress |
13 */ |
18 */ |
14 |
19 |
15 // Strip, trim, kses, special chars for string saves. |
20 // Strip, trim, kses, special chars for string saves. |
95 add_filter( 'pre_post_mime_type', 'sanitize_mime_type' ); |
100 add_filter( 'pre_post_mime_type', 'sanitize_mime_type' ); |
96 add_filter( 'post_mime_type', 'sanitize_mime_type' ); |
101 add_filter( 'post_mime_type', 'sanitize_mime_type' ); |
97 |
102 |
98 // Meta. |
103 // Meta. |
99 add_filter( 'register_meta_args', '_wp_register_meta_args_allowed_list', 10, 2 ); |
104 add_filter( 'register_meta_args', '_wp_register_meta_args_allowed_list', 10, 2 ); |
|
105 |
|
106 // Counts. |
|
107 add_action( 'admin_init', 'wp_schedule_update_user_counts' ); |
|
108 add_action( 'wp_update_user_counts', 'wp_schedule_update_user_counts', 10, 0 ); |
|
109 foreach ( array( 'user_register', 'deleted_user' ) as $action ) { |
|
110 add_action( $action, 'wp_maybe_update_user_counts', 10, 0 ); |
|
111 } |
100 |
112 |
101 // Post meta. |
113 // Post meta. |
102 add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' ); |
114 add_action( 'added_post_meta', 'wp_cache_set_posts_last_changed' ); |
103 add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' ); |
115 add_action( 'updated_post_meta', 'wp_cache_set_posts_last_changed' ); |
104 add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' ); |
116 add_action( 'deleted_post_meta', 'wp_cache_set_posts_last_changed' ); |
284 add_filter( 'the_posts', '_close_comments_for_old_posts', 10, 2 ); |
296 add_filter( 'the_posts', '_close_comments_for_old_posts', 10, 2 ); |
285 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); |
297 add_filter( 'comments_open', '_close_comments_for_old_post', 10, 2 ); |
286 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); |
298 add_filter( 'pings_open', '_close_comments_for_old_post', 10, 2 ); |
287 add_filter( 'editable_slug', 'urldecode' ); |
299 add_filter( 'editable_slug', 'urldecode' ); |
288 add_filter( 'editable_slug', 'esc_textarea' ); |
300 add_filter( 'editable_slug', 'esc_textarea' ); |
289 add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' ); |
|
290 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); |
301 add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri' ); |
291 add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); |
302 add_filter( 'xmlrpc_pingback_error', 'xmlrpc_pingback_error' ); |
292 add_filter( 'title_save_pre', 'trim' ); |
303 add_filter( 'title_save_pre', 'trim' ); |
293 |
304 |
294 add_action( 'transition_comment_status', '_clear_modified_cache_on_transition_comment_status', 10, 2 ); |
305 add_action( 'transition_comment_status', '_clear_modified_cache_on_transition_comment_status', 10, 2 ); |
330 add_action( 'wp_head', 'wp_site_icon', 99 ); |
341 add_action( 'wp_head', 'wp_site_icon', 99 ); |
331 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); |
342 add_action( 'wp_footer', 'wp_print_footer_scripts', 20 ); |
332 add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); |
343 add_action( 'template_redirect', 'wp_shortlink_header', 11, 0 ); |
333 add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); |
344 add_action( 'wp_print_footer_scripts', '_wp_footer_scripts' ); |
334 add_action( 'init', '_register_core_block_patterns_and_categories' ); |
345 add_action( 'init', '_register_core_block_patterns_and_categories' ); |
335 add_action( 'current_screen', '_load_remote_block_patterns' ); |
|
336 add_action( 'init', 'check_theme_switched', 99 ); |
346 add_action( 'init', 'check_theme_switched', 99 ); |
337 add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); |
347 add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); |
338 add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); |
348 add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); |
|
349 add_action( 'start_previewing_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) ); |
339 add_action( 'after_switch_theme', '_wp_menus_changed' ); |
350 add_action( 'after_switch_theme', '_wp_menus_changed' ); |
340 add_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
351 add_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
341 add_action( 'wp_print_styles', 'print_emoji_styles' ); |
352 add_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
353 add_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); |
342 |
354 |
343 if ( isset( $_GET['replytocom'] ) ) { |
355 if ( isset( $_GET['replytocom'] ) ) { |
344 add_filter( 'wp_robots', 'wp_robots_no_robots' ); |
356 add_filter( 'wp_robots', 'wp_robots_no_robots' ); |
345 } |
357 } |
346 |
358 |
388 add_action( 'do_all_pings', 'generic_ping', 10, 0 ); |
400 add_action( 'do_all_pings', 'generic_ping', 10, 0 ); |
389 add_action( 'do_robots', 'do_robots' ); |
401 add_action( 'do_robots', 'do_robots' ); |
390 add_action( 'do_favicon', 'do_favicon' ); |
402 add_action( 'do_favicon', 'do_favicon' ); |
391 add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 ); |
403 add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 ); |
392 add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' ); |
404 add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' ); |
393 add_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
394 add_action( 'admin_print_scripts', 'print_head_scripts', 20 ); |
|
395 add_action( 'admin_print_footer_scripts', '_wp_footer_scripts' ); |
|
396 add_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
397 add_action( 'admin_print_styles', 'print_admin_styles', 20 ); |
|
398 add_action( 'init', 'smilies_init', 5 ); |
405 add_action( 'init', 'smilies_init', 5 ); |
399 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); |
406 add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); |
400 add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); |
407 add_action( 'plugins_loaded', 'wp_maybe_load_embeds', 0 ); |
401 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); |
408 add_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); |
402 // Create a revision whenever a post is updated. |
409 // Create a revision whenever a post is updated. |
403 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); |
410 add_action( 'post_updated', 'wp_save_post_revision', 10, 1 ); |
404 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); |
411 add_action( 'publish_post', '_publish_post_hook', 5, 1 ); |
405 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); |
412 add_action( 'transition_post_status', '_transition_post_status', 5, 3 ); |
406 add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); |
413 add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); |
407 add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); |
414 add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); |
408 add_action( 'admin_init', 'send_frame_options_header', 10, 0 ); |
|
409 add_action( 'welcome_panel', 'wp_welcome_panel' ); |
|
410 |
415 |
411 // Privacy. |
416 // Privacy. |
412 add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' ); |
417 add_action( 'user_request_action_confirmed', '_wp_privacy_account_request_confirmed' ); |
413 add_action( 'user_request_action_confirmed', '_wp_privacy_send_request_confirmation_notification', 12 ); // After request marked as completed. |
418 add_action( 'user_request_action_confirmed', '_wp_privacy_send_request_confirmation_notification', 12 ); // After request marked as completed. |
414 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' ); |
419 add_filter( 'wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' ); |
451 add_action( 'wp_head', 'wp_post_preview_js', 1 ); |
456 add_action( 'wp_head', 'wp_post_preview_js', 1 ); |
452 |
457 |
453 // Timezone. |
458 // Timezone. |
454 add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_offset' ); |
459 add_filter( 'pre_option_gmt_offset', 'wp_timezone_override_offset' ); |
455 |
460 |
456 // Admin color schemes. |
|
457 add_action( 'admin_init', 'register_admin_color_schemes', 1 ); |
|
458 add_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' ); |
|
459 |
|
460 // If the upgrade hasn't run yet, assume link manager is used. |
461 // If the upgrade hasn't run yet, assume link manager is used. |
461 add_filter( 'default_option_link_manager_enabled', '__return_true' ); |
462 add_filter( 'default_option_link_manager_enabled', '__return_true' ); |
462 |
463 |
463 // This option no longer exists; tell plugins we always support auto-embedding. |
464 // This option no longer exists; tell plugins we always support auto-embedding. |
464 add_filter( 'pre_option_embed_autourls', '__return_true' ); |
465 add_filter( 'pre_option_embed_autourls', '__return_true' ); |
511 /** |
512 /** |
512 * Filters formerly mixed into wp-includes. |
513 * Filters formerly mixed into wp-includes. |
513 */ |
514 */ |
514 // Theme. |
515 // Theme. |
515 add_action( 'setup_theme', 'create_initial_theme_features', 0 ); |
516 add_action( 'setup_theme', 'create_initial_theme_features', 0 ); |
|
517 add_action( 'setup_theme', '_add_default_theme_supports', 1 ); |
516 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); |
518 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); |
517 add_action( 'wp_head', '_custom_logo_header_styles' ); |
519 add_action( 'wp_head', '_custom_logo_header_styles' ); |
518 add_action( 'plugins_loaded', '_wp_customize_include' ); |
520 add_action( 'plugins_loaded', '_wp_customize_include' ); |
519 add_action( 'transition_post_status', '_wp_customize_publish_changeset', 10, 3 ); |
521 add_action( 'transition_post_status', '_wp_customize_publish_changeset', 10, 3 ); |
520 add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' ); |
522 add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' ); |
560 add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 ); |
562 add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 ); |
561 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); |
563 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' ); |
562 add_action( 'enqueue_block_editor_assets', 'enqueue_editor_block_styles_assets' ); |
564 add_action( 'enqueue_block_editor_assets', 'enqueue_editor_block_styles_assets' ); |
563 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); |
565 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); |
564 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_format_library_assets' ); |
566 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_format_library_assets' ); |
565 add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' ); |
567 add_action( 'enqueue_block_editor_assets', 'wp_enqueue_global_styles_css_custom_properties' ); |
566 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); |
568 add_filter( 'wp_print_scripts', 'wp_just_in_time_script_localization' ); |
567 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); |
569 add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' ); |
568 add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); |
570 add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 ); |
569 add_action( 'admin_head', 'wp_check_widget_editor_deps' ); |
571 add_action( 'admin_head', 'wp_check_widget_editor_deps' ); |
570 |
572 |
571 // Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. |
573 // Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494. |
572 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); |
574 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); |
573 add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); |
575 add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); |
574 |
576 |
|
577 // SVG filters like duotone have to be loaded at the beginning of the body in both admin and the front-end. |
|
578 add_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); |
|
579 add_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' ); |
|
580 |
575 add_action( 'wp_default_styles', 'wp_default_styles' ); |
581 add_action( 'wp_default_styles', 'wp_default_styles' ); |
576 add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); |
582 add_filter( 'style_loader_src', 'wp_style_loader_src', 10, 2 ); |
577 |
583 |
578 add_action( 'wp_head', 'wp_maybe_inline_styles', 1 ); // Run for styles enqueued in <head>. |
584 add_action( 'wp_head', 'wp_maybe_inline_styles', 1 ); // Run for styles enqueued in <head>. |
579 add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer. |
585 add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer. |
580 |
586 |
581 add_action( 'admin_footer-post.php', 'wp_add_iframed_editor_assets_html' ); |
587 /* |
582 add_action( 'admin_footer-post-new.php', 'wp_add_iframed_editor_assets_html' ); |
588 * Disable "Post Attributes" for wp_navigation post type. The attributes are |
|
589 * also conditionally enabled when a site has custom templates. Block Theme |
|
590 * templates can be available for every post type. |
|
591 */ |
|
592 add_filter( 'theme_wp_navigation_templates', '__return_empty_array' ); |
583 |
593 |
584 // Taxonomy. |
594 // Taxonomy. |
585 add_action( 'init', 'create_initial_taxonomies', 0 ); // Highest priority. |
595 add_action( 'init', 'create_initial_taxonomies', 0 ); // Highest priority. |
586 add_action( 'change_locale', 'create_initial_taxonomies' ); |
596 add_action( 'change_locale', 'create_initial_taxonomies' ); |
587 |
597 |
602 add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); |
612 add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 ); |
603 |
613 |
604 // Widgets. |
614 // Widgets. |
605 add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 ); |
615 add_action( 'after_setup_theme', 'wp_setup_widgets_block_editor', 1 ); |
606 add_action( 'init', 'wp_widgets_init', 1 ); |
616 add_action( 'init', 'wp_widgets_init', 1 ); |
|
617 add_action( 'change_locale', array( 'WP_Widget_Media', 'reset_default_labels' ) ); |
607 |
618 |
608 // Admin Bar. |
619 // Admin Bar. |
609 // Don't remove. Wrong way to disable. |
620 // Don't remove. Wrong way to disable. |
610 add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); |
621 add_action( 'template_redirect', '_wp_admin_bar_init', 0 ); |
611 add_action( 'admin_init', '_wp_admin_bar_init' ); |
622 add_action( 'admin_init', '_wp_admin_bar_init' ); |
623 // Embeds. |
634 // Embeds. |
624 add_action( 'rest_api_init', 'wp_oembed_register_route' ); |
635 add_action( 'rest_api_init', 'wp_oembed_register_route' ); |
625 add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 ); |
636 add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 ); |
626 |
637 |
627 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); |
638 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); |
628 add_action( 'wp_head', 'wp_oembed_add_host_js' ); |
639 add_action( 'wp_head', 'wp_oembed_add_host_js' ); // Back-compat for sites disabling oEmbed host JS by removing action. |
|
640 add_filter( 'embed_oembed_html', 'wp_maybe_enqueue_oembed_host_js' ); |
629 |
641 |
630 add_action( 'embed_head', 'enqueue_embed_scripts', 1 ); |
642 add_action( 'embed_head', 'enqueue_embed_scripts', 1 ); |
631 add_action( 'embed_head', 'print_emoji_detection_script' ); |
643 add_action( 'embed_head', 'print_emoji_detection_script' ); |
632 add_action( 'embed_head', 'print_embed_styles' ); |
644 add_action( 'embed_head', 'print_embed_styles' ); |
633 add_action( 'embed_head', 'wp_print_head_scripts', 20 ); |
645 add_action( 'embed_head', 'wp_print_head_scripts', 20 ); |
658 // Capabilities. |
670 // Capabilities. |
659 add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 ); |
671 add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 ); |
660 add_filter( 'user_has_cap', 'wp_maybe_grant_resume_extensions_caps', 1 ); |
672 add_filter( 'user_has_cap', 'wp_maybe_grant_resume_extensions_caps', 1 ); |
661 add_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps', 1, 4 ); |
673 add_filter( 'user_has_cap', 'wp_maybe_grant_site_health_caps', 1, 4 ); |
662 |
674 |
663 // Block Templates CPT and Rendering |
675 // Block templates post type and rendering. |
664 add_filter( 'render_block_context', '_block_template_render_without_post_block_context' ); |
676 add_filter( 'render_block_context', '_block_template_render_without_post_block_context' ); |
665 add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 ); |
677 add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 ); |
|
678 add_action( 'save_post_wp_template_part', 'wp_set_unique_slug_on_create_template_part' ); |
666 add_action( 'wp_footer', 'the_block_template_skip_link' ); |
679 add_action( 'wp_footer', 'the_block_template_skip_link' ); |
667 add_action( 'setup_theme', 'wp_enable_block_templates' ); |
680 add_action( 'setup_theme', 'wp_enable_block_templates' ); |
|
681 add_action( 'wp_loaded', '_add_template_loader_filters' ); |
668 |
682 |
669 unset( $filter, $action ); |
683 unset( $filter, $action ); |