true ) ); foreach( $post_types as $post_type ) add_meta_box( 'tcp_bs_carousel', __( 'Carousel', 'tcp' ), array( __CLASS__, 'tcp_bs_carousel_meta_box' ), $post_type, 'side', 'high' ); } static function tcp_bs_carousel_meta_box( $post ) { $tcp_add_to_home_carousel = tcp_is_added_to_home_carousel( $post->ID ); $tcp_image_for_carousel = tcp_get_image_for_carousel( $post->ID ); ?>
/>
0 ) { $upload = get_post_meta( $post_id, 'tcp_image_for_carousel', true ); if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); $upload = wp_handle_upload( $_FILES['tcp_image_for_carousel'], array( 'test_form' => false ) ); if ( isset( $upload['error'] ) && '0' != $upload['error'] ) { wp_die( __( 'There was an error uploading the file.', 'tcp' ) ); } else { update_post_meta( $post_id, 'tcp_image_for_carousel', $upload ); } } elseif ( isset( $_REQUEST['tcp_image_for_carousel-remove'] ) ) { $upload = get_post_meta( $post_id, 'tcp_image_for_carousel', true ); if ( isset( $upload['file'] ) ) unlink( $upload['file'] ); delete_post_meta( $post_id, 'tcp_image_for_carousel' ); } } static function delete_post( $post_id ) { global $post; if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; delete_post_meta( $post_id, 'tcp_add_to_home_carousel' ); delete_post_meta( $post_id, 'tcp_image_for_carousel' ); } } TCPBSCarouselMetabox::init(); function tcp_is_added_to_home_carousel( $post_id ) { $tcp_add_to_home_carousel = get_post_meta( $post_id, 'tcp_add_to_home_carousel', true ); if ( $tcp_add_to_home_carousel == '' ) $tcp_add_to_home_carousel = false; return $tcp_add_to_home_carousel; } function tcp_get_image_for_carousel( $post_id ) { $tcp_image_for_carousel = get_post_meta( $post_id, 'tcp_image_for_carousel', true ); if ( $tcp_image_for_carousel == '' ) $tcp_image_for_carousel = false; return $tcp_image_for_carousel; }