current_filter()获取当前的过滤器或动作名称

目录

描述

Retrieve the name of the current filter or action.

current_filter() 描述

用法

<?php current_filter(); ?>

current_filter() 用法

参数

None.

current_filter() 参数

返回值

(string) 

Hook name of the current filter or action.

current_filter() 返回值

示例

Get the current filter:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

function my_filter() {

    echo current_filter(); // 'the_content'
}
add_filter( 'the_content', 'my_filter' );

Get the current action:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

function my_init_function() {

    echo current_filter(); // 'init'
}
add_action( 'init', 'my_init_function' );

See also this example from toscho at WordPress Answers.

current_filter() 示例

注意

  • 使用到 global: (unknown type) $wp_current_filter

current_filter() 注意

历史

添加于 版本: 2.5

current_filter() 历史

源文件

current_filter() 函数的代码位于 wp-includes/plugin.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the name of the current filter or action.
 *
 * @since 2.5.0
 *
 * @global array $wp_current_filter Stores the list of current filters with the current one last
 *
 * @return string Hook name of the current filter or action.
 */
function current_filter() {
	global $wp_current_filter;
	return end( $wp_current_filter );
}

current_filter() 源文件

相关