我在Wordpress上插入自定义选项页面媒体按钮时有些疑惑。我得到了下面我一直使用的代码,用于在wordpress上创建自定义页面选项,仅使用text / textarea输入。
有人可以帮我弄明白如何插入"媒体按钮"上传文件或获取mymedia上的图片?像这样:
<?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ções feitas com sucesso! Recarregue a página principal.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>Configuraçõ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çõ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');
?>