Advertisement
Guest User

WP_Alchemy Metabox Functions for Media Uploader

a guest
Feb 1st, 2011
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2.  
  3. //define some constants
  4. define('FUNCTIONS_PATH', STYLESHEETPATH . '/functions/');
  5. define('FUNCTIONS', get_bloginfo('stylesheet_directory') . '/functions/');
  6.  
  7.  
  8. // Require WP_Alchemy Meta Box Class
  9. require_once(FUNCTIONS_PATH . 'WPAlchemy/MetaBox.php');
  10.  
  11. // include css to help style our custom meta boxes
  12. // this should be a global stylesheet used by all similar meta boxes
  13. if (is_admin()) wp_enqueue_style('custom_meta_css', FUNCTIONS .'WPAlchemy/meta.css');
  14.  
  15. // Define Metaboxes
  16.  
  17. $featured_metabox = new WPAlchemy_MetaBox(array
  18. (
  19.     'id' => '_featured_meta', // underscore prefix hides fields from the custom fields area
  20.     'title' => _('Add Slides'),
  21.     'template' => FUNCTIONS_PATH .'WPAlchemy/new_featured_meta.php',
  22.     'prefix' => '_featured_meta_',
  23.     'types' => array('page'),
  24.     'priority' => 'high',
  25.     'init_action' => 'featured_init_action', // defaults to NULL
  26.     'head_action' => 'featured_head_action',
  27.  
  28.    
  29. ));
  30.  
  31.  
  32. function featured_init_action(){
  33.     wp_enqueue_script('jquery-ui',  'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js' , array( 'jquery' ));
  34. }
  35.  
  36. function featured_head_action() {
  37. global $featured_metabox; ?>
  38.     <script type='text/javascript'>
  39.     /* <![CDATA[ */
  40.  
  41.     //avoid jquery flicker
  42.     document.write('<style type="text/css">body{display:none}</style>');
  43.  
  44.     jQuery(document).ready(function($) {
  45.  
  46.     $('#js-warning').hide();
  47.    
  48. /*
  49.  * Change title of custom slide on change of input box
  50.  */
  51. $('.slide_title').live('change', function() {
  52.   $(this).parents('.wpa_group').children('h4:first').html("<?php _e('Custom Slide: ');?>" + $(this).val());
  53. });
  54.  
  55.  
  56. var formfield;
  57. $('.upload_image_button').live('click', function() {
  58.     formfield = $(this).prev('input');
  59.     tb_show('', 'media-upload.php?type=image&TB_iframe=true');
  60.     return false;
  61. });
  62.  
  63. window.original_send_to_editor = window.send_to_editor;
  64. window.send_to_editor = function(html){
  65.     if (formfield) {
  66.         fileurl = $('img',html).attr('src');
  67.         formfield.val(fileurl);
  68.         formfield.prev('img').attr('src',fileurl).fadeIn();
  69.         tb_remove();
  70.         formfield = ''; //reset formfield to null so original works
  71.     } else {
  72.         window.original_send_to_editor(html);
  73.     }
  74. };
  75.    
  76.     });  
  77.    
  78.    
  79.  
  80.  
  81.  
  82.     /* ]]> */
  83. </script> <?php
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement