WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#31559 new enhancement

Meta boxes should have before/after hooks

Reported by: jtsternberg Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch 2nd-opinion
Focuses: administration Cc:
PR Number:

Description

Currently there is no way to hook into an existing metabox. If I wanted to modify the featured image metabox (add a checkbox or something), I'd have to unregister the metabox, and re-register w/ my own callback. This is not good for compatibility w/ other plugins, etc.

I propose before_callback and after_callback hooks for metaboxes.

Basically, we'd replace this:

echo '<div class="inside">' . "\n";
call_user_func($box['callback'], $object, $box);
echo "</div>\n";

with:

echo '<div class="inside">' . "\n";

do_action( 'before_metabox_callback', $object, $box );
do_action( "before_{$box['id']}_metabox_callback", $object, $box );

call_user_func($box['callback'], $object, $box);

do_action( 'after_metabox_callback', $object, $box );
do_action( "after_{$box['id']}_metabox_callback", $object, $box );

echo "</div>\n";

Attachments (1)

31559.diff (2.2 KB) - added by jtsternberg 5 years ago.

Download all attachments as: .zip

Change History (6)

@jtsternberg
5 years ago

#1 @jtsternberg
5 years ago

  • Keywords has-patch 2nd-opinion added

#2 @helen
5 years ago

I'd rather see this on a case-by-case basis - maintaining something like this into the future seems painful at best.

#3 @iseulde
5 years ago

  • Version trunk deleted

#4 @Cybr
4 years ago

I'd like to see more extensibility on these features too. Adding extra meta boxes on the same subject seems unorganized and adds unneeded clutter.

A simple filter or a do_action() would be nice.

e.g.:

// Line 763 meta-boxes.php:
<p><strong><?php _e('Order') ?></strong></p>
<p><label class="screen-reader-text" for="menu_order"><?php _e('Order') ?></label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order) ?>" /></p>

<?php do_action( 'after_page_attributes_meta_box' ); ?>

<?php if ( 'page' == $post->post_type && get_current_screen()->get_help_tabs() ) { ?>
<p><?php _e( 'Need help? Use the Help tab in the upper right of your screen.' ); ?></p>
<?php
	}

A nice scenario would be to add the wpautop filter option to that section through a plugin.

#5 @DrewAPicture
3 years ago

#34675 was marked as a duplicate.

Note: See TracTickets for help on using tickets.