Booking Activities Shortcodes

Below, you’ll find a detailed guide on how to add the Booking Activities Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Booking Activities Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Booking Activities Plugin and the shortcodes it provides:

Plugin Icon
Booking Activities

"Booking Activities is a versatile WordPress plugin designed to streamline and manage all your booking needs. With its user-friendly interface, scheduling and organizing events becomes effortless."

★★★★☆ (102) Active Installs: 5000+ Tested with: 6.2.3 PHP Version: 5.3
Included Shortcodes:
  • [bookingactivities_form]
  • [bookingactivities_list]
  • [bookingactivities_login]

Booking Activities [bookingactivities_form] Shortcode

The BookingActivities shortcode is used to display a booking form on your website. It retrieves a specific form based on the ‘form’ attribute value. This shortcode takes two parameters: ‘form’ and ‘id’. ‘Form’ is the form ID, while ‘id’ is a unique identifier for the form instance. The output is a booking form, filtered through ‘bookacti_shortcode_’ . $tag . ‘_output’.

Shortcode: [bookingactivities_form]

Parameters

Here is a list of all possible bookingactivities_form shortcode parameters and attributes:

  • form – Specifies the ID of the booking form to display
  • id – Provides a unique identifier for the form instance

Examples and Usage

Basic example – A simple usage of the booking form shortcode. This will display the booking form with the ID of 1.

[bookingactivities_form form=1 /]

Advanced examples

Displaying a booking form by referencing both ID and title. The form will first try to load by ID, but if not found, it will try to load by title. This example assumes a form with the ID of 2 and the title ‘myform’.

[bookingactivities_form form=2 id='myform' /]

Displaying a booking form by only referencing the title. This example assumes a form with the title ‘myform’. If multiple forms share the same title, the first one found will be displayed.

[bookingactivities_form id='myform' /]

Displaying a booking form by only referencing the ID. This example assumes a form with the ID of 3. If the form with this ID is not found, nothing will be displayed.

[bookingactivities_form form=3 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [bookingactivities_form] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'bookingactivities_form', 'bookacti_shortcode_booking_form' );

Shortcode PHP function:

function bookacti_shortcode_booking_form( $raw_atts = array(), $content = null, $tag = '' ) {
	$default_atts = array(
		'form' => 0,
		'id' => ''
	);
	$atts = shortcode_atts( $default_atts, array_change_key_case( (array) $raw_atts, CASE_LOWER ), $tag );
	$output = '';

	// Retrieve the booking form
	if( ! empty( $atts[ 'form' ] ) ) {
		$form_id = intval( $atts[ 'form' ] );
		$instance_id = sanitize_title_with_dashes( $atts[ 'id' ] );
		$output = bookacti_display_form( $form_id, $instance_id, 'display', false );
	}

	return apply_filters( 'bookacti_shortcode_' . $tag . '_output', $output, $raw_atts, $content );
}

Code file location:

booking-activities/booking-activities/controller/controller-shortcodes.php

Booking Activities [bookingactivities_list] Shortcode

The Booking Activities shortcode is a powerful tool for managing user bookings. It displays a list of user bookings, but if the user isn’t logged in, it shows a login form instead. The shortcode also allows filtering by template and can be customized by third parties. It’s a versatile tool for managing bookings on a WordPress site.

Shortcode: [bookingactivities_list]

Parameters

Here is a list of all possible bookingactivities_list shortcode parameters and attributes:

  • login_form – Specifies a form to show when a user is not logged in.
  • form – Specifies a form to show, replaces login form if both are set.
  • templates – Determines which templates to filter by in the booking list.
  • columns – Defines the columns to be displayed in the booking list.
  • per_page – Sets the number of bookings to display per page.

Examples and Usage

Basic example – A simple usage of the shortcode to display the booking list for the logged-in user.

[bookingactivities_list /]

Advanced examples

Display the booking list with specific columns only. Here, we are showing only the ‘status’ and ‘quantity’ columns.

[bookingactivities_list columns="status,quantity" /]

Limit the number of bookings shown per page. This example shows only 5 bookings per page.

[bookingactivities_list per_page="5" /]

Display a login form if the user is not logged in. The ‘login_form’ attribute is set to the ID of the desired login form.

[bookingactivities_list login_form="2" /]

Filter the booking list by templates. Here, we are showing bookings from template 1 and 3 only.

[bookingactivities_list templates="1,3" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [bookingactivities_list] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'bookingactivities_list', 'bookacti_shortcode_booking_list' );

Shortcode PHP function:

function bookacti_shortcode_booking_list( $raw_atts = array(), $content = null, $tag = '' ) {
	// Normalize attribute keys, lowercase
    $raw_atts = array_change_key_case( (array) $raw_atts, CASE_LOWER );
	
	// If the user is not logged in, and if a login form is defined, show it instead of the booking list
	if( ! is_user_logged_in() && ! empty( $raw_atts[ 'login_form' ] ) ) {
		$raw_atts[ 'form' ] = $raw_atts[ 'login_form' ];
		return bookacti_shortcode_login_form( $raw_atts, $content, $tag );
	}
	
	$booking_list = '';
	
	// Sanitize the attributes
	$atts = bookacti_sanitize_booking_list_shortcode_attributes( $raw_atts );
	
	if( $atts !== false ) {
		$templates = array();
		if( isset( $atts[ 'templates' ] ) ) { 
			$templates = $atts[ 'templates' ];
			unset( $atts[ 'templates' ] );
		}

		// Format booking filters
		$filters = bookacti_format_booking_filters( $atts );

		// Allow to filter by any template
		if( ! empty( $templates ) && is_array( $templates ) ) { $filters[ 'templates' ] = $templates; }

		// Let third party change the filters
		$filters = apply_filters( 'bookacti_user_booking_list_booking_filters', $filters, $atts, $content );

		$booking_list = bookacti_get_user_booking_list( $filters, $atts[ 'columns' ], $atts[ 'per_page' ] );
	}
	
	return apply_filters( 'bookacti_shortcode_' . $tag . '_output', $booking_list, $raw_atts, $content );
}

Code file location:

booking-activities/booking-activities/controller/controller-shortcodes.php

Booking Activities [bookingactivities_login] Shortcode

Booking Activities shortcode is a useful tool that displays a login form for users. It verifies if a user is logged in and presents a form if not. The shortcode attributes include ‘form’, ‘redirect_url’, and ‘id’. The ‘form’ attribute is essential for retrieving the booking form. The ‘redirect_url’ attribute is used to redirect users after logging in. The ‘id’ attribute is used to differentiate between multiple forms. It’s a great way to enhance user experience on your WordPress site.

Shortcode: [bookingactivities_login]

Parameters

Here is a list of all possible bookingactivities_login shortcode parameters and attributes:

  • form – numeric ID of the booking form to be displayed
  • redirect_url – URL to redirect users after successful login
  • id – unique identifier for the login form element

Examples and Usage

Basic example – A simple usage of the shortcode to display a login form with a specific form ID.

[bookingactivities_login form=2 /]

Advanced examples

Displaying a login form with a specific form ID and a custom CSS ID. The CSS ID can be used to apply custom styling to the form.

[bookingactivities_login form=2 id="custom-login-form" /]

Displaying a login form with a specific form ID, a custom CSS ID, and a redirect URL. After successful login, the user will be redirected to the specified URL.

[bookingactivities_login form=2 id="custom-login-form" redirect_url="https://example.com/welcome" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [bookingactivities_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'bookingactivities_login', 'bookacti_shortcode_login_form' );

Shortcode PHP function:

function bookacti_shortcode_login_form( $raw_atts = array(), $content = null, $tag = '' ) {
	$default_atts = array(
		'form' => 0,
		'redirect_url' => '',
		'id' => ''
	);
	$atts = shortcode_atts( $default_atts, array_change_key_case( (array) $raw_atts, CASE_LOWER ), $tag );
	$output = '';
	
	// Retrieve the booking form
	if( ! is_user_logged_in() && ! empty( $atts[ 'form' ] ) ) {
		$form_id = intval( $atts[ 'form' ] );
		$form_css_id = sanitize_title_with_dashes( $atts[ 'id' ] );
		$instance_id = $form_css_id ? esc_attr( $form_css_id ) : esc_attr( 'login-form-' . rand() );
		$GLOBALS[ 'bookacti_login_redirect_url' ] = esc_url_raw( $atts[ 'redirect_url' ] );
		$output = bookacti_display_form( $form_id, $instance_id, 'login_form', false );
	}

	return apply_filters( 'bookacti_shortcode_' . $tag . '_output', $output, $raw_atts, $content );
}

Code file location:

booking-activities/booking-activities/controller/controller-shortcodes.php

Conclusion

Now that you’ve learned how to embed the Booking Activities Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *