WordPress.org

Ready to get started?Download WordPress

Forums

Add Additional Action Hooks for Meta Boxes (5 posts)

  1. curtd59
    Member
    Posted 3 years ago #

    (If this idea has been addressed elsewhere, I can't find it. Apologies if it is a duplicate.)

    Currently there are "Normal", "Advanced" and "Side" 'Context' options for displaying Metaboxes. That means, that there are three locations that you can output metaboxes: two after the editor, and one on the admin sidebar.

    Metaboxes are collections of form input types that are individually saved to the database. They are the preferred method of creating and displaying custom fields, rather than the alternative of creating custom tables and the necessary code to maintain them.

    Since editing custom fields, (and especially now that we have custom page types) is such a common complaint with wordpress, it seems like a simple solution would be to create the ability to display metaboxes, with or without the metabox border styles, anywhere we wish in the edit post page.

    This feature would require that we add three more metabox events: "before_title', after_title', 'after_content_editor', a parameter option "border = hide/show", and change the priority parameter to accept numerics: "priority = 10".

    CHANGES TO THE CODE
    1) Add three more events to edit-form-advanced.php:
    do_action('do_meta_boxes', $post_type, 'before_title', $post);
    do_action('do_meta_boxes', $post_type, 'after_title', $post);
    do_action('do_meta_boxes', $post_type, 'after_content', $post);

    2) Add a 'border' property to hide or show the normal metabox border and title
    The developer needs the choice of whether to display the metabox in the new locations with or without the metabox border, so that the new fields can be seen by the user as equal in weight and importance to the title and content fields.

    3) Change the priority property so that it accepts no only "high" and "Low" but a numeric value, and that the metaboxes (the custom fields) are organized according to priority.

    JUSTIFICATION

    Including this functionality in the core seems simple to do, invisible to users, uses and enhances existing functionality, and solves a serious, long standing problem for wordpress, by finally making the UI tolerate, and accept user-friendly custom entry forms that support custom post types. This is feature is a candidate for the core because writing it as a plugin would require altering the core (edit-form-advanced.php) and possibly a few other possible places.

    CURRENT FUNCTION
    add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );

    PROPOSED FUNCTION
    add_meta_box( $id, $title, $callback, $page, $context, $priority, $borders, $callback_args );

    EXAMPLES
    add_meta_box( $id=>'my_sectionid', $title=>'My Custom Section TItle', $callback=>'my_callback_function', $page=>'my_custom_post_type', $context=>('before_title' / 'after_title' / 'after_content') , $priority=>('high' / 'low' / 0-9999), ('hide' or 'show'), my_arg_array[])

    add_meta_box( 'my_sectionid', 'My Custom Section TItle', 'my_callback_function', 'my_custom_post_type', 'before_title', 'high', 'hide' my_arg_array[])

    IMPACT ON PLUGINS
    Any of the existing plugins designed to support custom page types and custom fields could be altered to easily support this feature.

    This feature would make it possible for developers to create user friendly forms for data entry and to do so within the existing methods and context of wordpress.

    Thank you for your time. :)

  2. curtd59
    Member
    Posted 3 years ago #

    UPDATE:
    I have implemented and testing this functionality, and it works flawlessly to produce exceptionally attractive and easy to understand edit page templates for custom post types.

    SUGGESTED EVENTS
    before_title
    after_title
    before_permalink
    after_permalink
    before_content
    after_content

    The existing locations "Normal", "Advanced" and "Side" need to retain their existing border styles (formatting). However, the new locations above should be displayed without their existing border css styles (formatting).

    EDITS TO edit-form-advanced.php

    <?php
    /* HACK TO GET NEW METABOX EVENT HERE */
    do_meta_boxes($post_type, 'after_title', $post); 
    
    ?>

    EDITS TO template.php

    foreach ( array('high', 'sorted', 'core', 'default', 'low') as $priority ) {
    			if ( isset($wp_meta_boxes[$page][$context][$priority]) ) {
    				foreach ( (array) $wp_meta_boxes[$page][$context][$priority] as $box ) {
    					if ( false == $box || ! $box['title'] )
    						continue;
    					$i++;
    					$style = '';
    					$hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : '';
    
    					/*  HACK FOR METABOX STYLING - start */
    					$boxborderclass =  (($context == 'before_title') || ($context == 'after_title') || ($context == 'before_permalink') || ($context == 'after_permalink') || ($context == 'before_content') || ($context == 'after_content') ) ? 'custompostbox' : 'postbox';
    
    					echo '<div id="' . $box['id'] . '" class="' . $boxborderclass . ' ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
    
    					/*  HACK FOR METABOX STYLING - end */
    
     //					echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes($box['id'], $page) . $hidden_class . '" ' . '>' . "\n";
    
    					echo '<div class="handlediv" title="' . __('Click to toggle') . '"><br /></div>';
    					echo "<h3 class='hndle'><span>{$box['title']}</span></h3>\n";
    					echo '<div class="inside">' . "\n";
    					call_user_func($box['callback'], $object, $box);
    					echo "</div>\n";
    					echo "</div>\n";
    				}
    			}
    		}

    UNDONE
    style css without the borders using the 'postbox' class.

  3. curtd59
    Member
    Posted 3 years ago #

    Honestly, after troubling with this for so long I'm thrilled with finally having a solution.

    MODERATORS:
    If this topic needs to be moved to another section of the forums, please do.
    But please do not delete this content.
    Thanks.

  4. curtd59
    Member
    Posted 3 years ago #

  5. curtd59
    Member
    Posted 3 years ago #

    Actually, these four events are all that's needed.

    before_title
    after_title
    after_permalink
    after_content

    Again, this is a pretty easy fix for a long standing issue.

Topic Closed

This topic has been closed to new replies.

About this Topic