true ) );
foreach( $post_types as $post_type ) {
add_meta_box( 'bre_carousel', __( 'Carousel', 'boot-ecommerce' ), array( __CLASS__, 'bre_carousel_meta_box' ), $post_type, 'normal', '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 );
$bre_carousel_title = bre_get_carousel_title( $post->ID );
$bre_carousel_link = bre_get_carousel_link( $post->ID );
$bre_carousel_external_link = bre_get_carousel_external_link( $post->ID );
$bre_carousel_slogan = bre_get_carousel_slogan( $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.', 'boot-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' );
}
update_post_meta( $post_id, 'bre_carousel_title', trim( $_POST['bre_carousel_title'] ) );
update_post_meta( $post_id, 'bre_carousel_link', trim( $_POST['bre_carousel_link'] ) );
update_post_meta( $post_id, 'bre_carousel_external_link', isset( $_POST['bre_carousel_external_link'] ) );
update_post_meta( $post_id, 'bre_carousel_slogan', trim( $_POST['bre_carousel_slogan'] ) );
}
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' );
delete_post_meta( $post_id, 'bre_carousel_title' );
delete_post_meta( $post_id, 'bre_carousel_link' );
delete_post_meta( $post_id, 'bre_carousel_external_link' );
delete_post_meta( $post_id, 'bre_carousel_slogan' );
}
}
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;
}
function bre_get_carousel_title( $post_id ) {
return get_post_meta( $post_id, 'bre_carousel_title', true );
}
function bre_get_carousel_link( $post_id ) {
return get_post_meta( $post_id, 'bre_carousel_link', true );
}
function bre_get_carousel_external_link( $post_id ) {
return (bool)get_post_meta( $post_id, 'bre_carousel_external_link', true );
}
function bre_get_carousel_slogan( $post_id ) {
return get_post_meta( $post_id, 'bre_carousel_slogan', true );
}