如何在自定义选项页面@ Wordpress中插入媒体按钮

时间:2014-12-21 14:28:11

标签: php wordpress

我在Wordpress上插入自定义选项页面媒体按钮时有些疑惑。我得到了下面我一直使用的代码,用于在wordpress上创建自定义页面选项,仅使用text / textarea输入。

有人可以帮我弄明白如何插入"媒体按钮"上传文件或获取mymedia上的图片?像这样:

enter image description here

<?php 

$header_featured = array( 
    array( "name" => __('Featured #1 - Título'), "desc" => __(""), "id" => "featured_1_title", "std" => "", "type" => "text" ),
    array( "name" => __('Featured #1 - Descrição'), "desc" => __(""), "id" => "featured_1_text", "std" => "", "type" => "textarea" )    
); 

function header_featured_add_admin() {

    global $themename, $shortname, $header_featured;

    if ( $_GET['page'] == basename(__FILE__) ) {

        if ( 'save' == $_REQUEST['action'] ) {

                foreach ($header_featured as $k => $value) {
                    update_option( $value[ $k ], $_REQUEST[ $k ] ); }

                foreach ($header_featured as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }

                header("Location: admin.php?page=featured_options.php&saved=true");
                die;

        } else if( 'reset' == $_REQUEST['action'] ) {

            foreach ($header_featured as $value) {
                delete_option( $value['id'] ); }

            header("Location: admin.php?page=featured_options.php&reset=true");
            die;

        } else if ( 'reset_widgets' == $_REQUEST['action'] ) {
            $null = null;
            update_option('sidebars_widgets',$null);
            header("Location: admin.php?page=featured_options.php&reset=true");
            die;
        }
    }
    add_menu_page("Destaque", "Destaque", 'edit_dashboard', basename(__FILE__), 'header_featured_admin');

}

function header_featured_admin() {

    global $themename, $shortname, $header_featured;

    if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>Altera&ccedil;&otilde;es feitas com sucesso! Recarregue a p&aacute;gina principal.</strong></p></div>';
    if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>Configura&ccedil;&otilde;es resetadas.</strong></p></div>';
    if ( $_REQUEST['reset_widgets'] ) echo '<div id="message" class="updated fade"><p><strong>Widgets resetados.</strong></p></div>';

?>

<div="wrap">
<style type="text/css">
#fk_painel { display: block; }
#fk_painel i{ font-size: 11px; }

#fk_painel input[type=text] { width: 600px; display: block; }
#fk_painel #wp-blog_columnistbio-wrap { width: 600px; }
#wpfooter { display: none; }
</style>

<h2>Destaque</h2>

<form method="post" action="" id="fk_painel">

<table class="form-table">

    <?php 
    foreach ($header_featured as $option => $value) { 
    switch ( $value['type'] ) {
    case 'text':
    ?>
        <tr valign="top">
            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo _e($value['name'],'ohayo'); ?></label></th>
            <td>
                <input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { echo $value['std']; } ?>" />
                <?php echo _e($value['desc'],'ohayo'); ?>

            </td>
        </tr>

    <?php
    break;
    case 'textarea':
    ?>
        <tr valign="top">
            <th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo _e($value['name'],'ohayo'); ?></label></th>
            <td>
            <?php the_editor(get_option($value['id']) != "" ? _e(get_option($value['id']),'ohayo') : _e($value['std'],'ohayo'), $value['id']);?>
            <br /><?php echo _e($value['desc'],'ohayo'); ?></td>
        </tr>

<?php
        break;

    }
}
?>

    </table>

    <p class="submit">
        <input name="save" type="submit" value="<?php _e('Salvar altera&ccedil;&otilde;es','ohayo'); ?>" />
        <input type="hidden" name="action" value="save" />
    </p>
</form>
<form method="post" action="">
    <p class="submit">
        <input name="reset" type="submit" value="<?php _e('Resetar','ohayo'); ?>" />
        <input type="hidden" name="action" value="reset" />
    </p>
</form>

<style type="text/css">#footer { display: none; }</style>
</div>
<?php
}

add_action('admin_menu' , 'header_featured_add_admin'); 
?>

0 个答案:

没有答案