*/ class TICA_Events_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; $type = TICA_Events::POST_TYPE; $this->when_box_id = "{$type}_form_when"; $this->from_date_id = "{$type}_from_date"; $this->to_date_id = "{$type}_to_date"; $this->from_time_id = "{$type}_from_time"; $this->to_time_id = "{$type}_to_time"; $this->when_fields = [ $this->from_date_id, $this->to_date_id, $this->from_time_id, $this->to_time_id, ]; $this->where_box_id = "{$type}_form_where"; $this->location_name_id = "{$type}_location_name"; $this->location_address_id = "{$type}_location_address"; $this->location_city_id = "{$type}_location_city"; $this->location_state_id = "{$type}_location_state"; $this->location_zip_id = "{$type}_location_zip"; $this->location_country_id = "{$type}_location_country"; $this->where_fields = [ $this->location_name_id, $this->location_address_id, $this->location_city_id, $this->location_state_id, $this->location_zip_id, $this->location_country_id, ]; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/tica-events-admin.css', $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * @param $hook * * @since 1.0.0 */ public function enqueue_scripts( $hook ) { global $post; // add scripts to add/edit form if ( TICA_Events::POST_TYPE == $post->post_type && in_array( $hook, [ 'post-new.php', 'post.php' ] ) ) { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/tica-events-edit.js', ['jquery'], $this->version, false ); $options = [ 'from_date_id' => $this->from_date_id, 'to_date_id' => $this->to_date_id, 'from_time_id' => $this->from_time_id, 'to_time_id' => $this->to_time_id, ]; $options = json_encode($options); wp_add_inline_script($this->plugin_name, "jQuery(document).ready(function() { jQuery('#{$this->when_box_id}').initWhenBox({$options}); });"); } } public function register_events_cpt() { // register events post type $labels = array( 'name' => _x( 'Events', 'Post Type General Name', 'e' ), 'singular_name' => _x( 'Event', 'Post Type Singular Name', 'tica-events' ), 'menu_name' => __( 'TICA Events', 'tica-events' ), 'name_admin_bar' => __( 'Event', 'tica-events' ), 'archives' => __( 'Events', 'tica-events' ), 'attributes' => __( 'Event Attributes', 'tica-events' ), 'parent_item_colon' => __( 'Parent Item:', 'tica-events' ), 'all_items' => __( 'All Events', 'tica-events' ), 'add_new_item' => __( 'Add New Event', 'tica-events' ), 'add_new' => __( 'Add New', 'tica-events' ), 'new_item' => __( 'New Event', 'tica-events' ), 'edit_item' => __( 'Edit Event', 'tica-events' ), 'update_item' => __( 'Update Event', 'tica-events' ), 'view_item' => __( 'View Event', 'tica-events' ), 'view_items' => __( 'View Events', 'tica-events' ), 'search_items' => __( 'Search Events', 'tica-events' ), 'not_found' => __( 'Not found', 'tica-events' ), 'not_found_in_trash' => __( 'Not found in Trash', 'tica-events' ), 'featured_image' => __( 'Featured Image', 'tica-events' ), 'set_featured_image' => __( 'Set featured image', 'tica-events' ), 'remove_featured_image' => __( 'Remove featured image', 'tica-events' ), 'use_featured_image' => __( 'Use as featured image', 'tica-events' ), 'insert_into_item' => __( /** @lang text */ 'Insert into event', 'tica-events' ), 'uploaded_to_this_item' => __( 'Uploaded to this events item', 'tica-events' ), 'items_list' => __( 'Events list', 'tica-events' ), 'items_list_navigation' => __( 'Events list navigation', 'tica-events' ), 'filter_items_list' => __( 'Filter Events list', 'tica-events' ), ); $args = array( 'label' => __( 'Events', 'tica-events' ), 'description' => __( 'Events Description', 'tica-events' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 30, 'menu_icon' => plugin_dir_url( __FILE__ ) . 'img/icon.png', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => true, 'capability_type' => 'post', 'rewrite' => [ 'slug' => 'event' ] ); register_post_type( TICA_Events::POST_TYPE, $args ); } public function add_meta_boxes() { add_meta_box( TICA_Events::POST_TYPE . '_meta_when', __( 'When (EDT)', 'tica-events' ), [ $this, 'meta_when_callback' ], null, 'side', 'high' ); add_meta_box( TICA_Events::POST_TYPE . '_meta_where', __( 'Location', 'tica-events' ), [ $this, 'meta_where_callback' ] ); } public function meta_when_callback( $post ) { if ( $post->post_type != TICA_Events::POST_TYPE ) { return; } $meta = get_post_meta( $post->ID ); $from_date = ( ! empty( $meta[$this->from_date_id][0] ) ) ? $meta[$this->from_date_id][0] : ''; $to_date = ( ! empty( $meta[$this->to_date_id][0] ) ) ? $meta[$this->to_date_id][0] : ''; $from_time = ( ! empty( $meta[$this->from_time_id][0] ) ) ? $meta[$this->from_time_id][0] : ''; $to_time = ( ! empty( $meta[$this->to_time_id][0] ) ) ? $meta[$this->to_time_id][0] : ''; ?>