( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) , 'items' => $items_sort , 'resource_id' => absint( $resource_id ) ) ); } return $calendar_legend_html; } function wpbc_get_calendar_legend__content_html( $params ) { $defaults = array( 'is_vertical' => ( 'On' != get_bk_option( 'booking_legend_is_vertical' ) ) ? false : true , 'text_for_day_cell' => ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) , 'items' => array( 'available' , 'approved' , 'pending' , 'partially' ) , 'unavailable_day_cell_tag' => 'span' , 'resource_id' => 0 , 'titles' => array() ); $params = wp_parse_args( $params, $defaults ); $legend_arr = array(); // Available. if ( 1 ) { $key = 'available'; $day_cell_tag = 'a'; $legend_arr[ $key ] = '
| ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= '';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '' . $day_cell_tag . '>';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' |
| ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= '';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '' . $day_cell_tag . '>';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' |
| ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= '';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' <' . $day_cell_tag . '>' . esc_html( $params['text_for_day_cell'] ) . '' . $day_cell_tag . '>';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' ';
$legend_arr[ $key ] .= ' |
| '; } else { $my_partially .= ' | ';
}
$my_partially .= ' ';
$my_partially .= ' ';
$my_partially .= '';
$my_partially .= ' ';
$my_partially .= ' ';
$my_partially .= ' ';
$my_partially .= ' ';
$my_partially .= ' ';
$my_partially .= 'ยท |
| ';
$my_unavailable .= ' ';
$my_unavailable .= ' ';
$my_unavailable .= '';
$my_unavailable .= ' ';
$my_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '' . $params['unavailable_day_cell_tag'] . '>';
$my_unavailable .= ' ';
$my_unavailable .= ' ';
$my_unavailable .= ' |
| ';
$my_resource_unavailable .= ' ';
$my_resource_unavailable .= ' ';
$my_resource_unavailable .= '';
$my_resource_unavailable .= ' ';
$my_resource_unavailable .= ' <' . $params['unavailable_day_cell_tag'] . '>' . esc_html( $params['text_for_day_cell'] ) . '' . $params['unavailable_day_cell_tag'] . '>';
$my_resource_unavailable .= ' ';
$my_resource_unavailable .= ' ';
$my_resource_unavailable .= ' |
Dates: [selected_short_dates_hint]([days_number_hint]...' * @param int $resource_id - ID of booking resource Example: '4' * @param string $my_booking_form - name of booking form (possible usage of custom booking form) Example: 'standard' * * @return array|string|string[] * * Example of shortcode parameters: * [legend_items items="available,unavailable,pending,approved,partially" text_for_day_cell="31"] * [legend_items is_vertical="1"] * [legend_items] * [legend_items items="resource_unavailable,available,unavailable,pending,approved,partially" text_for_day_cell="31" titles="resource_unavailable={Resource unavailable days} unavailable={Season unavailable}"] * * PHP code example with escaping single and double quotes: * echo wpbc_replace_shortcodes_in_booking_form__legend_items( '[legend_items' . ' items="unavailable,available,pending,approved,partially"' . ' titles="' .' unavailable={' . htmlspecialchars( __( "Unavailable day's", 'booking' ), ENT_QUOTES ) . '}' .' pending={' . htmlspecialchars( __( "Pending", 'booking' ), ENT_QUOTES ) . '}' .'"' . ' text_for_day_cell="' . gmdate( 'd' ) . '"' . ' unavailable_day_cell_tag="a"' .']' ); */ function wpbc_replace_shortcodes_in_booking_form__legend_items( $return_form, $resource_id = 1, $my_booking_form = '' ) { // $legend__content_html = wpbc_get_calendar_legend(); //$return_form = str_replace('[legend_items]', $legend__content_html, $return_form); $pos = 0; while ( false !== strpos( $return_form, '[legend_items ' ) ) { $shortcode_params = wpbc_get_params_of_shortcode_in_string( 'legend_items', $return_form , $pos ); if ( ( isset( $shortcode_params['text_for_day_cell'] ) ) && ( empty( $shortcode_params['text_for_day_cell'] ) ) ) { $shortcode_params['text_for_day_cell'] = gmdate( 'd' ); } $shortcode_titles_params = array(); if ( ! empty( $shortcode_params['titles'] ) ){ $shortcode_titles_params = wpbc_get_params_of_shortcode_in_string( 'titles', '[titles ' . $shortcode_params['titles'] . ']' , 0 , '%\s*([^=]*)=[{]([^}]*)[}]\s*%' ); foreach ( $shortcode_titles_params as $title_name => $title_val ) { $shortcode_titles_params[ $title_name ] = htmlspecialchars_decode( $title_val ); } } $calendar_legend_html = wpbc_get_calendar_legend__content_html( array( 'is_vertical' => ( ! empty( $shortcode_params['is_vertical'] ) ) ? true : false , 'text_for_day_cell' => ( ! empty( $shortcode_params['text_for_day_cell'] ) ) ? $shortcode_params['text_for_day_cell'] : ( ( 'On' != get_bk_option( 'booking_legend_is_show_numbers' ) ) ? ' ' : gmdate( 'd' ) ) , 'items' => ( ! empty( $shortcode_params['items'] ) ) ? explode( ',',$shortcode_params['items'] ) : array( 'available' , 'approved' , 'pending' , 'partially' ) , 'unavailable_day_cell_tag' => ( ! empty( $shortcode_params['unavailable_day_cell_tag'] ) ) ? $shortcode_params['unavailable_day_cell_tag'] : 'span' , 'resource_id' => absint( $resource_id ) , 'titles' => $shortcode_titles_params ) ); $return_form = substr( $return_form, 0, ( $shortcode_params['start'] - 1 ) ) . $calendar_legend_html . substr( $return_form, ( $shortcode_params['end'] + 1 ) ); $pos = $shortcode_params['end']; } return $return_form; } add_filter( 'wpbc_replace_shortcodes_in_booking_form', 'wpbc_replace_shortcodes_in_booking_form__legend_items', 10, 3 );