S F Y'; const ANW_TIME_FORMAT = 'l, H:i'; $anw_types = [ ANW_TYPE_USER => __( 'User', ANW_TEXT_DOMAIN ), ANW_TYPE_FIDUCIARY => __( 'Fiduciary', ANW_TEXT_DOMAIN ), ]; require_once 'functions.php'; // --------------------------------------------------------------------------------------------------------------------- // INIT JS/CSS (BEGIN) // --------------------------------------------------------------------------------------------------------------------- function anw_admin_enqueue_scripts() { global $pagenow, $typenow; if ( in_array( $pagenow, [ 'post-new.php', 'post.php' ] ) && ANW_POST_TYPE == $typenow ) { $suffix = ''; //$suffix = SCRIPT_DEBUG ? '' : '.min'; $lang = get_curr_lang(); if ( 'en' != $lang ) { wp_enqueue_script( "anw_datepicker_{$lang}", plugins_url( "js/jquery-ui/datepicker-{$lang}{$suffix}.js", __FILE__ ), [ 'jquery-ui-datepicker' ] ); } wp_enqueue_style( 'anw_jquery_ui', plugins_url( "css/jquery-ui{$suffix}.css", __FILE__ ) ); wp_enqueue_style( 'anw_admin', plugins_url( "css/admin{$suffix}.css", __FILE__ ) ); wp_enqueue_script( 'anw_edit_form', plugins_url( "js/edit-form{$suffix}.js", __FILE__ ), [ 'jquery-ui-datepicker' ] ); $vars = [ 'lang' => $lang, 'plugins_url' => plugins_url( '/', __FILE__ ), ]; wp_localize_script( 'anw_edit_form', 'anw_edit_form', $vars ); } } add_action( 'admin_enqueue_scripts', 'anw_admin_enqueue_scripts' ); function anw_enqueue_scripts() { $suffix = ''; //$suffix = SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'anw_admin', plugins_url( "css/user{$suffix}.css", __FILE__ ) ); wp_enqueue_script( 'anw_list', plugins_url( "js/list{$suffix}.js", __FILE__ ) ); } add_action( 'wp_enqueue_scripts', 'anw_enqueue_scripts' ); // --------------------------------------------------------------------------------------------------------------------- // INIT JS/CSS (END) // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- // REGISTER POST TYPE (BEGIN) // --------------------------------------------------------------------------------------------------------------------- function anw_register_post_type() { $labels = [ 'name' => __( 'Webinars', ANW_TEXT_DOMAIN ), 'singular_name' => __( 'Webinar', ANW_TEXT_DOMAIN ), 'add_new' => __( 'Add New', ANW_TEXT_DOMAIN ), 'add_new_item' => __( 'Add New Webinar', ANW_TEXT_DOMAIN ), 'edit_item' => __( 'Edit Webinar', ANW_TEXT_DOMAIN ), 'new_item' => __( 'New Webinar', ANW_TEXT_DOMAIN ), 'view_item' => __( 'View Webinar', ANW_TEXT_DOMAIN ), 'view_items' => __( 'View Webinars', ANW_TEXT_DOMAIN ), 'search_items' => __( 'Search Webinars', ANW_TEXT_DOMAIN ), 'not_found' => __( 'No Webinars found.', ANW_TEXT_DOMAIN ), 'not_found_in_trash' => __( 'No Webinars found in Trash.', ANW_TEXT_DOMAIN ), 'all_items' => __( 'All Webinars', ANW_TEXT_DOMAIN ), 'archives' => __( 'Webinar Archives', ANW_TEXT_DOMAIN ), 'attributes' => __( 'Webinar Attributes', ANW_TEXT_DOMAIN ), 'insert_into_item' => __( /** @lang text */ 'Insert into Webinar', ANW_TEXT_DOMAIN ), 'uploaded_to_this_item' => __( 'Uploaded to this webinar', ANW_TEXT_DOMAIN ), 'featured_image' => __( 'Featured Image', ANW_TEXT_DOMAIN ), 'set_featured_image' => __( 'Set featured image', ANW_TEXT_DOMAIN ), 'remove_featured_image' => __( 'Remove featured image', ANW_TEXT_DOMAIN ), 'use_featured_image' => __( 'Use as featured image', ANW_TEXT_DOMAIN ), 'filter_items_list' => __( 'Filter webinars list', ANW_TEXT_DOMAIN ), 'items_list_navigation' => __( 'Webinars list navigation', ANW_TEXT_DOMAIN ), 'items_list' => __( 'Webinars list', ANW_TEXT_DOMAIN ), ]; register_post_type( ANW_POST_TYPE, [ 'labels' => $labels, 'public' => false, 'hierarchical' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-video-alt2', 'capability_type' => 'post', 'supports' => [ 'title', 'editor', 'revisions' ], ] ); } add_action( 'init', 'anw_register_post_type' ); function anw_set_tz() { date_default_timezone_set( get_option( 'timezone_string' ) ); } add_action( 'init', 'anw_set_tz' ); // --------------------------------------------------------------------------------------------------------------------- // REGISTER POST TYPE (END) // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- // INTERNATIONALIZATION (BEGIN) // --------------------------------------------------------------------------------------------------------------------- function anw_textdomain() { $plugin_rel_path = basename( dirname( __FILE__ ) ) . '/languages/'; load_plugin_textdomain( ANW_TEXT_DOMAIN, false, $plugin_rel_path ); } add_action( 'plugins_loaded', 'anw_textdomain' ); // --------------------------------------------------------------------------------------------------------------------- // INTERNATIONALIZATION (END) // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- // WEBINAR EDIT FORM (BEGIN) // --------------------------------------------------------------------------------------------------------------------- function anw_form_additional_fields( $post ) { global $anw_types; if ( ANW_POST_TYPE == $post->post_type ) { $value = get_post_meta( $post->ID, get_related_name( 'webinar_date' ), true ); if ( ! $value ) { $value = mktime(); } $date = date_i18n( 'd/m/Y', $value ); //date_i18n( 'j F Y', $value ); $time_h = date( 'H', $value ); $time_m = date( 'i', $value ); $url = get_post_meta( $post->ID, get_related_name( 'webinar_url' ), true ); $type = get_post_meta( $post->ID, get_related_name( 'webinar_type' ), true ); ?>

Example:
ID; wp_nonce_field($action, $name); } } add_action( 'edit_form_after_title', 'anw_form_additional_fields' ); function anw_render_attribs_metabox( $post ) { $id = 'webinar-attr-free'; $name = 'webinar_attr[free]'; $value = get_post_meta( $post->ID, get_related_name( 'webinar_attr_free' ), true ); ?> $value ) { $field = 'webinar_attr_' . $key; update_post_meta( $post_ID, get_related_name( $field ), $value ); } } } } add_action( 'save_post_' . ANW_POST_TYPE, 'anw_save_post_meta' ); // --------------------------------------------------------------------------------------------------------------------- // WEBINAR EDIT FORM (END) // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- // ADMIN WEBINARS LIST (BEGIN) // --------------------------------------------------------------------------------------------------------------------- function anw_webinars_columns( $columns ) { if ( array_key_exists( 'date', $columns ) ) { $columns['date'] = __( 'Created', ANW_TEXT_DOMAIN ); } $last_value = end( $columns ); $last_key = key( $columns ); unset( $columns[$last_key] ); $columns['webinar_type'] = __( 'Type', ANW_POST_TYPE ); $columns['webinar_date'] = __( 'Date', ANW_POST_TYPE ); $columns[$last_key] = $last_value; return $columns; } add_filter( 'manage_' . ANW_POST_TYPE . '_posts_columns', 'anw_webinars_columns' ); // add custom column function anw_webinars_sortable_columns( $columns ) { $columns['webinar_date'] = 'webinar_date'; $columns['webinar_type'] = 'webinar_type'; return $columns; } add_filter( 'manage_edit-' . ANW_POST_TYPE . '_sortable_columns', 'anw_webinars_sortable_columns' ); // mark custom column as sorted function anw_webinars_columns_values( $column ) { global $post, $anw_types; switch ( $column ) { case 'webinar_date': $date = get_post_meta( $post->ID, get_related_name( 'webinar_date' ), true); if ( $date ) { echo esc_html( date( "d/m/Y H:i", $date ) ); } else { echo esc_html( '-' ); } break; case 'webinar_type': $type = get_post_meta( $post->ID, get_related_name( 'webinar_type' ), true); if ( array_key_exists( $type, $anw_types ) ) { echo esc_html( $anw_types[$type] ); } else { echo esc_html( '-' ); } break; } } add_action( 'manage_' . ANW_POST_TYPE . '_posts_custom_column' , 'anw_webinars_columns_values' ); // output custom column value function anw_orderby( WP_Query $query ) { if( ! $query->is_main_query() || ANW_POST_TYPE != $query->get( 'post_type' ) ) { return; // Nothing to do } $orderby = strtolower( $query->get( 'orderby') ); if ( '' == $orderby ) { $orderby = 'webinar_date'; // change default order } switch ( $orderby ) { case 'webinar_date': $query->set( 'meta_key', get_related_name( 'webinar_date' ) ); $query->set( 'orderby', 'meta_value_num' ); break; case 'webinar_type': $query->set( 'meta_key', get_related_name( 'webinar_type' ) ); $query->set( 'orderby', 'meta_value_num' ); break; } } add_action( 'pre_get_posts', 'anw_orderby' ); // --------------------------------------------------------------------------------------------------------------------- // ADMIN WEBINARS LIST (END) // --------------------------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------------------------- // SHORTCODE (BEGIN) // --------------------------------------------------------------------------------------------------------------------- /** * @param array $clauses * @param WP_Query $query * * @return mixed */ function anw_meta_query( $clauses, $query ) { global $wpdb; if ( ANW_POST_TYPE == @$query->query['post_type'] && ! is_admin() ) { $current_timestamp = time(); $clauses['where'] .= "\nAND ({$wpdb->postmeta}.meta_value + 3600 >= {$current_timestamp}) "; } return $clauses; } add_filter( 'posts_clauses', 'anw_meta_query', 10, 2 ); function anw_get_query( $type ) { global $anw_types; if ( ! array_key_exists( $type, $anw_types ) ) { return false; } $query_params = [ 'post_type' => ANW_POST_TYPE, 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => get_related_name( 'webinar_date' ), 'meta_query' => [ [ 'key' => get_related_name( 'webinar_type' ), 'value' => $type, ] ], ]; return new WP_Query($query_params); } function anw_shortcode() { global $anw_types; $anw_query = []; foreach ( array_keys( $anw_types ) as $type ) { $anw_query[$type] = anw_get_query( $type ); } ob_start(); require 'tpl/shortcode.php'; return ob_get_clean(); } add_shortcode( ANW_SHORTCODE, 'anw_shortcode' ); // --------------------------------------------------------------------------------------------------------------------- // SHORTCODE (END) // ---------------------------------------------------------------------------------------------------------------------