无法在自定义mets框中保存Rev Slider

时间:2014-09-04 12:10:21

标签: wordpress

我正在为网页创建自定义元框。这个metabox的主要功能之一是能够调用Revolution Slider。此时我可以创建一个下拉列表,显示所有可用的revsliders,但我无法保存并调用它们。下面是我的代码,也许有人可以告诉我我做错了什么。

function simplex_page_theme ($post) {
    $values = get_post_custom($post->ID);   
    $revslider = isset( $values['revslider'] ) ? esc_attr( $values['revslider'][0] ) : ”;
    wp_nonce_field( 'simp_meta_box', 'simplex_meta_box_nonce' );
?>

<tr valign="top">
    <td>
        <?php $revslider = new RevSlider();
        $arrSliders = $revslider->getArrSliders();
        if( empty( $arrSliders ) ) : ?>
            <div style="background-color:#FFFFE0; border:1px solid #E6DB55; padding:0 0.8em; margin:0;">
                <p style="font-weight:bold; margin:7px 0;"><?php printf( __('No sliders found!  Please create a new slider from the %1$sRevolution Slider%2$s page.'), '<a href="admin.php?page=revslider">', '</a>' ); ?></p>
            </div>
        <?php else : ?>
            <label for="current_rev_slider"><?php esc_html_e('Choose a Revolution Slider:'); ?></label><br />
            <select name="rev_slider_shortcode" id="current_rev_slider">
                <option value=""<?php echo (get_option('revslider') == '') ? ' selected="selected"' : ''; ?>><?php esc_html_e('--Select Slider--'); ?></option> 
                <option value="<?php echo $revslider->getShortcode(); ?>"><?php echo $revslider->getTitle(); ?></option> 
                <?php foreach( $arrSliders as $revslider ): ?>
                <?php endforeach; ?>
            </select><br />
            <em><?php  printf( __('To create additional sliders or to configure the existing ones please refer to the %1$sRevolution Slider%2$s page.'), '<a title="'.esc_html__('Go to Revolution Slider page').'" href="admin.php?page=revslider">', '</a>' ); ?></em><br />
            <div class="clear"></div>
        <?php endif; ?>
    </td>
</tr>

<?php }
// Saves the Custom Metabozes
add_action( 'save_post', 'simplex_meta_box_save' );
function simplex_meta_box_save( $post_id ){
    // Bail if we're doing an auto save
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    // if our nonce isn't there, or we can't verify it, bail
    if( !isset( $_POST['simplex_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['simplex_meta_box_nonce'], 'simp_meta_box' ) ) return;

    // if our current user can't edit this post, bail
    if( !current_user_can( 'edit_post' ) ) return;

    // now we can actually save the data
    $htmallowed = array(
        'a' => array( // on allow a tags
            'href' => array() // and those anchors can only have href attribute
        )
    );

    // Make sure your data is set before trying to save it
    if( isset( $_POST['revslider'] ) )
        update_post_meta( $post_id, 'revslider', esc_attr( $_POST['revslider'] ) );

}

1 个答案:

答案 0 :(得分:0)

查看有关创建和保存元框的本教程。它应该指向正确的方向。 http://www.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/