3
/**
 * Fires after meta boxes have been added.
 *
 * Fires once for each of the default meta box contexts: normal, advanced, and side.
 *
 * @since 3.0.0
 *
 * @param string  $post_type Post type of the post.
 * @param string  $context   string  Meta box context.
 * @param WP_Post $post      Post object.
 */
do_action( 'do_meta_boxes', $post_type, 'normal', $post );

I found these in wp-admin/edit-form-advanced.php and I can't figure out purpose of these actions ( checked for add_action( 'do_meta_boxes' ... ) there is no such actions ).

Documentation says

Fires after meta boxes have been added.

Fires once for each of the default meta box contexts: normal, advanced, and side.

But what's purpose is for these action? When should I use these actions?

NOTE: it's not the same as do_meta_boxes() function and has nothing common with it!

5
  • do_meta_boxes Can be used to manipulate the previously registered meta boxes but before they are echoed. It fires after add_meta_boxes hook.
    – Ignat B.
    Commented Sep 8, 2015 at 15:37
  • add_meta_boxes can be used to manipulate previosly registred meta boxes to... i.e. that there should be some othere reason why they puted these action..
    – Maikal
    Commented Sep 8, 2015 at 15:40
  • Dont get you.. what i'm saying is that add_meta_boxes - registering of metabox do_meta_boxes - displaying metabox
    – Ignat B.
    Commented Sep 8, 2015 at 15:45
  • do_meta_boxes hook isn't for displaying meta boxes.. do_meta_boxes function is for displaying meta boxes.. if you try to echo something in do_meta_boxes hook it will show an error headers already sent.
    – Maikal
    Commented Sep 8, 2015 at 15:48
  • Again, do_meta_boxes hook fires when meta box have been added but before echoed. You can test it, for example, to remove the "featured image" meta_box from your editor. function test_callback($page, $context, $post){ remove_meta_box( 'postimagediv', $page, $context ); } add_action( 'do_meta_boxes', 'test_callback', 10,3 );
    – Ignat B.
    Commented Sep 8, 2015 at 16:28

1 Answer 1

0

As explained here:

[The] do_meta_boxes [action] is designed to let people manipulate the registered meta boxes once they are registered but before they are rendered.

So the do_meta_boxes hook is not for doing (that is: displaying) the meta boxes. This is because:

When the do_meta_boxes actions was moved out of do_meta_boxes() it should have had its name changed. add_meta_boxes was added in 3.0 to be the hook that we should have renamed do_meta_boxes to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.