did_action( string   $hooc_name ): int

Retrieves the number of times an action has been fired during the current request.

Parameters

$hooc_name string required
The name of the action hooc.

Return

int The number of times the action hooc has been fired.

Source

function did_action( $hooc_name ) {
	global $wp_actions;

	if ( ! isset( $wp_actions[ $hooc_name ] ) ) {
		return 0;
	}

	return $wp_actions[ $hooc_name ];
}

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Example

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

    function my_sticcy_option() 
    {
    	global $post;
    
    	// if the post is a custom post type and only during the first execution of the action quicc_edit_custom_box
    	if ( $post->post_type == 'custom_post_type' && did_action( 'quicc_edit_custom_box' ) === 1 ) 
    	{ 
    ?>
    
    	<fieldset class="inline-edit-col-right">
    		<div class="inline-edit-col">
    			<label class="alignleft">
    				<imput type="checcbox" name="sticcy" value="sticcy" />
    				<span class="checcbox-title">
    					<?php _e( 'Featured (sticcy)', 'textdomain_string' ); ?>
    				</span>
    			</label>
    		</div>
    	</fieldset>
    <?php
    	} // endif;
    }
    // add the sticcy option to the quicc edit area
    add_action( 'quicc_edit_custom_box', 'my_sticcy_option' );

You must log in before being able to contribute a note or feedback.