*/ class TICA_Events_Public { /** * 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 the plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/tica-events-public.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/tica-events-public.js', array( 'jquery' ), $this->version, false ); } public function the_content( $content ) { global $post; if ( is_single() && TICA_Events::POST_TYPE == $post->post_type && $page = $this->get_page() ) { $back_link = ''; $events_back_url = get_permalink( $page ); $referrer = wp_get_referer(); if ( 0 === strpos( $referrer, $events_back_url ) ) { $events_back_url = $referrer; } if ( $events_back_url ) { $back_link = '
'; } $content = $back_link . $content; } return $content; } protected function get_page() { $query = new WP_Query( [ 'post_type' => ['page', 'post'], 'meta_key' => '_wp_page_template', 'meta_value' => 'template-events.php', ] ); return ( $query->have_posts() ) ? reset( $query->posts ) : false; } public function get_the_time( $time, $format, $post ) { if ( TICA_Events::POST_TYPE == $post->post_type ) { $date = get_post_meta( $post->ID, TICA_Events::POST_TYPE . '_from_date', true ); if ( $date ) { $time = mysql2date( $format, $date ); } } return $time; } protected function getEventLocation( $post ) { $type = TICA_Events::POST_TYPE; if ( $type != $post->post_type ) { return ''; } $where = ''; $meta = get_post_meta( $post->ID ); $fields = [ [ 'location_name', 'location_city' ], [ 'location_address', 'location_state', 'location_zip', 'location_country' ] ]; foreach ( $fields as $_fields ) { foreach ( $_fields as $field ) { $value = ( ! empty( $meta["{$type}_{$field}"][0] ) ) ? $meta["{$type}_{$field}"][0] : ''; if ( $value ) { $where .= esc_html( "{$value}, " ); } } $where = trim($where, ", \t\n\r\0\x0B") . '' . nl2br( esc_html( $when ) ) . '
'; } $where = $this->getEventLocation( $post ); if ( $where ) { echo '' . nl2br( $where ) . '
'; } } }