Appointment Booking Calendar Shortcodes

Below, you’ll find a detailed guide on how to add the Appointment Booking Calendar 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 Appointment Booking Calendar Plugin shortcodes not to show or not to work correctly.

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

Plugin Icon
Appointment Booking Calendar

"Appointment Booking Calendar is a user-friendly WordPress plugin enabling seamless scheduling. This tool simplifies the process of booking appointments, improving site functionality and user experience."

★★★★✩ (87) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [CPABC_APPOINTMENT_CALENDAR]
  • [CPABC_EDIT_CALENDAR]
  • [CPABC_APPOINTMENT_LIST]

Appointment Booking Calendar [CPABC_APPOINTMENT_CALENDAR] Shortcode

The CPABC Appointment Calendar shortcode allows users to embed an appointment booking calendar on their WordPress site. The shortcode can be customized to display a specific calendar or user. The associated PHP function extracts the ‘calendar’ and ‘user’ attributes from the shortcode. If a calendar ID is provided, it’s set as the fixed calendar ID. If a username is given, the function queries the database to retrieve that user’s ID. If neither is provided, the user ID defaults to 0. The function then generates the public form for booking appointments and returns it as the shortcode’s output. This allows the booking form to be inserted anywhere shortcodes are accepted.

Shortcode: [CPABC_APPOINTMENT_CALENDAR]

Parameters

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

  • calendar – Specifies the ID of the selected calendar
  • user – Defines the username to link with the calendar

Examples and Usage

Basic example – Displaying a default appointment booking calendar.

[CPABC_APPOINTMENT_CALENDAR /]

Advanced examples

Displaying a specific calendar by referencing its ID. Here, the ‘calendar’ parameter is used to specify the ID of the calendar to be displayed.

[CPABC_APPOINTMENT_CALENDAR calendar=1 /]

Displaying a calendar associated with a specific user. The ‘user’ parameter is used to specify the login name of the user whose calendar is to be displayed.

[CPABC_APPOINTMENT_CALENDAR user="john_doe" /]

In case where both ‘calendar’ and ‘user’ parameters are provided, the ‘calendar’ parameter takes precedence. If a calendar with the specified ID is not found, it will try to display the calendar associated with the specified user.

[CPABC_APPOINTMENT_CALENDAR calendar=1 user="john_doe" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'CPABC_APPOINTMENT_CALENDAR', 'cpabc_appointments_filter_content' );

Shortcode PHP function:

function cpabc_appointments_filter_content($atts) {
    global $wpdb;
    extract( shortcode_atts( array(
		'calendar' => '',
		'user' => '',
	), $atts ) );
    $calendar = 1;
    if ($calendar != '')
        define ('CPABC_CALENDAR_FIXED_ID',intval($calendar));
    else if ($user != '')
    {
        $users = $wpdb->get_results( "SELECT user_login,ID FROM ".$wpdb->users." WHERE user_login='".esc_sql($user)."'" );
        if (isset($users[0]))
            define ('CPABC_CALENDAR_USER',$users[0]->ID);
        else
            define ('CPABC_CALENDAR_USER',0);
    }
    else
        define ('CPABC_CALENDAR_USER',0);
    ob_start();
    cpabc_appointments_get_public_form();
    $buffered_contents = ob_get_contents();
    ob_end_clean();
    return $buffered_contents;
}

Code file location:

appointment-booking-calendar/appointment-booking-calendar/cpabc_appointments.php

Appointment Booking Calendar [CPABC_EDIT_CALENDAR] Shortcode

The Appointment Booking Calendar shortcode, CPABC_EDIT_CALENDAR, allows users to edit their calendar appointments. This shortcode fetches user-specific appointments from the database and displays them for editing.

Shortcode: [CPABC_EDIT_CALENDAR]

Parameters

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

  • calendar – Specifies the specific calendar to be edited
  • user – Defines the user allowed to make edits to the calendar

Examples and Usage

Basic Example – The shortcode is used to edit the appointment-booking-calendar by referencing the calendar’s ID.

[CPABC_EDIT_CALENDAR calendar=1 /]

Advanced Examples

In the following example, the shortcode is used to edit the appointment-booking-calendar by referencing both the calendar’s ID and the user’s ID. The calendar will first try to load by the calendar ID, but if not found, it will try to load by the user’s ID.

[CPABC_EDIT_CALENDAR calendar=1 user=2 /]

In another advanced example, the shortcode is used to edit the appointment-booking-calendar by referencing only the user’s ID. The calendar will load based on the user’s ID.

[CPABC_EDIT_CALENDAR user=3 /]

These examples demonstrate how the shortcode can be modified with different parameters to suit specific needs. Whether you need to edit the calendar based on the calendar’s ID, the user’s ID, or both, the shortcode provides the flexibility to do so.

PHP Function Code

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

Shortcode line:

add_shortcode( 'CPABC_EDIT_CALENDAR', 'cpabc_appointments_filter_edit' );

Shortcode PHP function:

function cpabc_appointments_filter_edit($atts) {
    global $wpdb;
    extract( shortcode_atts( array(
		'calendar' => '',
		'user' => '',
	), $atts ) );
	$buffered_contents = '';
	$current_user = wp_get_current_user();
	$myrows = $wpdb->get_results( "SELECT * FROM ".CPABC_APPOINTMENTS_CONFIG_TABLE_NAME." where conwer<>'' AND conwer='".esc_sql($current_user->ID )."'" );
    if (count($myrows))
    {
        if (!defined('CP_CALENDAR_ID'))
            define ('CP_CALENDAR_ID',$myrows[0]->id);
        define ('CPABC_CALENDAR_ON_PUBLIC_WEBSITE',true);
        ob_start();
        @include_once dirname( __FILE__ ) . '/cpabc_appointments_admin_int.inc.php';
        $buffered_contents = ob_get_contents();
        ob_end_clean();
    }
    return $buffered_contents;
}

Code file location:

appointment-booking-calendar/appointment-booking-calendar/cpabc_appointments.php

Appointment Booking Calendar [CPABC_APPOINTMENT_LIST] Shortcode

The ‘CPABC_APPOINTMENT_LIST’ shortcode is designed to display a list of appointments from the Appointment Booking Calendar plugin. It fetches data based on attributes like ‘calendar’, ‘user’, ‘group’, ‘fields’, ‘from’, and ‘to’. It also allows grouping of data and customizing the display fields. The shortcode can filter appointments based on a specific user or calendar ID. It can also define a date range for the appointments to be displayed.

Shortcode: [CPABC_APPOINTMENT_LIST]

Parameters

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

  • calendar – The ID of the specific calendar to show appointments from.
  • user – The username to filter appointments by.
  • group – To group appointments by ‘yes’ or ‘no’.
  • fields – The details to include in the list like ‘DATE’, ‘TIME’, ‘NAME’.
  • from – The start date to filter appointments from.
  • to – The end date to filter appointments to.

Examples and Usage

Basic example – Display the appointment list for the current day.

[CPABC_APPOINTMENT_LIST]

Advanced examples

Display the appointment list for a specific calendar, by referencing the calendar ID. The appointments will be grouped.

[CPABC_APPOINTMENT_LIST calendar=1 group='yes']

Display the appointment list for a specific user, by referencing the user login. The appointments will be shown for the next 30 days.

[CPABC_APPOINTMENT_LIST user='admin' from='today' to='today +30 days']

Display a specific set of fields in the appointment list for the next 90 days. The fields to be shown are DATE, TIME, and NAME.

[CPABC_APPOINTMENT_LIST fields='DATE,TIME,NAME' from='today' to='today +90 days']

Display the appointment list for a specific calendar and user, by referencing both the calendar ID and the user login. The appointments will be shown for the next 30 days, and the appointments will be grouped.

[CPABC_APPOINTMENT_LIST calendar=1 user='admin' from='today' to='today +30 days' group='yes']

PHP Function Code

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

Shortcode line:

add_shortcode( 'CPABC_APPOINTMENT_LIST', 'cpabc_appointments_filter_list' );

Shortcode PHP function:

function cpabc_appointments_filter_list($atts) {
    global $wpdb;
    extract( shortcode_atts( array(
		'calendar' => '',
		'user' => '',
		'group' => 'no',
		'fields' => 'DATE,TIME,NAME',
		'from' => "today",
		'to' => "today +90 days",
	), $atts ) );

	$from = date("Y-m-d 00:00:00", strtotime($from));
	$to = date("Y-m-d 23:59:59", strtotime($to));
	$group = strtolower($group);

    if ($calendar != '')
        define ('CPABC_CALENDAR_FIXED_ID', intval($calendar));
    else if ($user != '')
    {
        $users = $wpdb->get_results( "SELECT user_login,ID FROM ".$wpdb->users." WHERE user_login='".esc_sql($user)."'" );
        if (isset($users[0]))
            define ('CPABC_CALENDAR_USER',$users[0]->ID);
        else
            define ('CPABC_CALENDAR_USER',0);
    }
    else
        define ('CPABC_CALENDAR_USER',0);

    if (defined('CPABC_CALENDAR_USER') && CPABC_CALENDAR_USER != 0)
        $myrows = $wpdb->get_results( "SELECT * FROM ".CPABC_APPOINTMENTS_CONFIG_TABLE_NAME." WHERE conwer=".CPABC_CALENDAR_USER." AND caldeleted=0" );
    else if (defined('CPABC_CALENDAR_FIXED_ID'))
        $myrows = $wpdb->get_results( "SELECT * FROM ".CPABC_APPOINTMENTS_CONFIG_TABLE_NAME." WHERE id=".CPABC_CALENDAR_FIXED_ID." AND caldeleted=0" );
    else
        $myrows = $wpdb->get_results( "SELECT * FROM ".CPABC_APPOINTMENTS_CONFIG_TABLE_NAME." WHERE caldeleted=0" );

    if (!defined('CP_CALENDAR_ID')) define ('CP_CALENDAR_ID',$myrows[0]->id);

    ob_start();
    echo '<link rel="stylesheet" type="text/css" href="'.plugins_url('../TDE_AppCalendar/'.esc_attr(cpabc_get_option('calendar_theme','modern/')).'all-css.css', __FILE__).'" />';
    $fields = explode(",",$fields);
    $last_date = '';
    $mycalendarrows = $wpdb->get_results( "SELECT * FROM ".CPABC_TDEAPP_CALENDAR_DATA_TABLE ." INNER JOIN  ".CPABC_APPOINTMENTS_TABLE_NAME." on  ".CPABC_APPOINTMENTS_TABLE_NAME.".id=".CPABC_TDEAPP_CALENDAR_DATA_TABLE.".reference WHERE datatime>='".esc_sql($from)."' AND datatime<='".esc_sql($to)."' AND appointment_calendar_id=".intval(CP_CALENDAR_ID)." ORDER BY datatime ASC");
    for($f=0; $f<count($mycalendarrows); $f++) {
        $params = unserialize($mycalendarrows[$f]->buffered_date);
        $params["CALENDAR"] = $mycalendarrows[$f]->appointment_calendar_id;
        $newline = ($last_date != $mycalendarrows[$f]->booked_time_unformatted);
        if ($group != 'yes' || $newline)
        {
            echo '<div class="cpabc_field_clear"></div>';
        }
        for ($k=0; $k < count($fields); $k++)
        {
            $fieldname = trim($fields[$k]);
            if ($group == 'yes')
            {
                if ($newline || ($fieldname != "DATE" && $fieldname != "TIME"))
                {
                    echo '<div class="cpabc_field_'.intval($k).'">';
                    echo esc_html(@$params[$fieldname]);
                    if ($fieldname != "DATE" && $fieldname != "TIME")
                    {
                        while ($f<count($mycalendarrows) && @$mycalendarrows[$f+1]->booked_time_unformatted == @$mycalendarrows[$f]->booked_time_unformatted)
                        {
                            $f++;
                            $params = unserialize($mycalendarrows[$f]->buffered_date);
                            echo ", ".esc_html(@$params[$fieldname]);
                        }
                        $k = count($fields);
                    }
                    echo '</div>';
                }
            }
            else
                echo '<div class="cpabc_field_'.$k.'">'.esc_html(@$params[$fieldname]).'</div>';
        }
        $last_date = $mycalendarrows[$f]->booked_time_unformatted;
    }
    echo '<div class="cpabc_field_clear"></div>';
    $buffered_contents = ob_get_contents();
    ob_end_clean();
    return $buffered_contents;
}

Code file location:

appointment-booking-calendar/appointment-booking-calendar/cpabc_appointments.php

Conclusion

Now that you’ve learned how to embed the Appointment Booking Calendar 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 *