remove_filter() - WordPress 函数参考中文文档

返回介绍

remove_filter()

发布于 2017-09-11 字数5876 浏览 907 评论 0

remove_filter( string $tag,  callable $function_to_remove,  int $priority = 10 )

Removes a function from a specified filter hook.


描述

This function removes a function attached to a specified filter hook. This method can be used to remove default functions attached to a specific filter hook and possibly replace them with a substitute.

To remove a hook, the $function_to_remove and $priority arguments must match when the hook was added. This goes for both filters and actions. No warning will be given on removal failure.


参数

$tag

(string)
(Required)
The filter hook to which the function to be removed is hooked.

$function_to_remove

(callable)
(Required)
The name of the function which should be removed.

$priority

(int)
(Optional)
The priority of the function.

Default value: 10


返回值

(bool) Whether the function existed before it was removed.


源代码

File: wp-includes/plugin.php

function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
	global $wp_filter;

	$r = false;
	if ( isset( $wp_filter[ $tag ] ) ) {
		$r = $wp_filter[ $tag ]->remove_filter( $tag, $function_to_remove, $priority );
		if ( ! $wp_filter[ $tag ]->callbacks ) {
			unset( $wp_filter[ $tag ] );
		}
	}

	return $r;
}

更新日志

Version 描述
1.2.0 Introduced.

相关函数

Used By

  • wp-includes/widgets/class-wp-widget-media-video.php:
    WP_Widget_Media_Video::render_media()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::save_changeset_post()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::check_read_post_permission()
  • wp-includes/class-wp-taxonomy.php:
    WP_Taxonomy::remove_hooks()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::insert_auto_draft_post()
  • wp-includes/post.php:
    _filter_query_attachment_filenames()
  • wp-includes/meta.php:
    unregister_meta_key()
  • wp-includes/class-wp-metadata-lazyloader.php:
    WP_Metadata_Lazyloader::reset_queue()
  • wp-includes/class-wp-customize-widgets.php:
    WP_Customize_Widgets::render_widget_partial()
  • wp-includes/class-wp-customize-nav-menus.php:
    WP_Customize_Nav_Menus::customize_register()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_crop_image()
  • wp-admin/includes/class-language-pack-upgrader.php:
    Language_Pack_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-theme-upgrader.php:
    Theme_Upgrader::check_parent_theme_filter()
  • wp-admin/includes/class-theme-upgrader.php:
    Theme_Upgrader::install()
  • wp-admin/includes/class-theme-upgrader.php:
    Theme_Upgrader::upgrade()
  • wp-admin/includes/class-theme-upgrader.php:
    Theme_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::install()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::upgrade()
  • wp-includes/option.php:
    unregister_setting()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_send_attachment_to_editor()
  • wp-admin/includes/bookmark.php:
    wp_link_manager_disabled_message()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::stop_previewing_theme()
  • wp-includes/kses.php:
    kses_remove_filters()
  • wp-includes/plugin.php:
    remove_action()
  • wp-includes/ms-functions.php:
    welcome_user_msg_filter()
  • wp-includes/class-wp-customize-widgets.php:
    WP_Customize_Widgets::stop_capturing_option_updates()
  • wp-includes/class-wp-editor.php:
    _WP_Editors::editor()
  • Show 25 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example

    
    remove_filter( 'the_content', 'wpautop' );
    
    
    foreach ( array( 'the_content', 'the_title', 'comment_text' ) as $hook )
        remove_filter( $hook, 'capital_P_dangit' );
    

    If a filter has been added from within a class, for example by a plugin, removing it will require accessing the class variable.

    
    global $my_class;
    remove_filter( 'the_content', array($my_class, 'class_filter_function') );
    

    It is also worth noting that you may need to prioritise the removal of the filter to a hook that occurs after the filter is added. You cannot successfully remove the filter before it has been added.

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!