Below, you’ll find a detailed guide on how to add the Appointment Hour Booking 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 Hour Booking Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Appointment Hour Booking Plugin and the shortcodes it provides:
"Appointment Hour Booking – WordPress Booking Plugin is a user-friendly tool that simplifies scheduling and booking processes. It's a perfect solution for businesses to manage appointments seamlessly."
- [cp_appb_plugin]
- [CP_APP_HOUR_BOOKING_LIST]
Appointment Hour Booking [cp_appb_plugin] Shortcode
The Appointment Hour Booking shortcode allows the integration of a booking form into a page. It filters content based on form attributes and generates HTML code. It first extracts the ‘id’ attribute from the shortcode and applies pre-form filters to modify attributes. It then generates the booking form and stores the output. Post-form filters are applied to the HTML code, which is then returned for inclusion on the webpage.
Shortcode: [cp_appb_plugin]
Parameters
Here is a list of all possible cp_appb_plugin shortcode parameters and attributes:
id
– A unique number that identifies the specific form.
Examples and Usage
Basic example – The shortcode displays the booking form linked to the specified ID
[cp_appb_plugin id="1" /]
Advanced examples
Using the shortcode to display the booking form with multiple attributes. The attributes are passed to the filter_content function, which then processes them and renders the form accordingly.
[cp_appb_plugin id="1" attribute_1="value_1" attribute_2="value_2" /]
Utilizing the shortcode to apply pre and post form filters. This allows you to modify the form attributes before the form is generated and alter the HTML code after the form is generated.
[cp_appb_plugin id="1" cpappb_pre_form="function_to_apply" cpappb_the_form="function_to_apply" /]
Note: In the advanced examples, ‘attribute_1’ and ‘attribute_2’ are placeholders for any attribute that you want to pass to the filter_content function. Similarly, ‘function_to_apply’ is a placeholder for any function you want to apply as a filter.
PHP Function Code
In case you have difficulties debugging what causing issues with [cp_appb_plugin]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( $cp_appb_plugin->shorttag, array($cp_appb_plugin, 'filter_content') );
Shortcode PHP function:
function filter_content($atts) {
global $wpdb;
extract( shortcode_atts( array(
'id' => '',
), $atts ) );
if ($id != '')
$this->item = intval($id);
/**
* Filters applied before generate the form,
* is passed as parameter an array with the forms attributes, and return the list of attributes
*/
$atts = apply_filters( 'cpappb_pre_form', $atts );
ob_start();
$this->insert_public_item();
$buffered_contents = ob_get_contents();
ob_end_clean();
/**
* Filters applied after generate the form,
* is passed as parameter the HTML code of the form with the corresponding <LINK> and <SCRIPT> tags,
* and returns the HTML code to includes in the webpage
*/
$buffered_contents = apply_filters( 'cpappb_the_form', $buffered_contents, $this->item );
return $buffered_contents;
}
Code file location:
appointment-hour-booking/appointment-hour-booking/app-booking-plugin.php
Appointment Hour Booking [CP_APP_HOUR_BOOKING_LIST] Shortcode
The Appointment Hour Booking plugin shortcode, ‘CP_APP_HOUR_BOOKING_LIST’, is designed to generate a list of appointments. It takes parameters such as calendar ID, fields, date range, status, service, email, user, maximum items, and limit. It enqueues styles, calculates dates, and creates queries based on the parameters. It then retrieves, sorts, and formats the appointment data from the database. It finally displays the data as per the specified fields.
Shortcode: [CP_APP_HOUR_BOOKING_LIST]
Parameters
Here is a list of all possible CP_APP_HOUR_BOOKING_LIST shortcode parameters and attributes:
calendar
– IDs of the calendar(s), separated by commasfields
– Fields to display: DATE, TIME, emailfrom
– Start date for the booking listto
– End date for the booking listpaidonly
– Show only paid bookingsstatus
– Show bookings with specific statusservice
– Show bookings for specific serviceemail
– Show bookings for specific emailonlycurrentuser
– Show bookings of the currently logged in usermaxitems
– Maximum number of bookings to displaylimit
– Limit the number of bookings fetched from the database
Examples and Usage
Basic example – Displaying a list of appointments for a specific calendar within the next 30 days.
[CP_APP_HOUR_BOOKING_LIST calendar="1" from="today" to="today +30 days"]
Advanced examples
Displaying a list of appointments for multiple calendars (1,2,3) within the next 7 days, only showing approved appointments.
[CP_APP_HOUR_BOOKING_LIST calendar="1,2,3" from="today" to="today +7 days" status="approved"]
Displaying a list of appointments for a specific calendar within the next 30 days, only showing appointments for a specific service (e.g., ‘Haircut’) and a specific user email (e.g., ‘user@example.com’).
[CP_APP_HOUR_BOOKING_LIST calendar="1" from="today" to="today +30 days" service="Haircut" email="user@example.com"]
Displaying a list of appointments for a specific calendar within the next 30 days, limiting the list to the first 10 appointments only.
[CP_APP_HOUR_BOOKING_LIST calendar="1" from="today" to="today +30 days" maxitems="10"]
Displaying a list of appointments for a specific calendar within the next 30 days, only showing appointments that have been paid.
[CP_APP_HOUR_BOOKING_LIST calendar="1" from="today" to="today +30 days" paidonly="true"]
PHP Function Code
In case you have difficulties debugging what causing issues with [CP_APP_HOUR_BOOKING_LIST]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'CP_APP_HOUR_BOOKING_LIST', array($cp_appb_plugin, 'filter_list') );
Shortcode PHP function:
function filter_list($atts) {
global $wpdb;
extract( shortcode_atts( array(
'calendar' => '', // accepts comma separated IDs
'fields' => 'DATE,TIME,email',
'from' => "today",
'to' => "today +30 days",
'paidonly' => "",
'status' => "notcancelled", // "all" means all statuses
'service' => "",
'email' => "",
'onlycurrentuser' => "",
'maxitems' => "",
'limit' => "10000"
), $atts ) );
if (!is_admin())
{
wp_enqueue_style('cpapp-publicstyle', plugins_url('css/stylepublic.css', __FILE__));
wp_enqueue_style('cpapp-custompublicstyle', $this->fixurl($this->get_site_url( false ),'cp_cpappb_resources=css'));
}
if (strtolower($status) == 'approved')
$status = '';
ob_start();
if ($this->get_option('date_format', 'mm/dd/yy') == 'dd/mm/yy')
{
$from = str_replace('/','.',$from);
$to = str_replace('/','.',$to);
}
// calculate dates
$from = date("Y-m-d",$this->localtimezone_strtotime($from));
$to = date("Y-m-d",$this->localtimezone_strtotime($to));
$to_query = date("Y-m-d",$this->localtimezone_strtotime($to." +1 day"));
$calquery = '';
$calendar = explode (",",$calendar);
foreach ($calendar as $cal)
if (trim($cal))
{
$calquery .= ($calquery!=''?' OR ':'').'formid='.intval(trim($cal));
$this->setId(intval(trim($cal)));
}
if ($calquery != '')
$calquery = '('.$calquery.') AND ';
if (strtolower($onlycurrentuser) == 'yes' || strtolower($onlycurrentuser) == 'true')
{
$current_user = wp_get_current_user();
if ($current_user->ID)
$user_query = " whoadded='".esc_sql($current_user->ID)."' AND ";
else
$user_query = "(1=0) AND "; // if no logged in user then no current user bookings
}
else
$user_query = '';
if ($email != '')
$user_query .= " (notifyto='".esc_sql($email)."') AND ";
// pre-select time-slots
$selection = array();
$rows = $wpdb->get_results( $wpdb->prepare("SELECT notifyto,posted_data,data,formid FROM ".$wpdb->prefix.$this->table_messages." WHERE notifyto<>'".esc_sql($this->blocked_by_admin_indicator)."' AND ".$user_query.$calquery."time<=%s ORDER BY time DESC LIMIT 0,".intval($limit), $to_query) );
foreach($rows as $item)
{
$data = unserialize($item->posted_data);
if (!$paidonly || (!empty($data['paid']) && $data['paid']))
{
$appindex = 0;
if (is_array($data["apps"]))
foreach($data["apps"] as $app)
{
$appindex++;
if ($app["date"] >= $from && $app["date"] <= $to &&
($status == 'notcancelled' || $status == 'all' || $status == $app["cancelled"]) &&
($status != 'notcancelled' || ('Cancelled by customer' != $app["cancelled"] && 'Cancelled' != $app["cancelled"]) )
)
{
if ($service == '' || $service == $app["service"])
$selection[] = array(
$app["date"]." ".$app["slot"],
$app["date"],
str_replace("/","-",$app["slot"]),
$data,
sanitize_email($item->notifyto),
$item->data,
$app["cancelled"],
$app["service"],
$appindex, // 8
$item->formid, // 9
$app["quant"] // 10
);
}
}
}
}
// order time-slots
if (!function_exists('appbkfastsortfn'))
{
function appbkfastsortfn($a, $b) { return ($a[0] > $b[0]?1:-1); }
}
usort($selection, "appbkfastsortfn" );
// clean fields IDs
$fields = explode(",",trim($fields));
for($j=0; $j<count($fields); $j++)
$fields[$j] = strtolower(trim($fields[$j]));
// print table
if (!count($selection))
echo '<div class="cpappb_noapps">'.__('No appointments found with the selected filters','appointment-hour-booking').'</div>';
else for($i=0; $i<count($selection) && ($maxitems == '' || $i < $maxitems); $i++)
{
echo '<div class="cpapp_no_wrap">';
for($j=0; $j<count($fields); $j++)
{
echo '<div class="cpappb_field_'.$j.($selection[$i][6]!=''?' cpappb_cancelled':'').'">';
switch ($fields[$j]) {
case 'rownumber':
echo intval($i)+1;
break;
case 'weekday':
echo ucfirst(__(date('l',strtotime($selection[$i][1]))));
break;
case 'date':
echo esc_html($this->format_date($selection[$i][1]));
break;
case 'time':
echo esc_html($selection[$i][2]);
break;
case 'email':
echo "<a href=\"mailto:".esc_attr($selection[$i][4])."\">".esc_html($selection[$i][4])."</a> ";
break;
case 'service':
echo esc_html($selection[$i][7])." ";
break;
case 'quantity':
echo esc_html($selection[$i][10])." ";
break;
case 'cancelled':
if ($selection[$i][6] == '')
echo __('Approved','appointment-hour-booking');
else
echo esc_html(__($selection[$i][6],'appointment-hour-booking'));
echo ' ';
break;
case 'data':
echo esc_html(substr($selection[$i][5],strpos($selection[$i][5],"\n\n")+2));
break;
case 'paid':
echo esc_html(( (!empty($selection[$i][3]['paid']) && $selection[$i][3]['paid'])?__('Yes','appointment-hour-booking'):' '));
break;
default:
if (is_array($selection[$i][3][$fields[$j]]))
echo esc_html(implode(",",$selection[$i][3][$fields[$j]]));
else
echo esc_html(($selection[$i][3][$fields[$j]]==''?' ':$selection[$i][3][$fields[$j]])." ");
}
echo '</div>';
}
echo '</div>';
echo '<div class="cpapp_break"></div>';
}
$buffered_contents = ob_get_contents();
ob_end_clean();
return $buffered_contents;
}
Code file location:
appointment-hour-booking/appointment-hour-booking/app-booking-plugin.php
Conclusion
Now that you’ve learned how to embed the Appointment Hour Booking 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.
Leave a Reply