Skip to content

Instantly share code, notes, and snippets.

@themefoundation
Created January 9, 2013 18:56
Show Gist options
  • Save themefoundation/4495791 to your computer and use it in GitHub Desktop.
Save themefoundation/4495791 to your computer and use it in GitHub Desktop.
Using the form input class.
<?php
/**
* Displays metabox content
*
* Displays metabox content based on the metabox array, usually set in the
* theme's functions.php file.
*
* @since 1.0
* @param array $post The current post object.
* @param array $metabox_fields The fields that will populate the metabox.
*/
function thtk_display_metabox_content( $post, $metabox_fields ) {
echo '<div class="thtk-metabox"><table class="form-table">';
// Sets security nonce
wp_nonce_field( 'thtk_metabox_nonce', 'metabox_nonce' );
// Gets stored values from the database.
$values = get_post_custom( $post->ID );
// Loops through each array element and calls the corresponding display function.
foreach( $metabox_fields[ 'args' ] as $metabox_field ) {
// Sets previously stored value and checks for new description.
$metabox_field[ 'value' ] = isset( $values[ $metabox_field[ 'id' ] ] ) ? esc_attr( $values[ $metabox_field[ 'id' ] ][ 0 ] ) : '';
// Uses the THTK_Form_Metabox class to dispay the metabox setting.
$thtk_input = new THTK_Form_Metabox( $metabox_field );
echo $thtk_input->get_metabox();
} // End foreach $metabox_fields[ 'args' ]
// HTML to match WordPress native formatting.
echo '</table></div><!-- .thtk-metabox -->';
} // End thtk_display_metabox_content()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment