true ) ); foreach( $post_types as $post_type ) add_meta_box( 'bre_carousel', __( 'Carousel', 'bre-bootstrap-ecommerce' ), array( __CLASS__, 'bre_carousel_meta_box' ), $post_type, 'side', 'high' ); } static function bre_carousel_meta_box( $post ) { $bre_add_to_home_carousel = bre_is_added_to_home_carousel( $post->ID ); $bre_image_for_carousel = bre_get_image_for_carousel( $post->ID ); ?>
/>
0 ) { $upload = get_post_meta( $post_id, 'bre_image_for_carousel', true ); if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); $upload = wp_handle_upload( $_FILES['bre_image_for_carousel'], array( 'test_form' => false ) ); if ( isset( $upload['error'] ) && '0' != $upload['error'] ) { wp_die( __( 'There was an error uploading the file.', 'bre-bootstrap-ecommerce' ) ); } else { update_post_meta( $post_id, 'bre_image_for_carousel', $upload ); } } elseif ( isset( $_REQUEST['bre_image_for_carousel-remove'] ) ) { $upload = get_post_meta( $post_id, 'bre_image_for_carousel', true ); if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); delete_post_meta( $post_id, 'bre_image_for_carousel' ); } } static function delete_post( $post_id ) { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; delete_post_meta( $post_id, 'bre_add_to_home_carousel' ); delete_post_meta( $post_id, 'bre_image_for_carousel' ); } } BREBoostrapCarouselMetabox::init(); function bre_is_added_to_home_carousel( $post_id ) { $bre_add_to_home_carousel = get_post_meta( $post_id, 'bre_add_to_home_carousel', true ); if ( $bre_add_to_home_carousel == '' ) $bre_add_to_home_carousel = false; return $bre_add_to_home_carousel; } function bre_get_image_for_carousel( $post_id ) { $bre_image_for_carousel = get_post_meta( $post_id, 'bre_image_for_carousel', true ); if ( $bre_image_for_carousel == '' ) $bre_image_for_carousel = false; return $bre_image_for_carousel; }