Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Last active August 29, 2015 14:12
Show Gist options
  • Save vimes1984/fff0cdf2a5373be891a0 to your computer and use it in GitHub Desktop.
Save vimes1984/fff0cdf2a5373be891a0 to your computer and use it in GitHub Desktop.
<?php
function add_theme_menu_pages(){
add_menu_page( 'Main options', 'Theme settings', 'manage_options', 'dance_theme_settings', 'dance_theme_settings');
add_submenu_page( 'dance_theme_settings', 'Shop page settings', 'Shop page settings', 'manage_options', 'shop-page-options', 'shop_page_options_func' );
}
function dance_theme_settings(){
echo "dance_theme_settings....";
}
function shop_page_options_func(){
if(function_exists( 'wp_enqueue_media' )){
wp_enqueue_media();
}else{
wp_enqueue_style('thickbox');
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
}
if (isset($_POST["update_settings"])) {
// Do the saving
$custom_media_url_shop = esc_attr($_POST["custom_media_url_shop"]);
update_option("custom_media_url_shop", $custom_media_url_shop);
$custom_shop_page_title = esc_attr($_POST["custom_shop_page_title"]);
update_option("custom_shop_page_title", $custom_shop_page_title);
$custom_shop_page_sub_title = esc_attr($_POST["custom_shop_page_sub_title"]);
update_option("custom_shop_page_sub_title", $custom_shop_page_sub_title);
?>
<div id="message" class="updated">Settings saved</div>
<?php
}else{
$custom_media_url_shop = get_option("custom_media_url_shop");
$custom_shop_page_title = get_option("custom_shop_page_title");
$custom_shop_page_sub_title = get_option("custom_shop_page_sub_title");
}
?>
<div class="wrap">
<?php screen_icon('themes'); ?> <h2>Shop, Cart and checkout page options</h2>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.custom_media_upload').click(function() {
var send_attachment_bkp = wp.media.editor.send.attachment;
var button = $(this);
wp.media.editor.send.attachment = function(props, attachment) {
$(button).prev().prev().attr('src', attachment.url);
$(button).prev().val(attachment.url);
wp.media.editor.send.attachment = send_attachment_bkp;
}
wp.media.editor.open(button);
return false;
});
</script>
<style>
.form-table.shopagesettings tr.lasttr{ border: 0; border-bottom: 2px solid #ddd; }
</style>
<h4>Please keep all these settintgs filled...</h4>
<form method="POST" action="">
<input type="hidden" name="update_settings" value="Y" />
<table class="form-table shopagesettings">
<tr valign="top">
<th scope="row">
<label for="shoppage_head_img">
Shop page header image:
</label>
</th>
<td>
<!-- Image Thumbnail -->
<img class="custom_media_image" src="<?php echo $custom_media_url_shop;?>" style="max-width:100px; float:left; margin: 0px 10px 0px 0px; display:inline-block;" />
<!-- Upload button and text field -->
<input class="custom_media_url_shop" id="" type="text" name="custom_media_url_shop" value="<?php echo $custom_media_url_shop;?>" style="margin-bottom:10px; clear:right;">
<a href="#" class="button custom_media_upload">Upload</a>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="custom_shop_page_title">
Shop page title:
</label>
</th>
<td>
<input type="text" name="custom_shop_page_title" placeholder="shop page header text" value="<?php echo $custom_shop_page_title; ?>">
</td>
</tr>
<tr valign="top" class="lasttr">
<th scope="row">
<label for="custom_shop_page_sub_title">
Shop page sub title:
</label>
</th>
<td>
<input type="text" name="custom_shop_page_sub_title" placeholder="shop page sub header" value="<?php echo $custom_shop_page_sub_title; ?>">
</td>
</tr>
</table>
<input type="submit" value="Save settings" class="button-primary"/>
</form>
</div>
<?php
}
add_action( 'admin_menu', 'add_theme_menu_pages' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment