do_feed()调用do_feed的hook钩子

目录

描述

译文

使用action钩子(hook)装载feed模板。

如果feed action没有钩子,函数会发布信息通知访问者feed不可用,之后函数消失。

每个feed最好只配备一个钩子。

原文

Loads the feed template from the use of an action hook.

If the feed action does not have a hook, then the function will die with a message telling the visitor that the feed is not valid.

It is better to only have one hook for each feed.

do_feed() 描述

用法

<?php do_feed() ?>

do_feed() 用法

参数

None.

do_feed() 参数

返回值

(void) 

This function does not return a value.

do_feed() 返回值

注意

  • 使用到: get_query_var() to get 'feed' from $wp_query.
  • 使用到: do_action() 调用 'do_feed_$feed' hook, if a hook exists for the feed where $feed is the 'feed' property from $wp_query.
  • 使用到 global: (object) $wp_query Used to tell if the use a comment feed.

do_feed() 注意

历史

添加于 版本: 2.1.0

do_feed() 历史

源文件

do_feed() 函数的代码位于 wp-includes/functions.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Load the feed template from the use of an action hook.
 *
 * If the feed action does not have a hook, then the function will die with a
 * message telling the visitor that the feed is not valid.
 *
 * It is better to only have one hook for each feed.
 *
 * @since 2.1.0
 *
 * @global WP_Query $wp_query Used to tell if the use a comment feed.
 */
function do_feed() {
	global $wp_query;

	$feed = get_query_var( 'feed' );

	// Remove the pad, if present.
	$feed = preg_replace( '/^_+/', '', $feed );

	if ( $feed == '' || $feed == 'feed' )
		$feed = get_default_feed();

	$hook = 'do_feed_' . $feed;
	if ( ! has_action( $hook ) )
		wp_die( __( 'ERROR: This is not a valid feed template.' ), '', array( 'response' => 404 ) );

	/**
	 * Fires once the given feed is loaded.
	 *
	 * The dynamic hook name, $hook, refers to the feed name.
	 *
	 * @since 2.1.0
	 *
	 * @param bool $is_comment_feed Whether the feed is a comment feed.
	 */
	do_action( $hook, $wp_query->is_comment_feed );
}

do_feed() 源文件