__( 'Announcements', 'apollo-bar' ), 'singular_name' => __( 'Announcement', 'apollo-bar' ), 'add_new' => __( 'Add New', 'apollo-bar' ), 'add_new_item' => __( 'Add New Announcement', 'apollo-bar' ), 'all_items' => __( 'All items', 'apollo-bar' ), 'edit_item' => __( 'Edit Announcement', 'apollo-bar' ), 'new_item' => __( 'New Announcement', 'apollo-bar' ), 'view_item' => __( 'View Announcement', 'apollo-bar' ), 'search_items' => __( 'Search Announcements', 'apollo-bar' ), 'not_found' => __( 'No Announcements found', 'apollo-bar' ), 'not_found_in_trash' => __( 'No Announcements found in Trash', 'apollo-bar' ), 'parent_item_colon' => '', 'menu_name' => __( 'Apollo Bar', 'apollo-bar' ) ); $args = array( 'labels' => $labels, 'singular_label' => __( 'Announcement', 'announcements', 'apollo-bar' ), 'public' => true, 'capability_type' => 'post', 'rewrite' => false, 'supports' => array( 'title', 'editor' ), ); register_post_type( 'announcements', $args ); } add_action( 'init', 'apb_register_announcements' ); // Add Columns to Announcements Custom Post Type // Add Columns add_filter( 'manage_edit-announcements_columns', 'apb_edit_announcements_columns' ) ; function apb_edit_announcements_columns( $columns ) { $columns = array( 'cb' => '', 'title' => __( 'Title', 'apollo-bar' ), 'apb_start_date' => __( 'Start Date', 'apollo-bar' ), 'apb_end_date' => __( 'End Date', 'apollo-bar' ), 'date' => __( 'Date', 'apollo-bar' ) ); return $columns; } // Add Columns Content add_action( 'manage_announcements_posts_custom_column', 'apb_manage_announcements_columns', 10, 2 ); function apb_manage_announcements_columns( $column, $post_id ) { global $post; switch( $column ) { /* If displaying the 'start date' column. */ case 'apb_start_date' : /* Get the post meta. */ $apb_start_date = get_post_meta( $post_id, 'apb_start_date', true ); /* If no start date is found, output a default message. */ if ( empty( $apb_start_date ) ) echo '' . __( 'Not selected!', 'apollo-bar' ) . ''; /* If there is a start date, displaying the 'start date' */ else echo $apb_start_date; break; /* If displaying the 'end date' column. */ case 'apb_end_date' : /* Get the post meta. */ $apb_end_date = get_post_meta( $post_id, 'apb_end_date', true ); /* If no end date is found, output a default message. */ if ( empty( $apb_end_date ) ) echo '' . __( 'Not selected!', 'apollo-bar' ) . ''; /* If there is a end date, displaying the 'end date' */ else echo $apb_end_date; break; /* Just break out of the switch statement for everything else. */ default : break; } } // Add Menu Icon function apollo_bar_icons() { echo ''; } add_action( 'admin_head', 'apollo_bar_icons' ); // Add Custom Screen Icon function apollo_bar_screen_icon() { $post_type = get_current_screen()->post_type; if ( 'announcements' == $post_type ) { echo ''; } } add_action( 'admin_head', 'apollo_bar_screen_icon' ); // Creating Custom Meta Boxes // Adding Meta Box function apb_add_metabox() { add_meta_box( 'apb_metabox_id', __( 'Scheduling', 'apollo-bar' ), 'apb_metabox', 'announcements', 'side', 'high' ); } add_action( 'add_meta_boxes', 'apb_add_metabox' ); // Adding the Fields function apb_metabox( $post ) { $values = get_post_custom( $post->ID ); $start_date = isset( $values['apb_start_date'] ) ? esc_attr( $values['apb_start_date'][0] ) : ''; $end_date = isset( $values['apb_end_date'] ) ? esc_attr( $values['apb_end_date'][0] ) : ''; wp_nonce_field( 'apb_metabox_nonce', 'metabox_nonce' ); ?>

post_type != 'announcements' ) ) return; wp_enqueue_style( 'jquery-ui-fresh', plugins_url( 'apollo-bar/css/jquery-ui-fresh.css' , dirname(__FILE__) ) ); wp_enqueue_script( 'apb-date-picker-js', plugins_url( 'apollo-bar/js/date-picker.js' , dirname(__FILE__) ) , array( 'jquery', 'jquery-ui-datepicker' ), APB_VERSION, true ); } add_action( 'admin_enqueue_scripts', 'apb_backend_post_scripts' ); // FrontEnd function apb_frontend_scripts() { wp_enqueue_style( 'apb-core-style', plugins_url( 'apollo-bar/css/apollo-bar.css' , dirname(__FILE__) ), APB_VERSION ); wp_enqueue_script( 'apb-core-js', plugins_url( 'apollo-bar/js/apollo-bar-core.js' , dirname(__FILE__) ) , array( 'jquery' ), APB_VERSION, true ); wp_enqueue_script( 'cookies', plugins_url( 'apollo-bar/js/jquery.cookie.js' , dirname(__FILE__) ) , array( 'jquery' ), APB_VERSION ); } add_action( 'wp_enqueue_scripts', 'apb_frontend_scripts' ); // Add backgrund color style to head section function apb_add_color_to_head() { global $apb_options; $bgcolor = $apb_options['apollo_bar_color']; $textcolor = $apb_options['apollo_bar_textcolor']; if( $apb_options['apollo_bar_noisy'] == true ) { echo '',"\n"; } else { echo '',"\n"; } } add_action( 'wp_head', 'apb_add_color_to_head' ); // Displaying Apollo Bar function apb_filter_where( $where = '' ) { // ...where dates are blank $where .= " OR (mt1.meta_key = 'apb_start_date' AND CAST(mt1.meta_value AS CHAR) = '') OR (mt2.meta_key = 'apb_end_date' AND CAST(mt2.meta_value AS CHAR) = '')"; return $where; } function apb_display_announcement() { global $wpdb, $apb_options; $today = date( 'Y-m-d' ); $args = array( 'post_type' => 'announcements', 'posts_per_page' => 0, 'post_status' => 'publish', 'meta_key' => 'apb_end_date', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'apb_start_date', 'value' => $today, 'compare' => '<=', ), array( 'key' => 'apb_end_date', 'value' => $today, 'compare' => '>=', ) ) ); // Add a filter to do complex 'where' clauses... add_filter( 'posts_where', 'apb_filter_where' ); $query = new WP_Query( $args ); // Take the filter away again so this doesn't apply to all queries. remove_filter( 'posts_where', 'apb_filter_where' ); $announcements = $query->posts; if ( $announcements && $apb_options['apollo_bar_display'] == true ) : ?>
Download Apollo Bar
' . do_shortcode( wpautop( ( $announcement->post_content ) ) ) . '
'; } ?>