array( __CLASS__, 'render_' . str_replace( '-', '_', $name ) ) ) ); } add_shortcode( 'eventwright_calendar', array( __CLASS__, 'shortcode_calendar' ) ); add_shortcode( 'eventwright_list', array( __CLASS__, 'shortcode_list' ) ); add_shortcode( 'eventwright_event_details', array( __CLASS__, 'shortcode_details' ) ); add_shortcode( 'eventwright_rsvp', array( __CLASS__, 'shortcode_rsvp' ) ); } /** * Our block category. * * @param array $cats Categories. * @return array */ public static function category( $cats ) { array_unshift( $cats, array( 'slug' => 'eventwright', 'title' => __( 'Events', 'eventwright' ), ) ); return $cats; } /** * Wrapper attributes when available. * * @param string $extra Extra classes. * @return string */ private static function wrapper( $extra = '' ) { if ( function_exists( 'get_block_wrapper_attributes' ) && \WP_Block_Supports::$block_to_render ) { return get_block_wrapper_attributes( array( 'class' => $extra ) ); } return 'class="' . esc_attr( $extra ) . '"'; } /** * Calendar block. * * @param array $attrs Attributes. * @return string */ public static function render_calendar( $attrs ) { $html = Views::calendar( array( 'view' => isset( $attrs['view'] ) ? $attrs['view'] : Settings::get( 'default_view' ), 'categories' => isset( $attrs['categories'] ) ? $attrs['categories'] : array(), 'show_filters' => isset( $attrs['showFilters'] ) ? $attrs['showFilters'] : true, 'show_subscribe' => isset( $attrs['showSubscribe'] ) ? $attrs['showSubscribe'] : true, 'per_page' => isset( $attrs['perPage'] ) ? $attrs['perPage'] : Settings::get( 'list_per_page' ), 'show_images' => isset( $attrs['showImages'] ) ? $attrs['showImages'] : true, ) ); return '
' . $html . '
'; } /** * Upcoming events block. * * @param array $attrs Attributes. * @return string */ public static function render_upcoming( $attrs ) { $html = Views::upcoming_list( array( 'limit' => isset( $attrs['limit'] ) ? $attrs['limit'] : 5, 'categories' => isset( $attrs['categories'] ) ? $attrs['categories'] : array(), 'show_images' => ! empty( $attrs['showImages'] ), 'show_venue' => isset( $attrs['showVenue'] ) ? $attrs['showVenue'] : true, 'show_all_link' => isset( $attrs['showAllLink'] ) ? $attrs['showAllLink'] : true, 'layout' => isset( $attrs['layout'] ) ? $attrs['layout'] : 'list', ) ); return '
' . $html . '
'; } /** * Event details block (on event pages, or for a chosen event). * * @param array $attrs Attributes. * @return string */ public static function render_event_details( $attrs ) { $id = ! empty( $attrs['eventId'] ) ? (int) $attrs['eventId'] : (int) get_the_ID(); if ( ! $id || get_post_type( $id ) !== Post_Types::EVENT ) { return ''; } return '
' . Frontend::event_details( $id ) . '
'; } /** * RSVP block. * * @param array $attrs Attributes. * @return string */ public static function render_rsvp( $attrs ) { $id = ! empty( $attrs['eventId'] ) ? (int) $attrs['eventId'] : (int) get_the_ID(); if ( ! $id || get_post_type( $id ) !== Post_Types::EVENT ) { return ''; } $html = RSVP::render( $id ); return $html ? '
' . $html . '
' : ''; } /** * [eventwright_calendar view="month" category="music,talks" filters="yes" per_page="10"]. * * @param array|string $atts Attributes. * @return string */ public static function shortcode_calendar( $atts ) { $atts = shortcode_atts( array( 'view' => Settings::get( 'default_view' ), 'category' => '', 'filters' => 'yes', 'subscribe' => 'yes', 'per_page' => Settings::get( 'list_per_page' ), 'images' => 'yes', ), $atts, 'eventwright_calendar' ); return Views::calendar( array( 'view' => $atts['view'], 'categories' => $atts['category'], 'show_filters' => $atts['filters'], 'show_subscribe' => $atts['subscribe'], 'per_page' => $atts['per_page'], 'show_images' => $atts['images'], ) ); } /** * [eventwright_list limit="5" category="music" images="no" venue="yes"]. * * @param array|string $atts Attributes. * @return string */ public static function shortcode_list( $atts ) { $atts = shortcode_atts( array( 'limit' => 5, 'category' => '', 'images' => 'no', 'venue' => 'yes', 'all_link' => 'yes', 'layout' => 'list', ), $atts, 'eventwright_list' ); return Views::upcoming_list( array( 'limit' => $atts['limit'], 'categories' => $atts['category'], 'show_images' => $atts['images'], 'show_venue' => $atts['venue'], 'show_all_link' => $atts['all_link'], 'layout' => $atts['layout'], ) ); } /** * [eventwright_event_details id="123"]. * * @param array|string $atts Attributes. * @return string */ public static function shortcode_details( $atts ) { $atts = shortcode_atts( array( 'id' => 0 ), $atts, 'eventwright_event_details' ); $id = $atts['id'] ? absint( $atts['id'] ) : (int) get_the_ID(); return get_post_type( $id ) === Post_Types::EVENT ? Frontend::event_details( $id ) : ''; } /** * [eventwright_rsvp id="123"]. * * @param array|string $atts Attributes. * @return string */ public static function shortcode_rsvp( $atts ) { $atts = shortcode_atts( array( 'id' => 0 ), $atts, 'eventwright_rsvp' ); $id = $atts['id'] ? absint( $atts['id'] ) : (int) get_the_ID(); return get_post_type( $id ) === Post_Types::EVENT ? RSVP::render( $id ) : ''; } }