Skip to content

Instantly share code, notes, and snippets.

@themefoundation
Created January 9, 2013 18:56

Revisions

  1. themefoundation created this gist Jan 9, 2013.
    37 changes: 37 additions & 0 deletions using-input-class-demo.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    <?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()