'GET', 'callback' => array( __CLASS__, 'calendar' ), 'permission_callback' => '__return_true', // Public: shows only published events, same as the page itself. 'args' => array( 'atts' => array( 'type' => 'string', 'default' => '{}', ), 'base' => array( 'type' => 'string', 'format' => 'uri', ), 'evwr_view' => array( 'type' => 'string' ), 'evwr_month' => array( 'type' => 'string' ), 'evwr_week' => array( 'type' => 'string' ), 'evwr_day' => array( 'type' => 'string' ), 'evwr_cat' => array( 'type' => 'string' ), 'evwr_page' => array( 'type' => 'integer' ), ), ) ); } /** * Render the calendar for the given state. * * @param \WP_REST_Request $request Request. * @return \WP_REST_Response */ public static function calendar( $request ) { $atts = json_decode( (string) $request['atts'], true ); $atts = is_array( $atts ) ? $atts : array(); $allowed = array( 'view', 'categories', 'show_filters', 'show_subscribe', 'per_page', 'show_images' ); $atts = array_intersect_key( $atts, array_flip( $allowed ) ); $base = (string) $request['base']; if ( $base && wp_validate_redirect( $base, '' ) ) { $atts['base_url'] = $base; } $state = array(); foreach ( Views::STATE_KEYS as $key ) { $state[ $key ] = isset( $request[ $key ] ) ? sanitize_text_field( (string) $request[ $key ] ) : ''; } $html = Views::calendar( $atts, $state ); return new \WP_REST_Response( array( 'html' => $html ) ); } }