WordPress 过滤器

知更鸟
知更鸟
站长
2322
文章
0
粉丝
WordPress 开发评论667阅读模式

在WordPress中,过滤器使开发人员能够在WordPress页面加载时拦截和修改数据,然后将其发送到浏览器或将其保存到数据库。

了解过滤器的工作原理并不是那么容易,部分原因是这个概念很难可视化,也因为过滤器经常与WordPress操作混淆。然而,这是一个需要掌握的重要概念,因为过滤器是开发人员与WordPress交互的最常见方式之一。

出于这些原因,此过滤器备忘单非常适合刚开始使用过滤器的人。此备忘单提供了对过滤器功能及其工作原理的深入了解,并提供了在WordPress开发中使用过滤器的快速参考指南。

WordPress Basics: Hooks & Functions

让我们从WordPress如何工作的基本概述开始,以帮助您了解过滤器在WordPress核心代码中的位置的上下文。

WordPress页面由一大堆函数和数据库查询组成,WordPress核心代码和主题协同工作以输出文本,图像,样式表和其他资源。浏览器在处理时解释所有这些数据,然后将其一起显示为一个网页。

在整个核心代码中都是钩子,它们基本上是占位符,开发人员可以使用它们来“挂钩”到WordPress中,并插入自己的自定义代码,以便在页面加载时进行处理。

有两种类型的挂钩:筛选器操作

通过筛选器挂钩,您可以在处理数据时拦截和修改数据。基本上,过滤器允许您在进入浏览器之前操作从数据库出来的数据,或者在进入数据库之前从浏览器出来的数据。例如,您可能希望执行一些简单操作,例如在所有博客文章的标题前面附加一个单词,或者过滤掉帖子评论中的不良语言。

另一方面,操作挂钩允许您在页面处理和加载的特定点添加额外的功能。例如,您可能希望向页面添加促销弹出消息或在页脚中显示版权消息。

基本上,过滤器钩子会改变东西而动作钩子会做一些事情

WordPress提供了大量内置的过滤器钩子,用于WordPress开发。但是,您也可以使用该函数创建自己的筛选器挂钩,我稍后将向您展示如何使用该函数。apply_filters()

功能

为了使用WordPress钩子,你需要编写一个函数

函数是一段自定义代码,用于指定某些事情将如何发生。例如,您可以编写函数代码来查询数据、输出内容或执行许多其他任务。

在WordPress中,如果你想在主题中“更改内容”,你需要编写一个使用过滤器钩子的过滤器函数。

使用筛选器:示例

将自己的过滤器添加到WordPress涉及三个基本步骤:

  1. 编写用于筛选数据的 PHP 函数。
  2. 通过调用来连接到WordPress中现有和适当的过滤器钩子。add_filter()
  3. 将PHP函数放在WordPress /插件文件中并激活它。

1. 创建过滤器函数

假设您想过滤掉您网站上博客文章评论中的不良语言。

第一步是编写一个函数来过滤您的WordPress评论,并删除不良语言或将其替换为其他单词。例如,您可以通过创建以下PHP函数,将不希望在网站上显示的坏词列表放在一起,并用审查标志替换它们:

function filter_bad_languge( $content ) {
$badwords = array('fopdoogle', 'gobermouch', 'yaldson');
$content = str_ireplace( $badwords, '{censored}', $content );
return $content;
}

以下是上述代码的细分:

  1. 这是挂接到筛选器挂钩中的代码。很容易发现自定义函数,因为它总是以 开头。function()
  2. filter_badlanguge是筛选器函数的名称。
  3. $content是函数的单个参数。
  4. $badwords = array('fopdoogle','gobermouch','yaldson');是函数执行的第一个工作。具体来说,它创建了一个名为 fopdoogle、gobermouch 和 yaldson 的数组,并将单词 fopdoogle、gobermouch 和 yaldson 添加到该数组中。$badwords
  5. str_ireplace循环遍历您的内容,搜索数组中存储的任何单词,将它们替换为“{censored}”,然后将它们返回到 $badwords$content
  6. return在这里非常重要:这是函数如何将过滤后的内容返回到WordPress核心。

2. 使用过滤器挂钩

一旦你对你的过滤器进行了编码,你需要使用钩子调用将其“挂钩”到WordPress核心中。为此,您可以使用:add_filter()

add_filter( 'comment_text', 'filter_bad_language' );

下面是上述代码的含义:

  1. comment_text是WordPress提供的过滤器钩子的名称,我们希望我们的过滤器应用于它,即我们希望我们的过滤器在博客文章评论上工作。
  2. filter_badlanguage是我们要用于筛选的函数的名称。

3. 安装和激活过滤器

为了让过滤器挂钩正常工作的最后一步是添加函数并在PHP文件中一起调用。继续我们的不良语言示例,我们将像这样组合代码:add_filter()

function filter_bad_languge( $content ) {
$badwords = array('fopdoogle', 'gobermouch', 'yaldson');
$content = str_ireplace( $badwords, '{censored}', $content );
return $content;
}
add_filter( 'comment_text', 'filter_bad_language' );

通常,您可以添加函数并调用主题的函数.php使用子主题的文件,或者创建一个新插件。如何做到这一点超出了本文的范围,但我强烈建议您在WordPress开发人员手册中阅读如何创建子主题以及如何创建插件

如果您决定在插件中使用您的函数,则需要安装并激活新创建的插件才能使您的代码正常工作。

使用自定义筛选器挂钩

WordPress插件开发中的一个有用功能是能够创建自定义钩子以用于插件,以便其他开发人员可以扩展和修改它们。

自定义钩子的创建和调用方式与创建和调用WordPress核心钩子的方式相同。

创建和使用您自己的自定义筛选器挂钩涉及两个基本步骤:

  1. 使用 apply_filters() 将自定义筛选器挂钩添加到现有函数。
  2. 您(或其他开发人员)编写了一个挂接到自定义筛选器挂钩中的自定义函数。

创建筛选器挂钩

若要创建自定义挂钩,请在代码中添加要放置挂钩的位置。apply_filters()

例如,使用上面的不良语言示例,假设我们希望允许其他开发人员添加新单词以进行审查。您可以通过更新函数以包含过滤器来执行此操作:

function filter_bad_languge( $content ) {
$badwords = array('fopdoogle', 'gobermouch', 'yaldson');
$badwords = apply_filters('add_bad_language_filter', $badwords );
$content = str_ireplace( $badwords, '{censored}', $content );
return $content;
}

add_badlanguage_filter成为可用于修改被删失单词列表的筛选器挂钩,并且是要返回的默认值。$content

使用自定义筛选器挂钩

那么,当其他开发人员使用此自定义筛选器时会发生什么情况呢?好吧,他们可以删除不好的单词,更改他们的名字,添加新单词等。在这个例子中,我只想添加一个新的审查词:

function add_new_bad_words($profanities) {
$extra_bad_words = array('sard', 'bescumber');
$profanities = array_merge($extra_bad_words, $profanities);
return $profanities;
}
add_filter('add_bad_language_filter', 'add_new_bad_words');

当add_new_bad_words函数显示坏词列表时,我们现在将看到以下内容:

  • 福普杜格尔
  • 戈伯穆赫
  • 亚尔德森
  • 萨德
  • 贝斯坎伯

(如果你还没有用谷歌搜索这些听起来不寻常的单词,它们是古老的英语诅咒词。

命名冲突

由于您可以为自定义钩子指定所需的任何名称,因此请务必为钩子名称添加前缀,以避免与其他插件发生冲突。

例如,简单地称为post_body的筛选器挂钩更有可能被其他开发人员使用。这意味着如果WordPress用户安装并激活您的插件,而另一个开发人员插件使用相似名称的钩子,则会导致错误。

建议您在自定义钩子前面加上姓名或公司的缩短版本,即 .wbb_add_bad_language_filter

从过滤器中解钩函数

在某些情况下,您可能希望您的插件禁用内置于WordPress中的过滤器或由冲突的插件使用的过滤器。您可以使用 remove_filter() 执行此操作

该函数有三个参数:筛选器挂钩的名称、应删除的函数的名称和优先级(仅当函数最初挂接到筛选器时设置了优先级时才是必需的)。remove_filter()

因此,要删除我之前创建的add_new_bad_words,我将使用:

remove_filter( 'add_new_bad_words', 'add_bad_language_filter');

然后,代码输出将恢复为我在原始函数中指定的值。apply_filters()

过滤器挂钩参考指南

WordPress有数百个内置的过滤器钩子,开发人员可以使用它们来挂钩到核心代码中。

WordPress Codex提供了有关如何使用过滤器钩子的指南,它使用以下类别列出了过滤器钩子:

  • 帖子、页面和附件(上传)筛选器
  • 注释、引用通告和 Ping 筛选器
  • 类别和术语筛选器
  • 链接过滤器
  • 日期和时间筛选器
  • 作者和用户过滤器
  • 博客过滤器
  • 博客信息和选项过滤器
  • 常规文本筛选器
  • 管理过滤器
  • 富文本编辑器筛选器
  • 模板过滤器
  • 注册和登录过滤器
  • 重定向/重写过滤器
  • WP_Query过滤器
  • 媒体过滤器
  • 高级WordPress过滤器
  • 部件
  • 管理栏

其中许多筛选器挂钩分为两个子类别:数据库读取数据库写入。这取决于函数是在页面上显示内容之前从数据库读取数据,还是在将数据保存到数据库之前编写代码。

在WordPress中使用钩子开始计算出您需要将代码“挂钩”到哪个钩子,然后编写一个函数来修改所需的数据。

帖子、页面和附件(上传)筛选器

数据库读取

  • attachment_fields_to_edit– 应用于编辑附件时要显示的表单域。
  • attachment_icon– 应用于函数中附件的图标。get_attachment_icon
  • attachment_innerHTML– 应用于要用于附件的标题(如果函数中没有图标)。get_attachment_innerHTML
  • author_edit_pre– 在显示编辑之前应用于帖子作者。
  • body_class– 应用于 HTML 元素的类。在get_body_class函数中调用。<body>
  • content_edit_pre– 应用于在显示之前发布内容以进行编辑。
  • content_filtered_edit_pre– 应用于在显示之前过滤以进行编辑的帖子内容。
  • excerpt_edit_pre– 应用于显示之前的帖子摘录以进行编辑。
  • date_edit_pre– 应用于显示之前的发布日期以进行编辑。
  • date_gmt_edit_pre– 应用于显示之前的发布日期以进行编辑。
  • get_attached_file– 应用于函数检索到的附件信息。get_attached_file
  • get_enclosed – Applied to the enclosures list for a post by the get_enclosed function.
  • get_pages – Applied to the list of pages returned by the get_pages function.
  • get_pung – Applied to the list of pinged URLs for a post by the function.get_pung
  • get_the_archive_title – Applied to the archive’s title in the get_the_archive_title function.
  • get_the_excerpt – Applied to the post’s excerpt in the get_the_excerpt function.
  • get_the_guid – Applied to the post’s GUID in the function.get_the_guid
  • get_to_ping – Applied to the list of URLs to ping for a post by the function.get_to_ping
  • icon_dir – Applied to the template’s image directory in several functions.
  • icon_dir_uri – Applied to the template’s image directory URI in several functions. Basically allows a plugin to specify that icons for MIME types should come from a different location.
  • image_size_names_choose – Applied to the list of image sizes selectable in the Media Library. Commonly used to make custom image sizes selectable.
  • mime_type_edit_pre – Applied to post mime type prior to display for editing.
  • modified_edit_pre – Applied to post modification date prior to display for editing.
  • modified_gmt_edit_pre – Applied to post modification gmt date prior to display for editing.
  • no_texturize_shortcodes – Applied to registered shortcodes. Can be used to exempt shortcodes from the automatic texturize function.
  • parent_edit_pre – Applied to post parent id prior to display for editing.
  • password_edit_pre – Applied to post password prior to display for editing.
  • post_class – Applied to the classes of the outermost HTML element for a post. Called in the function. Filter function arguments: an array of class names, an array of additional class names that were added to the first array, and the post ID.get_post_class
  • pre_kses – Applied to various content prior to being processed/sanitized by KSES. This hook allows developers to customize what types of scripts/tags should either be allowed in content or stripped.
  • prepend_attachment – Applied to the HTML to be prepended by the prepend_attachment function.
  • protected_title_format – Used to the change or manipulate the post title when the post is password protected.
  • private_title_format – Used to the change or manipulate the post title when its status is private.
  • sanitize_title – Applied to a post title by the function, after stripping out HTML tags.sanitize_title
  • single_post_title – Applied to the post title when used to create a blog page title by the and functions.wp_titlesingle_post_title
  • status_edit_pre – Applied to post status prior to display for editing.
  • the_content – Applied to the post content retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).
  • the_content_rss – Applied to the post content prior to including in an RSS feed. (Deprecated)
  • the_content_feed – Applied to the post content prior to including in an RSS feed.
  • the_editor_content – Applied to post content before putting it into a rich editor window.
  • the_excerpt – Applied to the post excerpt (or post content, if there is no excerpt) retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).
  • the_excerpt_rss – Applied to the post excerpt prior to including in an RSS feed.
  • the_password_form – Applied to the password form for protected posts.
  • the_tags – Applied to the tags retrieved from the database, prior to printing on the screen.
  • the_tags – Applied to the post title retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).
  • the_title_rss – Applied to the post title before including in an RSS feed (after first filtering with .the_title
  • title_edit_pre – Applied to post title prior to display for editing.
  • type_edit_pre – Applied to post type prior to display for editing.
  • wp_dropdown_pages – Applied to the HTML dropdown list of WordPress pages generated by the function.wp_dropdown_pages
  • wp_list_pages – Applied to the HTML list generated by the function.wp_list_pages
  • wp_list_pages_excludes – Applied to the list of excluded pages (an array of page IDs) in the function.wp_list_pages
  • wp_get_attachment_metadata – Applied to the attachment metadata retrieved by the function.wp_get_attachment_metadata
  • wp_get_attachment_thumb_file – Applied to the attachment thumbnail file retrieved by the function.wp_get_attachment_thumb_file
  • wp_get_attachment_thumb_url – Applied to the attachment thumbnail URL retrieved by the function.wp_get_attachment_thumb_URL
  • wp_get_attachment_url – Applied to the attachment URL retrieved by the function.wp_get_attachment_url
  • wp_mime_type_icon – Applied to the MIME type icon for an attachment calculated by the function.wp_mime_type_icon
  • wp_title – Applied to the blog page title before sending to the browser in the function.wp_title

Database Writes

  • add_ping – Applied to the new value of the pinged field on a post when a ping is added, prior to saving the new information in the database.
  • attachment_fields_to_save – Applied to fields associated with an attachment prior to saving them in the database. Called in the function. Filter function arguments: an array of post attributes, an array of attachment fields including the changes submitted from the form.media_upload_form_handler
  • attachment_max_dims – Applied to the maximum image dimensions before reducing an image size. Filter function input (and return value) is either false (if no maximum dimensions have been specified) or a two-item list (width, height).
  • category_save_pre – Applied to post category comma-separated list prior to saving it in the database (also used for attachments).
  • comment_status_pre – Applied to post comment status prior to saving it in the database (also used for attachments).
  • content_filtered_save_pre – Applied to filtered post content prior to saving it in the database (also used for attachments).
  • content_save_pre – Applied to post content prior to saving it in the database (also used for attachments).
  • excerpt_save_pre – Applied to post excerpt prior to saving it in the database (also used for attachments).
  • image_save_pre (deprecated) – Use image_editor_save_pre instead.
  • jpeg_quality (deprecated) – Use or instead.wp_editor_set_qualityWP_Image_Editor::set_quality()
  • name_save_pre (Deprecated) – Applied to post name prior to saving it in the database (also used for attachments).
  • phone_content – Applied to the content of a post submitted by email, before saving.
  • ping_status_pre – Applied to post ping status prior to saving it in the database (also used for attachments).
  • post_mime_type_pre – Applied to the MIME type for an attachment prior to saving it in the database.
  • status_save_pre – Applied to post status prior to saving it in the database.
  • thumbnail_filename – Applied to the file name for the thumbnail when uploading an image.
  • title_save_pre – Applied to post title prior to saving it in the database (also used for attachments).
  • update_attached_file – Applied to the attachment information prior to saving in post metadata in the update_attached_file function. Filter function arguments: attachment information, attachment ID.
  • wp_create_thumbnail (deprecated)
  • wp_delete_file – Applied to an attachment file name just before deleting.
  • wp_generate_attachment_metadata – Applied to the attachment metadata array before saving in the database.
  • wp_save_image_file (deprecated) – wp_save_image_editor_file instead.Use
  • wp_thumbnail_creation_size_limit – Applied to the size of the thumbnail when uploading an image. Filter function arguments: max file size, attachment ID, attachment file name.
  • wp_thumbnail_max_side_length – Applied to the size of the thumbnail when uploading an image. Filter function arguments: image side max size, attachment ID, attachment file name.
  • wp_update_attachment_metadata – Applied to the attachment metadata just before saving in the function. Filter function arguments: meta data, attachment ID.wp_update_attachment_metadata

Comment, Trackback, and Ping Filters

Database Reads

  • comment_excerpt applied to the comment excerpt by the comment_excerpt function. See also .get_comment_excerpt
  • comment_flood_filter – Applied when someone appears to be flooding your blog with comments. Filter function arguments: already blocked (true/false, whether a previous filtering plugin has already blocked it; set to true and return true to block this comment in a plugin), time of previous comment, time of current comment.
  • comment_post_redirect – Applied to the redirect location after someone adds a comment. Filter function arguments: redirect location, comment info array.
  • comment_text – Applied to the comment text before displaying on the screen by the function, and in the admin menus.comment_text
  • comment_text_rss – Applied to the comment text prior to including in an RSS feed.
  • comments_array – Applied to the array of comments for a post in the comments_template function. Filter function arguments: array of comment information structures, post ID.
  • comments_number – Applied to the formatted text giving the number of comments generated by the comments_number function. See also .get_comments_number
  • get_comment_excerpt – Applied to the comment excerpt read from the database by the function (which is also called by . See also .get_comment_excerptcomment_excerptcomment_excerpt
  • get_comment_ID – Applied to the comment ID read from the global variable by the function.$commentsget_comment_ID
  • get_comment_text – Applied to the comment text of the current comment in the function, which is also called by the function.get_comment_textcomment_text
  • get_comment_type – Applied to the comment type (“comment”, “trackback”, or “pingback”) by the function (which is also called by ).get_comment_typecomment_type
  • get_comments_number – Applied to the comment count read from the global variable by the function (which is also called by the comments_number function; see also comments_number filter).$postget_comments_number
  • post_comments_feed_link – Applied to the feed URL generated for the comments feed by the function.comments_rss

Database Writes

  • comment_save_pre – Applied to the comment data just prior to updating/editing comment data. Function arguments: comment data array, with indices ““, ““, ““, ““, ““, ““, and ““.comment_post_IDcomment_authorcomment_author_emailcomment_author_urlcomment_contentcomment_typeuser_ID
  • pre_comment_approved – Applied to the current comment’s approval status (true/false) to allow a plugin to override. Return true/false and set first argument to true/false to approve/disapprove the comment, and use global variables such as to access information about this comment.$comment_ID
  • pre_comment_content – Applied to the content of a comment prior to saving the comment in the database.
  • preprocess_comment – Applied to the comment data prior to any other processing, when saving a new comment in the database. Function arguments: comment data array, with indices ““, “comment_author”, ““, ““, ““, ““, and ““.comment_post_IDcomment_author_emailcomment_author_urlcomment_contentcomment_typeuser_ID
  • wp_insert_post_data – Applied to modified and unmodified post data in prior to update or insertion of post into database. Function arguments: modified and extended post array and sanitized post array.wp_insert_post()

Category and Term Filters

Database Reads

  • category_description – Applied to the “description” field categories by the and functions. Filter function arguments: description, category ID when called from ; description, category information array (all fields from the category table for that particular category) when called from .category_descriptionwp_list_categoriescategory_descriptionwp_list_categories
  • category_feed_link – Applied to the feed URL generated for the category feed by the function.get_category_feed_link
  • category_link – Applied to the URL created for a category by the function. Filter function arguments: link URL, category ID.get_category_link
  • get_ancestors – Applied to the list of ancestor IDs returned by the function (which is in turn used by many other functions). Filter function arguments: ancestor IDs array, given object ID, given object type.get_ancestors
  • get_categories – Applied to the category list generated by the function (which is in turn used by many other functions). Filter function arguments: category list, get_categories options list.get_categories
  • get_category – Applied to the category information that the get_category function looks up, which is basically an array of all the fields in WordPress’s category table for a particular category ID.
  • list_cats – Called for two different purposes: 1. the function uses it to filter the show_option_all and arguments (which are used to put options “All” and “None” in category drop-down lists). No additional filter function arguments; and 2: the function applies it to the category names. Filter function arguments: category name, category information list (all fields from the category table for that particular category).wp_dropdown_categoriesshow_option_nonewp_list_categories
  • list_cats_exclusions – Applied to the SQL WHERE statement giving the categories to be excluded by the get_categories function. Typically, a plugin would add to this list, in order to exclude certain categories or groups of categories from category lists. Filter function arguments: excluded category WHERE clause, options list.get_categories
  • single_cat_title – Applied to the category name when used to create a blog page title by the and functions.wp_titlesingle_cat_title
  • the_category – Applied to the list of categories (an HTML list with links) created by the function. Filter function arguments: generated HTML text, list separator being used (empty string means it is a default LI list), parents argument to .get_the_category_listget_the_category_list
  • the_category_rss – Applied to the category list (a list of category XML elements) for a post by the get_the_category_rss function, before including in an RSS feed. Filter function arguments are the list text and the type (“rdf” or “rss” generally).
  • wp_dropdown_cats – Applied to the drop-down category list (a text string containing HTML option elements) generated by the function.wp_dropdown_categories
  • wp_list_categories – Applied to the category list (an HTML list) generated by the function.wp_list_categories
  • wp_get_object_terms – Applied to the list of terms (an array of objects) generated by the function, which is called by a number of category/term related functions, such as and .wp_get_object_termsget_the_termsget_the_category

Database Writes

  • pre_category_description – Applied to the category description prior to saving in the database.
  • wp_update_term_parent – Filter term parent before update to term is applied, hook to this filter to see if it will cause a hierarchy loop.
  • edit_terms –  (actually an action, but often used like a filter) hooked in prior to saving taxonomy/category change in the database
  • pre_category_name – Applied to the category name prior to saving in the database.
  • pre_category_nicename – Applied to the category nice name prior to saving in the database.

Link Filters

These hooks let you filter links related to posts, pages, archives, and feeds.

  • attachment_link – Applied to the calculated attachment permalink by the function. Filter function arguments: link URL, attachment ID.get_attachment_link
  • author_feed_link – Applied to the feed URL generated for the author feed by the function.get_author_rss_link
  • author_link – Applied to the author’s archive permalink created by the function. Filter function arguments: link URL, author ID, author’s “nice” name. Note that is called within functions and .get_author_posts_urlget_author_posts_urlwp_list_authorsthe_author_posts_link
  • comment_reply_link – Applied to the link generated for replying to a specific comment by the function which is called within function . Filter function arguments: link (string), custom options (array), current comment (object), current post (object).get_comment_reply_linkcomments_template
  • day_link – Applied to the link URL for a daily archive by the function. Filter function arguments: URL, year, month number, day number.get_day_link
  • feed_link – Applied to the link URL for a feed by the function. Filter function arguments: URL, type of feed (e.g. “rss2”, “atom”, etc.).get_feed_link
  • get_comment_author_link – Applied to the HTML generated for the author’s link on a comment, in the function (which is also called by comment_author_link. Action function arguments: user name.get_comment_author_link
  • get_comment_author_url_link – Applied to the HTML generated for the author’s link on a comment, in the function (which is also called by ).get_comment_author_url_linkcomment_author_link
  • month_link – Applied to the link URL for a monthly archive by the function. Filter function arguments: URL, year, month number.get_month_link
  • page_link – Applied to the calculated page URL by the get_page_link function. Filter function arguments: URL, page ID. Note that there is also an internal filter called that can be used to filter the URLS of pages that are not designated as the blog’s home page (same arguments). Note that this only applies to WordPress pages, not posts, custom post types, or attachments._get_page_link
  • post_link – Applied to the calculated post permalink by the get_permalink function, which is also called by the the_permalink, , , and functions. Filter function arguments: permalink URL, post data list. Note that this only applies to WordPress default posts, and not custom post types (nor pages or attachments).post_permalinkprevious_post_linknext_post_link
  • post_type_link – Applied to the calculated custom post type permalink by the function.get_post_permalink
  • the_permalink – Applied to the permalink URL for a post prior to printing by function .the_permalink
  • year_link – Applied to the link URL for a yearly archive by the function. Filter function arguments: URL, year.get_year_link
  • tag_link – Applied to the URL created for a tag by the function. Filter function arguments: link URL, tag ID.get_tag_link
  • term_link – Applied to the URL created for a term by the function. Filter function arguments: term link URL, term object and taxonomy slug.get_term_link

Date and Time Filters

  • get_comment_date – Applied to the formatted comment date generated by the function (which is also called by ).get_comment_datecomment_date
  • get_comment_time – Applied to the formatted comment time in the get_comment_time function (which is also called by comment_time).
  • get_the_modified_date – Applied to the formatted post modification date generated by the function (which is also called by the function).get_the_modified_datethe_modified_date
  • get_the_modified_time – Applied to the formatted post modification time generated by the and functions (which are also called by the the_modified_time function).get_the_modified_timeget_post_modified_time
  • get_the_time – Applied to the formatted post time generated by the get_the_time and functions (which are also called by the the_time function).get_post_time
  • the_date – Applied to the formatted post date generated by the the_date function.
  • the_modified_date – Applied to the formatted post modification date generated by the function.the_modified_date
  • the_modified_time – Applied to the formatted post modification time generated by the function.the_modified_time
  • the_time – Applied to the formatted post time generated by the function.the_time
  • the_weekday – Applied to the post date weekday name generated by the function.the_weekday
  • the_weekday_date – Applied to the post date weekday name generated by the function. Function arguments are the weekday name, before text, and after text (before text and after text are added to the weekday name if the current post’s weekday is different from the previous post’s weekday).the_weekday_date

Author and User Filters

  • login_body_class – Allows filtering of the body class applied to the login screen in .login_header()
  • login_redirect – Applied to the post/get variable during the user login process.redirect_to
  • user_contactmethods – Applied to the contact methods fields on the user profile page. (old page is here: contactmethods)
  • update_(meta_type)_metadata – Applied before a (user) metadata gets updated.

Database Reads

  • author_email – Applied to the comment author’s email address retrieved from the database by the function. See also .comment_author_emailget_comment_author_email
  • comment_author – Applied to the comment author’s name retrieved from the database by the function. See also .comment_authorget_comment_author
  • comment_author_rss – Applied to the comment author’s name prior to including in an RSS feed.
  • comment_email – Applied to the comment author’s email address retrieved from the database by the function.comment_author_email_link
  • comment_url – Applied to the comment author’s URL retrieved from the database by the function (see also ).comment_author_urlget_comment_author_url
  • get_comment_author – Applied to the comment author’s name retrieved from the database by , which is also called by . See also .get_comment_authorcomment_authorcomment_author
  • get_comment_author_email – Applied to the comment author’s email address retrieved from the database by , which is also called by . See also .get_comment_author_emailcomment_author_emailauthor_email
  • get_comment_author_IP – Applied to the comment author’s IP address retrieved from the database by the function, which is also called by .get_comment_author_IPcomment_author_IP
  • get_comment_author_url – Applied to the comment author’s URL retrieved from the database by the function, which is also called by . See also .get_comment_author_urlcomment_author_urlcomment_url
  • login_errors – Applied to the login error message printed on the login screen.
  • login_headertitle – Applied to the title for the login header URL (Powered by WordPress by default) printed on the login screen.
  • login_headerurl – Applied to the login header URL (points to wordpress.org by default) printed on the login screen.
  • login_message – Applied to the login message printed on the login screen.
  • role_has_cap – Applied to a role’s capabilities list in the function. Filter function arguments are the capabilities list to be filtered, the capability being questioned, and the role’s name.WP_Role->has_cap
  • sanitize_user – Applied to a user name by the function. Filter function arguments: user name (after some cleaning up), raw user name, strict (true or false to use strict ASCII or not).sanitize_user
  • the_author – Applied to a post author’s displayed name by the function, which is also called by the function.get_the_authorthe_author
  • the_author_email – Applied to a post author’s email address by the function.the_author_email
  • user_search_columns – Applied to the list of columns in the table to include in the clause inside .wp_usersWHEREWP_User_Query

Database Writes

  • pre_comment_author_email – Applied to a comment author’s email address prior to saving the comment in the database.
  • pre_comment_author_name – Applied to a comment author’s user name prior to saving the comment in the database.
  • pre_comment_author_url – Applied to a comment author’s URL prior to saving the comment in the database.
  • pre_comment_user_agent – Applied to the comment author’s user agent prior to saving the comment in the database.
  • pre_comment_user_ip – Applied to the comment author’s IP address prior to saving the comment in the database.
  • pre_user_id – Applied to the comment author’s user ID prior to saving the comment in the database.
  • pre_user_description – Applied to the user’s description prior to saving in the database.
  • pre_user_display_name – Applied to the user’s displayed name prior to saving in the database.
  • pre_user_email – Applied to the user’s email address prior to saving in the database.
  • pre_user_first_name – Applied to the user’s first name prior to saving in the database.
  • pre_user_last_name – Applied to the user’s last name prior to saving in the database.
  • pre_user_login – Applied to the user’s login name prior to saving in the database.
  • pre_user_nicename – Applied to the user’s “nice name” prior to saving in the database.
  • pre_user_nickname – Applied to the user’s nickname prior to saving in the database.
  • pre_user_url – Applied to the user’s URL prior to saving in the database.
  • registration_errors – Applied to the list of registration errors generated while registering a user for a new account.
  • user_registration_email – Applied to the user’s email address read from the registration page, prior to trying to register the person as a new user.
  • validate_username – Applied to the validation result on a new user name. Filter function arguments: valid (true/false), user name being validated.

Blogroll Filters

These hooks are for filtering content related to blogroll links.

  • get_bookmarks – Applied to link/blogroll database query results by the function. Filter function arguments: database query results list, arguments list.get_bookmarksget_bookmarks
  • link_category – Applied to the link category by the get_links_list and functions (as of WordPress 2.2).wp_list_bookmarks
  • link_description – Applied to the link description by the get_links and wp_list_bookmarks functions (as of WordPress 2.2).
  • link_rating – Applied to the link rating number by the function.get_linkrating
  • link_title – Applied to the link title by the get_links and functions (as of WordPress 2.2)wp_list_bookmarks
  • pre_link_description – Applied to the link description prior to saving in the database.
  • pre_link_image – Applied to the link image prior to saving in the database.
  • pre_link_name – Applied to the link name prior to saving in the database.
  • pre_link_notes – Applied to the link notes prior to saving in the database.
  • pre_link_rel – Applied to the link relation information prior to saving in the database.
  • pre_link_rss – Applied to the link RSS URL prior to saving in the database.
  • pre_link_target – Applied to the link target information prior to saving in the database.
  • pre_link_url – Applied to the link URL prior to saving in the database.

Blog Information and Option Filters

  • all_options – Applied to the option list retrieved from the database by the function.get_alloptions
  • all_plugins – Applied to the list of plugins retrieved for display in the plugins list table.
  • bloginfo – Applied to the blog option information retrieved from the database by the function, after first retrieving the information with the function. A second argument gives the name of the option that was requested. Note that , and do not use this filtering function (see ).bloginfoget_bloginfo$showbloginfobloginfo("url")bloginfo("directory")bloginfo("home")bloginfo_url
  • bloginfo_rss – Applied to the blog option information by function get_bloginfo_rss (which is also called from bloginfo_rss), after first retrieving the information with the get_bloginfo function, stripping out HTML tags, and converting characters appropriately. A second argument $show gives the name of the bloginfo option that was requested.
  • bloginfo_url – Applied to the the output of , and before returning the information.bloginfo("url")bloginfo("directory")bloginfo("home")
  • loginout – Applied to the HTML link for logging in and out (generally placed in the sidebar) generated by the wp_loginout function.
  • lostpassword_url – Applied to the URL that allows users to reset their passwords.
  • option_(option name) – Applied to the option value retrieved from the database by the get_option function, after unserializing (which decodes array-based options). To use this filter, you will need to add filters for specific options names, such as “option_foo” to filter the output of get_option(“foo”).
  • pre_get_space_used – Applied to the function to provide an alternative way of displaying storage space used. Returning false from this filter will revert to default display behavior (used directory space in megabytes).get_space_used()wp_upload_dir()
  • pre_option_(option name) – Applied to the option value retrieved from the database by the function, after unserializing (which decodes array-based options). To use this filter, you will need to add filters for specific options names, such as “” to filter the option “foo”.get_alloptionspre_option_foo
  • pre_update_option_(option name) – Applied the option value before being saving to the database to allow overriding the value to be stored. To use this filter, you will need to add filters for specific options names, such as “” to filter the option “foo”.pre_update_option_foo
  • register – Applied to the sidebar link created for the user to register (if allowed) or visit the admin panels (if already logged in) by the function.wp_register
  • upload_dir – Applied to the directory to be used for uploads calculated by the function. Filter function argument is an array with components “dir” (the upload directory path), “url” (the URL of the upload directory), and “error” (which you can set to true if you want to generate an error).wp_upload_dir
  • upload_mimes – Allows a filter function to return a list of MIME types for uploads, if there is no MIME list input to the function. Filter function argument is an associated list of MIME types whose component names are file extensions (separated by vertical bars) and values are the corresponding MIME types.wp_check_filetype

General Text Filters

  • attribute_escape – Applied to post text and other content by the attribute_escape function, which is called in many places in WordPress to change certain characters into HTML attributes before sending to the browser.
  • js_escape – Applied to JavaScript code before sending to the browser in the js_escape function.
  • sanitize_key – Applied to key before using it for your settings, field, or other needs, generated by functionsanitize_key

Administrative Filters

These hooks let you filter content related to the WordPress dashboard, including content editing screens.

  • admin_user_info_links – Applied to the user profile and info links in the WordPress admin quick menu.
  • autosave_interval – Applied to the interval for auto-saving posts.
  • bulk_actions – Applied to an array of bulk items in admin bulk action drop-downs.
  • bulk_post_updated_messages – Applied to an array of bulk action updated messages.
  • cat_rows – Applied to the category rows HTML generated for managing categories in the admin menus.
  • comment_edit_pre – Applied to comment content prior to display in the editing screen.
  • comment_edit_redirect – Applied to the redirect location after someone edits a comment in the admin . Filter function arguments: redirect location, comment ID.menus
  • comment_moderation_subject – Applied to the mail subject before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail subject, comment ID. Note that this happens inside the default function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_notify_moderator
  • comment_moderation_text – Applied to the body of the mail message before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail body text, comment ID. Note that this happens inside the default function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_notify_moderator
  • comment_notification_headers – Applied to the mail headers before sending email notifying the post author of a new comment. Filter function arguments: mail header text, comment ID. Note that this happens inside the default function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_notify_postauthor
  • comment_notification_subject – Applied to the mail subject before sending email notifying the post author of a new comment. Filter function arguments: mail subject, comment ID. Note that this happens inside the default function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_notify_postauthor
  • comment_notification_text – Applied to the body of the mail message before sending email notifying the post author of a new comment. Filter function arguments: mail body text, comment ID. Note that this happens inside the default function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_notify_postauthor
  • comment_row_actions – Applied to the list of action links under each comment row (like Reply, Quick Edit, Edit).
  • cron_request – Allows filtering of the URL, key and arguments passed to in .wp_remote_post()spawn_cron()
  • cron_schedules – Applied to an empty array to allow a plugin to generate cron schedules in the function.wp_get_schedules
  • custom_menu_order – Used to activate the ‘‘ filter.menu_order
  • default_content – Applied to the default post content prior to opening the editor for a new post.
  • default_excerpt – Applied to the default post excerpt prior to opening the editor for a new post.
  • default_title – Applied to the default post title prior to opening the editor for a new post.
  • editable_slug – Applied to the post, page, tag or category slug by the function.get_sample_permalink
  • format_to_edit – Applied to post content, excerpt, title, and password by the function, which is called by the admin menus to set up a post for editing. Also applied to when editing comments in the admin menus.format_to_edit
  • format_to_post – Applied to post content by the function, which is not used in WordPress by default.format_to_post
  • manage_edit-${post_type}_columns – Applied to the list of columns to print on the manage posts screen for a custom post type. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also action , which puts the column information into the edit screen.manage_${post_type}_posts_custom_column
  • manage_link-manager_columns – Was until WordPress 2.7. applied to the list of columns to print on the blogroll management screen. Filter function argument/return value is an associative list where the element key is the name of the column, and the value is the header text for that column. See also action , which puts the column information into the edit screen.manage_link_columnsmanage_link_custom_column
  • manage_posts_columns – Applied to the list of columns to print on the manage posts screen. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also action , which puts the column information into the edit screen. (see Scompt’s tutorial for examples and use.)manage_posts_custom_column
  • manage_pages_columns – Applied to the list of columns to print on the manage pages screen. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also action , which puts the column information into the edit screen.manage_pages_custom_column
  • manage_users_columns
  • manage_users_custom_column
  • manage_users_sortable_columns
  • media_row_actions – Applied to the list of action links under each file in the Media Library (like View, Edit).
  • menu_order – Applied to the array for the admin menu order. Must be activated with the ‘‘ filter before.custom_menu_order
  • nonce_life – Applied to the lifespan of a nonce to generate or verify the nonce. Can be used to generate nonces which expire earlier. The value returned by the filter should be in seconds.
  • nonce_user_logged_out – Applied to the current user ID used to generate or verify a nonce when the user is logged out.
  • plugin_row_meta – Add additional links below each plugin on the plugins page.
  • postmeta_form_limit – Applied to the number of post-meta information items shown on the post edit screen.
  • post_row_actions – Applied to the list of action links (like Quick Edit, Edit, View, Preview) under each post in the Posts > All Posts section.
  • post_updated_messages – Applied to the array storing user-visible administrative messages when working with posts, pages and custom post types. This filter is used to change the text of said messages, not to trigger them. See “customizing the messages” in the documentation.register_post_type
  • pre_upload_error – Applied to allow a plugin to create an XMLRPC error for uploading files.
  • preview_page_link – Applied to the link on the page editing screen that shows the page preview at the bottom of the screen.
  • preview_post_link – Applied to the link on the post editing screen that shows the post preview at the bottom of the screen.
  • richedit_pre – Applied to post content by the function, before displaying in the rich text editor.wp_richedit_pre
  • schedule_event – Applied to each recurring and single event as it is added to the cron schedule.
  • set-screen-option – Filter a screen option value before it is set.
  • show_password_fields – Applied to the true/false variable that controls whether the user is presented with the opportunity to change their password on the user profile screen (true means to show password changing fields; false means don’t).
  • terms_to_edit – Applied to the CSV of terms (for each taxonomy) that is used to show which terms are attached to the post.
  • the_editor – Applied to the HTML DIV created to house the rich text editor, prior to printing it on the screen. Filter function argument/return value is a string.
  • user_can_richedit – Applied to the calculation of whether the user’s browser has rich editing capabilities, and whether the user wants to use the rich editor, in the function. Filter function argument and return value is true/false if the current user can/cannot use the rich editor.user_can_richedit
  • user_has_cap – Applied to a user’s capabilities list in the function (which is called by the function). Filter function arguments are the capabilities list to be filtered, the capability being questioned, and the argument list (which has things such as the post ID if the capability is to edit posts, etc.)WP_User->has_capcurrent_user_can
  • wp_handle_upload_prefilter – Applied to the upload information when uploading a file. Filter function argument: array which represents a single element of .$_FILES
  • wp_handle_upload – Applied to the upload information when uploading a file. Filter function argument: array with elements “file” (file name), “url”, “type”.
  • wp_revisions_to_keep – Alters how many revisions are kept for a given post. Filter function arguments: number representing desired revisions saved (default is unlimited revisions), the post object.
  • wp_terms_checklist_args – Applied to arguments of the function. Filter function argument: array of checklist arguments, post ID.wp_terms_checklist()
  • wp_upload_tabs – Applied to the list of custom tabs to display on the upload management admin screen. Use action to display a page for your custom tab (see Plugin API/Action Reference).upload_files_(tab)
  • media_upload_tabs – Applied to the list of custom tabs to display on the upload management admin screen. Use action to display a page for your custom tab (see Plugin API/Action Reference).upload_files_(tab)
  • plugin_action_links_(plugin file name) – Applied to the list of links to display on the plugins page (beside the activate/deactivate links).
  • views_edit-post – Applied to the list posts eg All (30) | Published (22) | Draft (5) | Pending (2) | Trash (1)

Rich Text Editor Filters

Using these hooks, you can modify the configuration of TinyMCE, the rich text editor.

  • mce_spellchecker_languages – Applied to the language selection available in the spell checker.
  • mce_buttons, , , – Applied to the rows of buttons for the rich editor toolbar (each is an array of button names).mce_buttons_2mce_buttons_3mce_buttons_4
  • mce_css – Applied to the CSS file URL for the rich text editor.
  • mce_external_plugins – Applied to the array of external plugins to be loaded by the rich text editor.
  • mce_external_languages – Applied to the array of language files loaded by external plugins, allowing them to use the standard translation method (see tinymce/langs/wp-langs.php for reference).
  • tiny_mce_before_init – Applied to the whole init array for the editor.

Template Filters

The filter hooks in this section allow you to work with themes, templates, and style files.

  • locale_stylesheet_uri – Applied to the locale-specific stylesheet URI returned by the function. Filter function arguments: URI, stylesheet directory URI.get_locale_stylesheet_uri
  • stylesheet – Applied to the stylesheet returned by the function.get_stylesheet
  • stylesheet_directory – Applied to the stylesheet directory returned by the function. Filter function arguments: stylesheet directory, stylesheet.get_stylesheet_directory
  • stylesheet_directory_uri – Applied to the stylesheet directory URI returned by the function. Filter function arguments: stylesheet directory URI, stylesheet.get_stylesheet_directory_uri
  • stylesheet_uri – Applied to the stylesheet URI returned by the function. Filter function arguments: stylesheet URI, stylesheet.get_stylesheet_uri
  • template – Applied to the template returned by the get_template function.
  • template_directory – Applied to the template directory returned by the function. Filter function arguments: template directory, template.get_template_directory
  • template_directory_uri – Applied to the template directory URI returned by the function. Filter function arguments: template directory URI, template.get_template_directory_uri
  • theme_root – Applied to the theme root directory (normally wp-content/themes) returned by the get_theme_root function.
  • theme_root_uri – Applied to the theme root directory URI returned by the function. Filter function arguments: URI, site URL. You can also replace individual template files from your theme, by using the following filter hooks. See also the action hook. Each of these filters takes as input the path to the corresponding template file in the current theme. A plugin can modify the file to be used by returning a new path to a template file.get_theme_root_uritemplate_redirect
  • 404_template
  • archive_template – You can use this for example to enforce a specific template for a custom post type archive. This way you can keep all the code in a plugin.
  • attachment_template
  • author_template
  • category_template
  • comments_popup_template
  • comments_template – The “” filter can be used to load a custom template form a plugin which replace the themes default comment template.comments_template
  • date_template
  • home_template
  • page_template
  • paged_template
  • search_template
  • single_template – You can use this for example to enforce a specific template for a custom post type. This way you can keep all the code in a plugin.
  • shortcut_link – Applied to the “Press This” bookmarklet link.
  • template_include
  • wp_nav_menu_args – Applied to the arguments of the function.wp_nav_menu
  • wp_nav_menu_items – Filter the HTML list content for navigation menus.

Registration & Login Filters

  • authenticate – Allows basic authentication to be performed on login based on username and password.
  • registration_errors – Applied to the list of registration errors generated while registering a user for a new account.
  • user_registration_email – Applied to the user’s email address read from the registration page, prior to trying to register the person as a new user.
  • validate_username – Applied to the validation result on a new user name. Filter function arguments: valid (true/false), user name being validated.
  • wp_authenticate_user – Applied when a user attempted to log in, after WordPress validates username and password, but before validation errors are checked.

Redirect/Rewrite Filters – Advanced

These advanced filters relate to WordPress’s handling of rewrite rules.

  • allowed_redirect_hosts – Applied to the list of host names deemed safe for redirection. wp-login.php uses this to defend against a dangerous ‘‘ request parameterredirect_to
  • author_rewrite_rules – Applied to the author-related rewrite rules after they are generated.
  • category_rewrite_rules – Applied to the category-related rewrite rules after they are generated.
  • comments_rewrite_rules – Applied to the comment-related rewrite rules after they are generated.
  • date_rewrite_rules – Applied to the date-related rewrite rules after they are generated.
  • mod_rewrite_rules – Applied to the list of rewrite rules given to the user to put into their .htaccess file when they change their permalink structure. (Note: replaces deprecated filter rewrite_rules.)
  • page_rewrite_rules – Applied to the page-related rewrite rules after they are generated.
  • post_rewrite_rules – Applied to the post-related rewrite rules after they are generated.
  • redirect_canonical – Can be used to cancel a “canonical” URL redirect. Accepts 2 parameters: , . To cancel the redirect return , to allow the redirect return .$redirect_url$requested_urlFALSE$redirect_url
  • rewrite_rules_array – Applied to the entire rewrite rules array after it is generated.
  • root_rewrite_rules – Applied to the root-level rewrite rules after they are generated.
  • search_rewrite_rules – Applied to the search-related rewrite rules after they are generated.
  • wp_redirect – Applied to a redirect URL by the default function. Filter function arguments: URL, HTTP status code. Note that is also a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_redirectwp_redirect
  • wp_redirect_status – Applied to the HTTP status code when redirecting by the default function. Filter function arguments: HTTP status code, URL. Note that is also a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_redirectwp_redirect

WP_Query Filters

These are filters run by the object in the course of building and executing a query to retrieve posts.WP_Query

  • found_posts – Applied to the list of posts, just after querying from the database.
  • found_posts_query – After the list of posts to display is queried from the database, WordPress selects rows in the query results. This filter allows you to do something other than at that step.SELECT FOUND_ROWS()
  • post_limits – Applied to the LIMIT clause of the query that returns the post array.
  • posts_clauses – Applied to the entire SQL query, divided into a keyed array for each clause type, that returns the post array. Can be easier to work with than .posts_request
  • posts_distinct – Allows a plugin to add a clause to the query that returns the post array.DISTINCTROW
  • posts_fields – Applied to the field list for the query that returns the post array.
  • posts_groupby – Applied to the GROUP BY clause of the query that returns the post array (normally empty).
  • posts_join – Applied to the clause of the query that returns the post array. This is typically used to add a table to the , in combination with the filter.JOINJOINposts_where
  • posts_join_paged – Applied to the clause of the query that returns the post array, after the paging is calculated (though paging does not affect the , so this is actually equivalent to ).JOINJOINposts_join
  • posts_orderby – Applied to the clause of the query that returns the post array.ORDER BY
  • posts_request – Applied to the entire SQL query that returns the post array, just prior to running the query.
  • posts_results – Allows you to manipulate the resulting array returned from the query.
  • posts_search – Applied to the search SQL that is used in the clause of .WHEREWP_Query
  • posts_where – Applied to the clause of the query that returns the post array.WHERE
  • posts_where_paged – Applied to the clause of the query that returns the post array, after the paging is calculated (though paging does not affect the , so this is actually equivalent to ).WHEREWHEREposts_where
  • the_posts – Applied to the list of posts queried from the database after minimal processing for permissions and draft status on single-post pages.

Media Filters

这些媒体过滤器挂钩使您能够集成不同类型的媒体。

  • editor_max_image_size
  • image_downsize
  • get_image_tag_class
  • get_image_tag
  • image_resize_dimensions
  • intermediate_image_sizes
  • icon_dir
  • wp_get_attachment_image_attributes
  • img_caption_shortcode
  • post_gallery
  • use_default_gallery_style
  • gallery_style
  • (adjacent)_image_link
  • embed_defaults
  • load_default_embeds
  • embed_googlevideo
  • upload_size_limit
  • wp_image_editors
  • plupload_default_settings
  • plupload_default_params
  • image_size_names_choose
  • wp_prepare_attachment_for_js
  • media_upload_tabs
  • disable_captions
  • media_view_settings
  • media_view_strings
  • wp_handle_upload_prefilter

高级WordPress过滤器

本节中的高级筛选器挂钩与国际化,杂项查询和其他基本WordPress函数相关。

  • create_user_query– 应用于用于在运行查询之前将新用户的信息保存到数据库的查询。
  • get_editable_authors– 应用于当前用户有权在函数中编辑的帖子作者列表。get_editable_authors
  • get_next_post_join– 在get_next_post(在当前显示的帖子之后查找帖子),应用于子句(如果用户正在查看类别存档,该子句通常会连接到类别表)。筛选函数参数:子句,保持在同一类别(真/假),排除类别列表。functionSQL JOINJOIN
  • get_next_post_sort– 在函数get_next_post(在当前显示的帖子之后查找帖子)中,应用于子句(通常按发布日期升序排序,限制为1个帖子)。筛选函数参数:子句。SQL ORDER BYORDER BY
  • get_next_post_where– 在功能中(在当前显示的帖子之后查找帖子),应用于子句(通常查找下一个日期已发布的帖子)。筛选函数参数:子句,保持在同一类别(真/假),排除类别列表。get_next_postSQL WHEREWHERE
  • get_previous_post_join– 在函数get_previous_post(在当前显示的帖子之前查找帖子),应用于子句(如果用户正在查看类别存档,该子句通常会连接到类别表)。过滤函数参数:join子句,保持在同一类别(真/假),排除类别列表。SQL JOIN
  • get_previous_post_sort– 在函数get_previous_post(在当前显示的帖子之前查找帖子),应用于子句(通常按发布日期降序排序,限制为1个帖子)。筛选函数参数:子句。SQL ORDER BYORDER BY
  • get_previous_post_where– 在函数中(在当前显示的帖子之前查找帖子),应用于子句(通常查找以前发布的日期的帖子)。筛选函数参数:子句,保持在同一类别(真/假),排除类别列表。get_previous_postSQL WHEREWHERE
  • gettext– 由函数应用于翻译文本(由和国际化函数等函数调用)。过滤函数参数:已翻译文本、未翻译文本和文本域。即使国际化无效或尚未加载文本域,也会应用。translation()__()_e()
  • override_load_textdomain
  • get_meta_sql– 在函数中(生成要附加到高级元查询的主查询的 SQL 子句),应用于高级元查询生成的 and 子句。过滤器函数参数: , , , , , ,WP_Meta_Query::get_sqlSQL JOINWHEREarray( compact( 'join', 'where' )$this->queries$type$primary_table$primary_id_column$context )
  • get_others_drafts– 应用于选择其他用户的草稿以显示在管理菜单中的查询。
  • get_users_drafts– 应用于选择用户草稿以显示在管理菜单中的查询。
  • locale– 通过函数应用于区域设置。get_locale
  • query– 应用于所有查询(至少加载插件后运行的所有查询)。
  • query_string– 已弃用 – 改为使用或请求。query_vars
  • query_vars– 在 SQL 查询形成之前应用于公共 WordPress 查询变量列表。对于删除插件以其他方式处理的额外永久链接信息非常有用。
  • request– 喜欢 ,但在添加“额外”和私有查询变量后应用。query_vars
  • excerpt_length– 定义单篇文章摘录的长度。
  • excerpt_more– 定义摘录末尾的更多字符串。
  • post_edit_form_tag– 允许您将代码附加到默认帖子/页面编辑器中的表单标签。
  • update_user_query– 应用于在运行查询之前用于更新用户信息的更新查询。
  • uploading_iframe_src(自WP 2.5起删除) - 应用于HTML src标签,用于在帖子和页面编辑屏幕上上传iframe。
  • xmlrpc_methods– 应用于 XMLRPC 服务器定义的 XMLRPC 方法列表。
  • wp_mail_from– 在函数发送任何邮件之前应用。提供的值是从当前主机名处的 wordpress 地址计算得出的(由 设置)。过滤器应以“user@example.com”或“姓名<user@example.com>”的形式返回电子邮件地址或姓名/电子邮件组合(不带引号!wp_mail$_SERVER['SERVER_NAME']
  • wp_mail_from_name– 在函数发送任何邮件之前应用。筛选器应返回一个名称字符串,以用作来自 name 的电子邮件。wp_mail
  • update_(meta_type)_metadata– 在元数据更新之前应用。例如,如果用户元数据被更新,则钩子将为“”update_user_metadata

部件

这些过滤器钩子允许您使用内置于WordPress核心中的小部件。

  • dynamic_sidebar_params– 应用于传递给WordPress小部件中函数的参数。widgets_init
  • widget_archives_dropdown_args– 应用于传递给WordPress Archives小部件中函数的参数。wp_get_archives()
  • widget_categories_args– 应用于传递给 WordPress 类别小部件中函数的参数。wp_list_categories()
  • widget_links_args– 应用于传递给 WordPress 链接小部件中函数的参数。wp_list_bookmarks()
  • widget_nav_menu_args– 应用于传递给WordPress自定义菜单小部件中函数的参数。wp_nav_menu()
  • widget_pages_args– 应用于传递给 WordPress Pages 小部件中函数的参数。wp_list_pages()
  • widget_tag_cloud_args– 应用于传递给 WordPress Pages 小部件中函数的参数。wp_tag_cloud()
  • widget_text– 应用于WordPress文本小部件的小部件文本。也可能适用于某些第三方小部件。
  • widget_title- 应用于任何用户可编辑的WordPress小部件的小部件标题。也可能适用于某些第三方小部件。

 

本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
微信号已复制
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证