WordPress函数文档do_feed_rss()
获取一个动作钩子被激活的次数 描述 译文 检索动作被激活的次数 原文 Retrieve the number …
获取一个动作钩子被激活的次数
描述
译文
检索动作被激活的次数
原文
Retrieve the number of times an action is fired.
用法
<?php did_action( $tag ); ?>
参数
$tag
(string) (必填) The name of the action hook.
默认值: None
返回值
(integer)
The number of times action hook $tag is fired
示例
Using did_action() function to make sure custom meta field is only added during the first run since it can run multiple times.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
function my_sticky_option()
{
global $post;
// if the post is a custom post type and only during the first execution of the action quick_edit_custom_box
if ( $post->post_type == ‘custom_post_type’ && did_action( ‘quick_edit_custom_box’ ) === 1 )
{
?>
<fieldset class=“inline-edit-col-right”>
<div class=“inline-edit-col”>
<label class=“alignleft”>
<input type=“checkbox” name=“sticky” value=“sticky” />
<span class=“checkbox-title”>
<?php _e( ‘Featured (sticky)’, ‘textdomain_string’ ); ?>
</span>
</label>
</div>
</fieldset>
<?php
} // endif;
}
// add the sticky option to the quick edit area
add_action( ‘quick_edit_custom_box’, ‘my_sticky_option’ );
|
注意
- 使用到 global: (unknown type) $wp_actions
历史
添加于 版本: 2.1
源文件
did_action() 函数的代码位于 wp-includes/plugin.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Retrieve the number of times an action is fired.
*
* @since 2.1.0
*
* @global array $wp_actions Increments the amount of times action was triggered.
*
* @param string $tag The name of the action hook.
* @return int The number of times action hook $tag is fired.
*/
function did_action($tag) {
global $wp_actions;
if ( ! isset( $wp_actions[ $tag ] ) )
return 0;
return $wp_actions[$tag];
}
|
相关
Actions:
has_action(),
add_action(),
do_action(),
do_action_ref_array(),
did_action(),
remove_action(),
remove_all_actions()
- 原文:http://codex.wordpress.org/Function_Reference/did_action
类别:WordPress函数文档、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!