返回介绍

remove_filter()

发布于 2017-09-11 10:08:17 字数 5874 浏览 1091 评论 0 收藏 0

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

Removes a function from a specified filter hook.


description

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;
}

更新日志

Versiondescription
1.2.0Introduced.

相关函数

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文