Created
August 16, 2010 15:32
-
-
Save littlefyr/527139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$highlight_metabox = new WPAlchemy_MetaBox(array | |
( | |
'id' => '_metabox', | |
'title' => 'My Custom Custom Meta', | |
'types' => array('page'), | |
'template' => STYLESHEETPATH . '/custom/metabox.php' | |
)); | |
function my_admin_scripts() { | |
wp_enqueue_style('custom_meta_css', dirname(get_stylesheet_uri()). '/custom/meta.css'); | |
wp_register_script('meta-upload', dirname(get_stylesheet_uri()).'/js/meta-upload.js', array('jquery','media-uload','thickbox')); | |
wp_enqueue_script('meta-upload'); | |
} | |
function my_admin_styles() { | |
wp_enqueue_style('thickbox'); | |
} | |
if (is_admin()) { | |
add_action('admin_print_scripts', 'my_admin_scripts'); | |
add_action('admin_print_styles', 'my_admin_styles'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Adapted from: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ | |
jQuery(function($,undefined){ | |
// we start by making local references to some global objects so this | |
// will compress well. | |
var win=window, | |
doc=document, | |
current_upload_src, | |
original_send_to_editor = window.send_to_editor; | |
$(".upload").delegate('input.library', 'click',{}, function(event) { | |
var that = $(this), | |
caption = that.attr('title'); | |
current_upload_src = that.siblings("input.src"); | |
$("html").addClass("Image"); | |
tb_show(caption, 'media-upload.php?type=image&TB_iframe=true'); | |
return false; | |
}); | |
window.send_to_editor = function(html){ | |
if (!!original_send_to_editor) { | |
var fileurl = $('img', html).attr("src"); | |
current_upload_src.val(fileurl); | |
current_upload_src.siblings(".preview").find("img").attr('src', fileurl); | |
$("html").removeClass("Image"); | |
tb_remove(); | |
current_upload_src = null; | |
} else { | |
window.original_send_to_editor(html); | |
} | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label>Mug Shot</label> | |
<p class="upload"> | |
<?php $metabox->the_field('mugshot'); ?> | |
<input class="src" type="text" size="36" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>" /> | |
<input class="library" type="button" value="Upload Image" title="Upload a mugshot" /> | |
<span class="preview"><img src='<?php $metabox->the_value(); ?>' style="max-width:300px;max-height:300px"</span> | |
<span>Upload an image</span> | |
</p> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment