返回介绍

did_action()

发布于 2017-09-10 22:10:08 字数 4646 浏览 1124 评论 0 收藏 0

did_action( string $tag )

Retrieve the number of times an action is fired.


description


参数

$tag

(string) (Required) The name of the action hook.


返回值

(int) The number of times action hook $tag is fired.


源代码

File: wp-includes/plugin.php

function did_action($tag) {
	global $wp_actions;

	if ( ! isset( $wp_actions[ $tag ] ) )
		return 0;

	return $wp_actions[$tag];
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Used By

  • wp-includes/class-wp-editor.php: _WP_Editors::enqueue_default_editor()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::_publish_changeset_values()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::import_theme_starter_content()
  • wp-includes/theme.php: _wp_customize_publish_changeset()
  • wp-includes/class-wp-site.php: WP_Site::__get()
  • wp-includes/class-wp-site.php: WP_Site::__isset()
  • wp-includes/theme.php: add_theme_support()
  • wp-includes/theme.php: _remove_theme_support()
  • wp-includes/general-template.php: wp_admin_css()
  • wp-includes/load.php: wp_load_translations_early()
  • wp-includes/functions.php: _default_wp_die_handler()
  • wp-includes/taxonomy.php: create_initial_taxonomies()
  • wp-includes/media.php: wp_enqueue_media()
  • wp-includes/embed.php: wp_oembed_add_provider()
  • wp-includes/embed.php: wp_oembed_remove_provider()
  • wp-includes/media.php: wp_video_shortcode()
  • wp-includes/media.php: wp_audio_shortcode()
  • wp-includes/class-wp-rewrite.php: WP_Rewrite::wp_rewrite_rules()
  • wp-includes/class-wp-rewrite.php: WP_Rewrite::flush_rules()
  • wp-includes/ms-blogs.php: switch_to_blog()
  • wp-includes/ms-blogs.php: restore_current_blog()
  • wp-includes/wp-db.php: wpdb::check_connection()
  • wp-includes/wp-db.php: wpdb::select()
  • wp-includes/widgets.php: wp_register_sidebar_widget()
  • wp-includes/widgets.php: wp_register_widget_control()
  • wp-includes/widgets.php: _register_widget_form_callback()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::call_widget_update()
  • wp-includes/script-loader.php: print_head_scripts()
  • wp-includes/script-loader.php: wp_print_head_scripts()
  • wp-includes/script-loader.php: script_concat_settings()
  • wp-includes/script-loader.php: wp_default_scripts()
  • Show 26 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: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Example

    Using did_action() function to make sure custom meta field is only added during the first run since it can run multiple times.

    
    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' );
    

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

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

发布评论

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