BREBoostrapCarouselMetabox

Carousel.

Defined (1)

The class is defined in the following location(s).

/admin/boostrap-carousel.class.php  
  1. class BREBoostrapCarouselMetabox { 
  2. static function init() { 
  3. add_action( 'admin_init', array( __CLASS__, 'admin_init' ) ); 
  4.  
  5. static function admin_init() { 
  6. add_action( 'post_edit_form_tag', array( __CLASS__, 'post_edit_form_tag' ) ); 
  7. add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) ); 
  8. add_action( 'save_post', array( __CLASS__, 'save_post' ) ); 
  9. add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); 
  10.  
  11. static function post_edit_form_tag() { 
  12. echo ' enctype="multipart/form-data"'; 
  13.  
  14. static function add_meta_boxes() { 
  15. $post_types = get_post_types( array( 'public' => true ) ); 
  16. foreach( $post_types as $post_type ) 
  17. add_meta_box( 'bre_carousel', __( 'Carousel', 'bre-bootstrap-ecommerce' ), array( __CLASS__, 'bre_carousel_meta_box' ), $post_type, 'side', 'high' ); 
  18.  
  19. static function bre_carousel_meta_box( $post ) {  
  20. $bre_add_to_home_carousel = bre_is_added_to_home_carousel( $post->ID ); 
  21. $bre_image_for_carousel = bre_get_image_for_carousel( $post->ID ); ?> 
  22. <?php wp_nonce_field( 'bre_carousel_noncename', 'bre_carousel_noncename' ); ?> 
  23. <p> 
  24. <label for="bre_add_to_home_carousel"><?php _e( 'Add to carousel of carousel template', 'bre-bootstrap-ecommerce' ); ?></label> 
  25. <input type="checkbox" name="bre_add_to_home_carousel" id="bre_add_to_home_carousel" value="yes" <?php checked( $bre_add_to_home_carousel ); ?> /> 
  26. </p> 
  27. <p> 
  28. <label for="bre_add_to_home_carousel"><?php _e( 'Image to add', 'bre-bootstrap-ecommerce' ); ?>:</label> 
  29. <br/> 
  30. <?php if ( isset( $bre_image_for_carousel['url'] ) ) : ?> 
  31. <a href="<?php echo $bre_image_for_carousel['url']; ?>" target="_blank""> 
  32. <img width="266" height="207" alt="" class="attachment-post-thumbnail" src="<?php echo $bre_image_for_carousel['url']; ?>"> 
  33. </a> 
  34. <label><?php _e( 'Delete Image', 'bre-bootstrap-ecommerce' ); ?> <input type="checkbox" name="bre_image_for_carousel-remove" value="yes" /></label><br/> 
  35. <?php endif; ?> 
  36. <input name="bre_image_for_carousel" id="bre_image_for_carousel" type="file" style="width:10em" /> 
  37. <p class="description"><?php _e( 'If you upload a new file, existing one will be deleted.', 'bre-bootstrap-ecommerce' ); ?></p> 
  38. <p class="description"><?php _e( 'Remember to Save or Update to upload or delete the image.', 'bre-bootstrap-ecommerce' ); ?></p> 
  39. </p> 
  40. <?php } 
  41.  
  42. static function save_post( $post_id ) { 
  43. if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; 
  44. if ( ! wp_verify_nonce( isset( $_POST['bre_carousel_noncename'] ) ? $_POST['bre_carousel_noncename'] : '', 'bre_carousel_noncename' ) ) return $post_id; 
  45. unset( $_POST['bre_carousel_noncename'] ); 
  46. update_post_meta( $post_id, 'bre_add_to_home_carousel', isset( $_POST['bre_add_to_home_carousel'] ) ); 
  47. if ( isset( $_FILES['bre_image_for_carousel'] ) && strlen( $_FILES['bre_image_for_carousel']['tmp_name'] ) > 0 ) { 
  48. $upload = get_post_meta( $post_id, 'bre_image_for_carousel', true ); 
  49. if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); 
  50. $upload = wp_handle_upload( $_FILES['bre_image_for_carousel'], array( 'test_form' => false ) ); 
  51. if ( isset( $upload['error'] ) && '0' != $upload['error'] ) { 
  52. wp_die( __( 'There was an error uploading the file.', 'bre-bootstrap-ecommerce' ) ); 
  53. } else { 
  54. update_post_meta( $post_id, 'bre_image_for_carousel', $upload ); 
  55. } elseif ( isset( $_REQUEST['bre_image_for_carousel-remove'] ) ) { 
  56. $upload = get_post_meta( $post_id, 'bre_image_for_carousel', true ); 
  57. if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); 
  58. delete_post_meta( $post_id, 'bre_image_for_carousel' ); 
  59.  
  60. static function delete_post( $post_id ) { 
  61. if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; 
  62. delete_post_meta( $post_id, 'bre_add_to_home_carousel' ); 
  63. delete_post_meta( $post_id, 'bre_image_for_carousel' );