I'm trying to use the did_action() function to avoid running my functions more than one time, like this:
function create_my_fields( $meta_boxes ) {
/*
* Check if the action has been fired before or not.
* The rest of the code will be run only on the first time that the action is triggered.
*/
if ( did_action( 'rwmb_meta_boxes' ) !== 1 )
return;
$meta_boxes[] = [
'title' => '...',
'id' => '...',
'post_types' => '...',
'context' => '...',
'fields' => [
...
],
];
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'create_my_fields' );
Here, I'm trying to avoid running the code more than one time, but the value of did_action( 'rwmb_meta_boxes' )
is always 0
.
This do_action
function works fine with the native actions of WordPress, but it didn't work as expected with the rwmb_meta_boxes
one. Is it something that you have to support? Or there's something wrong here?