| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Booking Calendar |
| 5 |
* @subpackage Create pages Functions |
| 6 |
* @category Functions |
| 7 |
* |
| 8 |
* @author wpdevelop |
| 9 |
* @link https://wpbookingcalendar.com/ |
| 10 |
* @email info@wpbookingcalendar.com |
| 11 |
* |
| 12 |
* @modified 2023-05-10 |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 16 |
|
| 17 |
|
| 18 |
/** |
| 19 |
* Create page for Booking Calendar |
| 20 |
* |
| 21 |
* @param array $page_params = array( |
| 22 |
'post_content' => '[bookingedit]', |
| 23 |
'post_name' => 'wpbc-booking-edit', |
| 24 |
'post_title' => esc_html__('Booking edit','booking') |
| 25 |
) |
| 26 |
* |
| 27 |
* @return false|int - ID of the page. |
| 28 |
*/ |
| 29 |
function wpbc_create_page( $page_params = array() ){ // FixIn: 9.6.2.10. |
| 30 |
|
| 31 |
global $wp_rewrite; |
| 32 |
if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1. |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
// Create post object |
| 37 |
$defaults = array( |
| 38 |
//'menu_order' => 0, // The order the post should be displayed in. Default 0. If new post is a page, it sets the order in which it should appear in the tabs. |
| 39 |
//'pinged' => '', // Space or carriage return-separated list of URLs that have been pinged. Default empty. |
| 40 |
//'post_author' => get_current_user_id(), // The user ID number of the author. The ID of the user who added the post. Default is the current user ID. |
| 41 |
//'post_category' => array(), // Array of category IDs. Defaults to value of the 'default_category' option. post_category no longer exists, try wp_set_post_terms() for setting a post's categories |
| 42 |
//'post_date' => [ Y-m-d H:i:s ] // The date of the post. Default is the current time. The time post was made. |
| 43 |
//'post_date_gmt' => [ Y-m-d H:i:s ] // The time post was made, in GMT. |
| 44 |
//'post_excerpt' => '' //The post excerpt. Default empty. For all your post excerpt needs. |
| 45 |
//'post_parent' => 0, // Set this for the post it belongs to, if any. Default 0. Sets the parent of the new post. |
| 46 |
//'post_password' => '', //The password to access the post. Default empty. password for post? |
| 47 |
//'tags_input' => '', // Array of tag names, slugs, or IDs. Default empty. [ '<tag>, <tag>, <...>' ] //For tags. |
| 48 |
//'to_ping' => '', // Space or carriage return-separated list of URLs to ping. Default empty. Space or carriage return-separated list of URLs to ping. Default empty. |
| 49 |
//'tax_input' => '', // Default empty. [ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // support for custom taxonomies. |
| 50 |
'ID' => 0, // The post ID. If equal to something other than 0, the post with that ID will be updated. Default 0. |
| 51 |
'post_type' => 'page', // The post type. Default 'post'. [ 'post' | 'page' | 'link' | 'nav_menu_item' | 'custom_post_type' ] //You may want to insert a regular post, page, link, a menu item or some custom post type |
| 52 |
'post_status' => 'publish', // [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | 'custom_registered_status' ] // The post status. Default 'draft'. Set the status of the new post. |
| 53 |
'comment_status' => 'closed', // [ 'closed' | 'open' ] // 'closed' means no comments. |
| 54 |
'ping_status' => 'closed', // [ 'closed' | 'open' ] // 'closed' means pingbacks or trackbacks turned off |
| 55 |
'post_content' => '[bookingedit]', // The post content. Default empty. The full text of the post. |
| 56 |
'post_name' => 'wpbc-booking-edit', // sanitize_title( $post_title ), -- By default, converts accent characters to ASCII characters and further limits the output to alphanumeric characters, underscore (_) and dash (-) // The post name. Default is the sanitized post title when creating a new post. The name (slug) for your post |
| 57 |
'post_title' => esc_html__('Booking edit','booking') // The post title. Default empty. The title of your post. |
| 58 |
); |
| 59 |
|
| 60 |
|
| 61 |
$my_post = wp_parse_args( $page_params, $defaults ); |
| 62 |
|
| 63 |
|
| 64 |
$post_id = wp_insert_post( $my_post ); // Insert the post into the database |
| 65 |
|
| 66 |
if ( ( ! is_wp_error( $post_id ) ) && ( ! empty( $post_id ) ) ) { |
| 67 |
|
| 68 |
// Success |
| 69 |
|
| 70 |
// $post = get_post( $post_id ); |
| 71 |
// $post_url = get_permalink( $post_id ); |
| 72 |
|
| 73 |
} else { |
| 74 |
if ( is_wp_error( $post_id ) ) { |
| 75 |
// Error // __( 'Sorry, the post could not be created.' ) |
| 76 |
} |
| 77 |
if ( ! $post_id ) { |
| 78 |
// Error // __( 'Sorry, the post could not be created.' ) |
| 79 |
} |
| 80 |
$post_id = false; |
| 81 |
} |
| 82 |
|
| 83 |
return $post_id; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
/** |
| 88 |
* Is shortcode or some text exist in specific page |
| 89 |
* |
| 90 |
* @param string $relative_url relative URL of the page, if we have absolute url, then get it using: wpbc_make_link_relative( 'https://...' ); |
| 91 |
* @param string $shortcode_to_add shortcode to check '[booking' |
| 92 |
* |
| 93 |
* @return bool |
| 94 |
*/ |
| 95 |
function wpbc_is_shortcode_exist_in_page( $relative_url, $shortcode_to_add ) { |
| 96 |
|
| 97 |
if ( ! empty( $relative_url ) ) { |
| 98 |
|
| 99 |
$post_obj = get_page_by_path( $relative_url ); |
| 100 |
|
| 101 |
if ( ! empty( $post_obj ) ) { |
| 102 |
if ( false !== strpos( $post_obj->post_content, $shortcode_to_add ) ) { |
| 103 |
return true; |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
/** |
| 113 |
* Add shortcode, if it does not exist yet, to the page |
| 114 |
* |
| 115 |
* @param string $relative_url relative URL of the page, if we have absolute url, then get it using: wpbc_make_link_relative( 'https://...' ); |
| 116 |
* @param string $shortcode_to_add shortcode '[bookingedit]' |
| 117 |
* |
| 118 |
* @return bool |
| 119 |
*/ |
| 120 |
function wpbc_add_shortcode_to_exist_page( $relative_url, $shortcode_to_add ) { |
| 121 |
|
| 122 |
if ( ! empty( $relative_url ) ) { |
| 123 |
|
| 124 |
$post_obj = get_page_by_path( $relative_url ); |
| 125 |
|
| 126 |
if ( ! empty( $post_obj ) ) { |
| 127 |
if ( false === strpos( $post_obj->post_content, $shortcode_to_add ) ) { // No such shortcode in this page. So we need to Add it. |
| 128 |
|
| 129 |
$my_post = array( |
| 130 |
'ID' => $post_obj->ID, |
| 131 |
'post_content' => $post_obj->post_content . "\r\n" . $shortcode_to_add |
| 132 |
); |
| 133 |
wp_update_post( $my_post ); // Update the post into the database |
| 134 |
|
| 135 |
return true; |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
return false; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
// --------------------------------------------------------------------------------------------------------------------- |
| 145 |
|
| 146 |
/** |
| 147 |
* Create new page or add to existing page the shortcode |
| 148 |
* |
| 149 |
* @param array $params |
| 150 |
* |
| 151 |
* @return array success: [ 'result' => true, 'relative_url' => $relative_post_url, 'message' => __( 'Booking form shortcode embedded into the page.', 'booking' ) ] |
| 152 |
* failed: [ 'result' => false, 'message' => __( 'We can not embed booking form shortcode into the page.', 'booking' ) ] |
| 153 |
* |
| 154 |
* Example: |
| 155 |
* $result_arr = wpbc_add_shortcode_into_page( array( |
| 156 |
* 'shortcode' => '[booking resource_id=1]', |
| 157 |
* 'post_title' => 'Booking Form' |
| 158 |
* ) ); |
| 159 |
*/ |
| 160 |
function wpbc_add_shortcode_into_page( $params = array() ) { |
| 161 |
|
| 162 |
$defaults = array( |
| 163 |
'page_post_name' => '', // 'wpbc-booking', |
| 164 |
'post_title' => esc_html( __( 'Booking Form', 'booking' ) ), |
| 165 |
'shortcode' => '[booking resource_id=1]', |
| 166 |
'check_exist_shortcode' => '[booking', // can be an array: array( '[booking resource_id=1]', '[booking type=1]', '[booking]' ) |
| 167 |
'page_id' => 0, |
| 168 |
'resource_id' => 0 // Optional |
| 169 |
); |
| 170 |
$params = wp_parse_args( $params, $defaults ); |
| 171 |
|
| 172 |
if ( empty( $params['page_post_name'] ) ) { |
| 173 |
$params['page_post_name'] = sanitize_title( $params['post_title'] ); // Get slug for the page |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
global $wp_rewrite; |
| 178 |
if ( is_null( $wp_rewrite ) ) { |
| 179 |
return array( 'result' => false, 'message' => 'Sorry, we are unable to insert the shortcode into the page. The reason is that wp_rewrite is not initialized.' ); |
| 180 |
} |
| 181 |
// ----------------------------------------------------------------------------------------------------------------- |
| 182 |
|
| 183 |
$params['page_id'] = intval( $params['page_id'] ); |
| 184 |
if ( ! empty( $params['page_id'] ) ) { |
| 185 |
$wp_post = get_post( $params['page_id'] ); |
| 186 |
} else { |
| 187 |
$wp_post = get_page_by_path( $params['page_post_name'] ); |
| 188 |
} |
| 189 |
|
| 190 |
$relative_post_url = ''; |
| 191 |
|
| 192 |
$post_title = ''; |
| 193 |
$post_url = ''; |
| 194 |
if ( ! empty( $wp_post ) ) { |
| 195 |
$post_title = $wp_post->post_title; |
| 196 |
$post_url = get_permalink( $wp_post->ID ); |
| 197 |
} |
| 198 |
|
| 199 |
if ( empty( $wp_post ) ) { // No default page. Create it. |
| 200 |
|
| 201 |
$page_params = array( |
| 202 |
'post_title' => $params['post_title'], |
| 203 |
'post_content' => $params['shortcode'], |
| 204 |
'post_name' => $params['page_post_name'] |
| 205 |
); |
| 206 |
$post_id = wpbc_create_page( $page_params ); |
| 207 |
|
| 208 |
if ( ! empty( $post_id ) ) { |
| 209 |
|
| 210 |
$new_post = get_post( $post_id ); |
| 211 |
if ( ! empty( $new_post ) ) { |
| 212 |
$post_title = $new_post->post_title; |
| 213 |
$post_url = get_permalink( $new_post->ID ); |
| 214 |
} |
| 215 |
|
| 216 |
$relative_post_url = wpbc_make_link_relative( get_permalink( $post_id ) ); |
| 217 |
|
| 218 |
// Scroll to the booking form. |
| 219 |
if ( ! empty( $params['resource_id'] ) ) { |
| 220 |
$post_url .= '#bklnk' . $params['resource_id']; |
| 221 |
} |
| 222 |
|
| 223 |
return array( 'result' => true, |
| 224 |
'relative_url' => $relative_post_url, |
| 225 |
/* translators: 1: ... */ |
| 226 |
'message' => __( 'A new page has been created.', 'booking' ) . ' ' . sprintf( __( 'The booking form shortcode %1$s has been embedded into the page %2$s', 'booking' ) |
| 227 |
, "<code class='wpbc_inserted_shortcode_view'>{$params['shortcode']}</code>" |
| 228 |
, "<a class='wpbc_open_page_as_new_tab' href='" . esc_url( $post_url ) . "'>{$post_title}</a>" |
| 229 |
. " <a target='_blank' class='wpbc_open_page_as_new_tab tooltip_top wpbc-bi-arrow-up-right-square' href='" . esc_url( $post_url ) . "' title='" . esc_attr( __( 'Open in new window', 'booking' ) ) . "'></a>" |
| 230 |
) |
| 231 |
); |
| 232 |
} |
| 233 |
|
| 234 |
} else { |
| 235 |
$relative_post_url = wpbc_make_link_relative( get_permalink( $wp_post->ID ) ); // Page already exist, so we need to update the |
| 236 |
} |
| 237 |
|
| 238 |
// Check if the shortcode in the page |
| 239 |
$is_shortcode_already_in_page = false; |
| 240 |
if ( is_array( $params['check_exist_shortcode'] ) ) { |
| 241 |
foreach ( $params['check_exist_shortcode'] as $check_shortcode ) { |
| 242 |
$is_shortcode_already_in_page = wpbc_is_shortcode_exist_in_page( $relative_post_url, $check_shortcode ); |
| 243 |
if ( $is_shortcode_already_in_page ) { |
| 244 |
break; |
| 245 |
} |
| 246 |
} |
| 247 |
} else { |
| 248 |
$is_shortcode_already_in_page = wpbc_is_shortcode_exist_in_page( $relative_post_url, $params['check_exist_shortcode'] ); |
| 249 |
} |
| 250 |
|
| 251 |
// Scroll to the booking form. |
| 252 |
if ( ! empty( $params['resource_id'] ) ) { |
| 253 |
$post_url .= '#bklnk' . $params['resource_id']; |
| 254 |
} |
| 255 |
|
| 256 |
// Check if existing page has our shortcode. We are checking for 'booking' because it can be '[booking]' or '[booking type=1]' ... |
| 257 |
if ( |
| 258 |
( ! $is_shortcode_already_in_page ) |
| 259 |
&& ( ! wpbc_is_shortcode_exist_in_page( $relative_post_url, $params['shortcode'] ) ) |
| 260 |
) { |
| 261 |
$is_sh_added = wpbc_add_shortcode_to_exist_page( $relative_post_url, $params['shortcode'] ); |
| 262 |
|
| 263 |
if ( $is_sh_added ) { |
| 264 |
return array( 'result' => true, |
| 265 |
'relative_url' => $relative_post_url, |
| 266 |
/* translators: 1: ... */ |
| 267 |
'message' => sprintf( __( 'The booking form shortcode %1$s has been embedded into the page %2$s', 'booking' ) |
| 268 |
, "<code class='wpbc_inserted_shortcode_view'>{$params['shortcode']}</code>" |
| 269 |
, "<a class='wpbc_open_page_as_new_tab' href='" . esc_url( $post_url ) . "'>{$post_title}</a>" |
| 270 |
. " <a target='_blank' class='wpbc_open_page_as_new_tab tooltip_top wpbc-bi-arrow-up-right-square' href='" . esc_url( $post_url ) . "' title='" . esc_attr( __( 'Open in new window', 'booking' ) ) . "'></a>" |
| 271 |
|
| 272 |
) |
| 273 |
); |
| 274 |
|
| 275 |
} else { |
| 276 |
return array( 'result' => false, |
| 277 |
/* translators: 1: ... */ |
| 278 |
'message' => sprintf( __( 'We are unable to embed the booking form shortcode %1$s into the page %2$s.', 'booking' ) |
| 279 |
, "<code class='wpbc_inserted_shortcode_view'>{$params['shortcode']}</code>" |
| 280 |
, "<a class='wpbc_open_page_as_new_tab' href='" . esc_url( $post_url ) . "'>{$post_title}</a>" |
| 281 |
. " <a target='_blank' class='wpbc_open_page_as_new_tab tooltip_top wpbc-bi-arrow-up-right-square' href='" . esc_url( $post_url ) . "' title='" . esc_attr( __( 'Open in new window', 'booking' ) ) . "'></a>" |
| 282 |
) |
| 283 |
); |
| 284 |
} |
| 285 |
} else { |
| 286 |
|
| 287 |
return array( 'result' => false, |
| 288 |
/* translators: 1: ... */ |
| 289 |
'message' => sprintf( __( 'The Booking Calendar shortcode %1$s is already present on this page %2$s.', 'booking' ) |
| 290 |
, "<code class='wpbc_inserted_shortcode_view'>{$params['shortcode']}</code>" |
| 291 |
, "<a class='wpbc_open_page_as_new_tab' href='" . esc_url( $post_url ) . "'>{$post_title}</a>" |
| 292 |
. " <a target='_blank' class='wpbc_open_page_as_new_tab tooltip_top wpbc-bi-arrow-up-right-square' href='" . esc_url( $post_url ) . "' title='" . esc_attr( __( 'Open in new window', 'booking' ) ) . "'></a>" |
| 293 |
) |
| 294 |
); |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
// --------------------------------------------------------------------------------------------------------------------- |
| 302 |
// --------------------------------------------------------------------------------------------------------------------- |
| 303 |
// --------------------------------------------------------------------------------------------------------------------- |
| 304 |
|
| 305 |
|
| 306 |
/** |
| 307 |
* Create new starter page with booking form |
| 308 |
* |
| 309 |
* @param $default_options_to_add - array from function wpbc_get_default_options(), which passed only from 'wpbc_before_activation__add_options'. Here we skip this option. |
| 310 |
* |
| 311 |
* @return void |
| 312 |
*/ |
| 313 |
function wpbc_create_page_with_booking_form( $default_options_to_add = array() ) { // FixIn: 9.6.2.11. |
| 314 |
|
| 315 |
global $wp_rewrite; |
| 316 |
if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1. |
| 317 |
|
| 318 |
// Maybe it was not init, yet |
| 319 |
if ( ! has_action( 'init', 'wpbc_create_page_with_booking_form' ) ) { |
| 320 |
add_action( 'init', 'wpbc_create_page_with_booking_form', 99 ); // <- priority to load it last |
| 321 |
} |
| 322 |
return false; |
| 323 |
} |
| 324 |
|
| 325 |
// ----------------------------------------------------------------------------------------------------------------- |
| 326 |
$post_url = ''; |
| 327 |
|
| 328 |
// FixIn: 10.9.2.5. |
| 329 |
if ( empty( get_page_by_path( 'wpbc-booking' ) ) ) { // Old page, NOT created before - Use new url |
| 330 |
$post_name_slug = 'wp-booking-calendar'; |
| 331 |
} else { // Old page already was Created - Use old url |
| 332 |
$post_name_slug = 'wpbc-booking'; |
| 333 |
} |
| 334 |
$wp_post = get_page_by_path( $post_name_slug ); |
| 335 |
|
| 336 |
if ( empty( $wp_post ) ) { // No default page. Create it. |
| 337 |
|
| 338 |
$page_params = array( |
| 339 |
'post_title' => esc_html( __( 'Booking Form', 'booking' ) ), |
| 340 |
'post_content' => '[booking resource_id=1]', |
| 341 |
'post_name' => $post_name_slug |
| 342 |
); |
| 343 |
$post_id = wpbc_create_page( $page_params ); |
| 344 |
|
| 345 |
if ( ! empty( $post_id ) ) { |
| 346 |
$post_url = wpbc_make_link_relative( get_permalink( $post_id ) ); |
| 347 |
} |
| 348 |
|
| 349 |
} else { |
| 350 |
$post_url = wpbc_make_link_relative( get_permalink( $wp_post->ID ) ); // Page already exist, so we need to update the |
| 351 |
} |
| 352 |
|
| 353 |
// ----------------------------------------------------------------------------------------------------------------- |
| 354 |
|
| 355 |
// Check if existing page has our shortcode. We are checking for 'booking' because it can be '[booking]' or '[booking type=1]' ... |
| 356 |
if ( ! wpbc_is_shortcode_exist_in_page( $post_url, '[booking' ) ) { |
| 357 |
$is_sh_added = wpbc_add_shortcode_to_exist_page( $post_url, '[booking resource_id=1]' ); |
| 358 |
} |
| 359 |
|
| 360 |
} |
| 361 |
add_bk_action( 'wpbc_before_activation__add_options', 'wpbc_create_page_with_booking_form' ); |
| 362 |
|
| 363 |
// --------------------------------------------------------------------------------------------------------------------- |
| 364 |
|
| 365 |
|
| 366 |
/** |
| 367 |
* Create new page and get URL of this page |
| 368 |
* |
| 369 |
* @param $default_options_to_add |
| 370 |
* |
| 371 |
* @return void |
| 372 |
*/ |
| 373 |
function wpbc_create_page_thank_you( $default_options_to_add ) { // FixIn: 9.6.2.11. |
| 374 |
|
| 375 |
global $wp_rewrite; |
| 376 |
if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1. |
| 377 |
|
| 378 |
// Maybe it was not init, yet |
| 379 |
if ( ! has_action( 'init', 'wpbc_create_page_thank_you' ) ) { |
| 380 |
add_action( 'init', 'wpbc_create_page_thank_you', 99 ); // <- priority to load it last |
| 381 |
} |
| 382 |
return false; |
| 383 |
} |
| 384 |
|
| 385 |
// ----------------------------------------------------------------------------------------------------------------- |
| 386 |
|
| 387 |
$thank_you_page_url = get_bk_option( 'booking_thank_you_page_URL' ); |
| 388 |
|
| 389 |
if ( ( empty( $thank_you_page_url ) ) // If No 'Thank you' page in Settings, or it's set as Empty. |
| 390 |
|| ( |
| 391 |
( '/thank-you' == wpbc_make_link_relative( get_bk_option( 'booking_thank_you_page_URL' ) ) ) |
| 392 |
&& ( empty( get_page_by_path( 'thank-you' ) ) ) // FixIn: 9.9.0.27. |
| 393 |
) |
| 394 |
|| ( '/' == wpbc_make_link_relative( get_bk_option( 'booking_thank_you_page_URL' ) ) ) |
| 395 |
){ |
| 396 |
$wp_post = get_page_by_path( 'wpbc-booking-received' ); |
| 397 |
|
| 398 |
$post_url = ''; |
| 399 |
|
| 400 |
if ( empty( $wp_post ) ) { // No default page. Create it. |
| 401 |
|
| 402 |
$page_params = array( |
| 403 |
'post_title' => esc_html( __( 'Booking Received', 'booking' ) ), |
| 404 |
'post_content' => esc_html( __( 'Thank you for your booking. Your booking has been successfully received.', 'booking' ) ) |
| 405 |
. "\r\n" . ' [booking_confirm]', |
| 406 |
'post_name' => 'wpbc-booking-received' |
| 407 |
); |
| 408 |
$post_id = wpbc_create_page( $page_params ); |
| 409 |
|
| 410 |
if ( ! empty( $post_id ) ) { |
| 411 |
$post_url = wpbc_make_link_relative( get_permalink( $post_id ) ); |
| 412 |
} |
| 413 |
|
| 414 |
} else { |
| 415 |
$post_url = wpbc_make_link_relative( get_permalink( $wp_post->ID ) ); // Page already exist, so we need to update the |
| 416 |
} |
| 417 |
|
| 418 |
if ( ! empty( $post_url ) ) { |
| 419 |
update_bk_option( 'booking_thank_you_page_URL', $post_url ); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
// ----------------------------------------------------------------------------------------------------------------- |
| 424 |
|
| 425 |
// Check if existing page has our shortcode |
| 426 |
$relative_url = wpbc_make_link_relative( get_bk_option( 'booking_thank_you_page_URL' ) ); |
| 427 |
$is_sh_added = wpbc_add_shortcode_to_exist_page( $relative_url, '[booking_confirm]' ); |
| 428 |
|
| 429 |
} |
| 430 |
add_bk_action( 'wpbc_before_activation__add_options', 'wpbc_create_page_thank_you' ); |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
/** |
| 435 |
* Create pages for [bookingedit] and [bookingcustomerlisting] shortcodes, |
| 436 |
* |
| 437 |
* if previously was not defined options |
| 438 |
* 'booking_url_bookings_edit_by_visitors' and 'booking_url_bookings_listing_by_customer' |
| 439 |
* to some pages different from homepage. |
| 440 |
* |
| 441 |
* @return void |
| 442 |
*/ |
| 443 |
function wpbc_create_page_bookingedit(){ // FixIn: 9.6.2.10. |
| 444 |
|
| 445 |
global $wp_rewrite; |
| 446 |
if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1. |
| 447 |
// Maybe it was not init, yet |
| 448 |
if ( ! has_action( 'init', 'wpbc_create_page_bookingedit' ) ) { |
| 449 |
add_action( 'init', 'wpbc_create_page_bookingedit', 99 ); // <- priority to load it last |
| 450 |
} |
| 451 |
return false; |
| 452 |
} |
| 453 |
|
| 454 |
// Booking Edit page - set default page and URL --------------------------------------------------------------- |
| 455 |
$url_booking_edit = get_bk_option( 'booking_url_bookings_edit_by_visitors' ); |
| 456 |
if ( |
| 457 |
( site_url() == $url_booking_edit ) |
| 458 |
&& ( empty( get_page_by_path( 'wpbc-my-booking' ) ) ) |
| 459 |
){ |
| 460 |
$page_params = array( |
| 461 |
'post_content' => '[bookingedit]', // The post content |
| 462 |
'post_name' => 'wpbc-my-booking', // sanitize_title( $post_title ) |
| 463 |
'post_title' => esc_html__( 'My Booking', 'booking' ) // Title |
| 464 |
); |
| 465 |
|
| 466 |
$post_id = wpbc_create_page( $page_params ); |
| 467 |
|
| 468 |
if ( ! empty( $post_id ) ) { |
| 469 |
$post_url = get_permalink( $post_id ); |
| 470 |
update_bk_option( 'booking_url_bookings_edit_by_visitors', $post_url ); |
| 471 |
} |
| 472 |
} else if ( |
| 473 |
( |
| 474 |
( site_url() == $url_booking_edit ) |
| 475 |
|| ( empty( $url_booking_edit ) ) |
| 476 |
) |
| 477 |
&& ( ! empty( get_page_by_path( 'wpbc-my-booking' ) ) ) |
| 478 |
){ |
| 479 |
$wp_post = get_page_by_path( 'wpbc-my-booking' ); |
| 480 |
if ( ! empty( $wp_post ) ) { |
| 481 |
update_bk_option( 'booking_url_bookings_edit_by_visitors', get_permalink( $wp_post->ID ) ); |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
// ----------------------------------------------------------------------------------------------------------------- |
| 486 |
// Check if existing page has our shortcode |
| 487 |
// ----------------------------------------------------------------------------------------------------------------- |
| 488 |
$booking_edit_relative_url = wpbc_make_link_relative( get_bk_option( 'booking_url_bookings_edit_by_visitors' ) ); |
| 489 |
$is_added = wpbc_add_shortcode_to_exist_page( $booking_edit_relative_url, '[bookingedit]' ); |
| 490 |
|
| 491 |
|
| 492 |
// ================================================================================================================= |
| 493 |
// ================================================================================================================= |
| 494 |
// ================================================================================================================= |
| 495 |
|
| 496 |
|
| 497 |
// Booking Listing page - set default page and URL --------------------------------------------------------------- |
| 498 |
$url_booking_edit = get_bk_option( 'booking_url_bookings_listing_by_customer' ); |
| 499 |
if ( |
| 500 |
( site_url() == $url_booking_edit ) |
| 501 |
&& ( empty( get_page_by_path( 'wpbc-my-bookings-listing' ) ) ) |
| 502 |
){ |
| 503 |
|
| 504 |
$page_params = array( |
| 505 |
'post_content' => '[bookingcustomerlisting]', // The post content |
| 506 |
'post_name' => 'wpbc-my-bookings-listing', // sanitize_title( $post_title ) |
| 507 |
'post_title' => esc_html__( 'My Bookings Listing', 'booking' ) // Title |
| 508 |
); |
| 509 |
|
| 510 |
$post_id = wpbc_create_page( $page_params ); |
| 511 |
|
| 512 |
if ( ! empty( $post_id ) ) { |
| 513 |
$post_url = get_permalink( $post_id ); |
| 514 |
update_bk_option( 'booking_url_bookings_listing_by_customer', $post_url ); |
| 515 |
} |
| 516 |
} else if ( |
| 517 |
( |
| 518 |
( site_url() == $url_booking_edit ) |
| 519 |
|| ( empty( $url_booking_edit ) ) |
| 520 |
) |
| 521 |
&& ( ! empty( get_page_by_path( 'wpbc-my-bookings-listing' ) ) ) |
| 522 |
){ |
| 523 |
$wp_post = get_page_by_path( 'wpbc-my-bookings-listing' ); |
| 524 |
if ( ! empty( $wp_post ) ){ |
| 525 |
update_bk_option( 'booking_url_bookings_listing_by_customer', get_permalink( $wp_post->ID ) ); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
// ----------------------------------------------------------------------------------------------------------------- |
| 531 |
// Check if existing page has our shortcode |
| 532 |
// ----------------------------------------------------------------------------------------------------------------- |
| 533 |
$booking_listing_relative_url = wpbc_make_link_relative( get_bk_option( 'booking_url_bookings_listing_by_customer' ) ); |
| 534 |
$is_added = wpbc_add_shortcode_to_exist_page( $booking_listing_relative_url, '[bookingcustomerlisting]' ); |
| 535 |
|
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
function wpbc_create_page_booking_payment_status(){ // FixIn: 9.6.2.13. |
| 540 |
|
| 541 |
global $wp_rewrite; |
| 542 |
if ( is_null( $wp_rewrite ) ) { // FixIn: 9.7.1.1. |
| 543 |
return false; |
| 544 |
} |
| 545 |
|
| 546 |
// Successful Payment page options --------------------------------------------------------------------------------- |
| 547 |
|
| 548 |
$post_url_relative = false; |
| 549 |
$slug = 'wpbc-booking-payment-successful'; |
| 550 |
if ( empty( get_page_by_path( $slug ) ) ) { |
| 551 |
// Create page |
| 552 |
$page_params = array( |
| 553 |
'post_title' => esc_html( __( 'Booking Payment Confirmation', 'booking' ) ), |
| 554 |
'post_content' => esc_html( __( 'Thank you for your booking. Your payment for the booking has been successfully received.', 'booking' ) ), |
| 555 |
'post_name' => $slug |
| 556 |
); |
| 557 |
|
| 558 |
$post_id = wpbc_create_page( $page_params ); |
| 559 |
|
| 560 |
if ( ! empty( $post_id ) ) { |
| 561 |
$post_url = get_permalink( $post_id ); |
| 562 |
$post_url_relative = str_replace( site_url(), '', $post_url ); |
| 563 |
} |
| 564 |
} |
| 565 |
if ( ! empty( $post_url_relative ) ) { |
| 566 |
|
| 567 |
//$post_url_relative = wpbc_make_link_absolute( $post_url_relative ); |
| 568 |
|
| 569 |
$payment_systems = array( |
| 570 |
'booking_stripe_v3_order_successful', |
| 571 |
'booking_paypal_return_url', |
| 572 |
'booking_authorizenet_order_successful', |
| 573 |
'booking_sage_order_successful', |
| 574 |
'booking_ideal_return_url', |
| 575 |
'booking_ipay88_return_url' |
| 576 |
); |
| 577 |
|
| 578 |
foreach ( $payment_systems as $payment_system ) { |
| 579 |
|
| 580 |
if ( |
| 581 |
( false === get_bk_option( $payment_system ) ) |
| 582 |
|| ( '/successful' == wpbc_make_link_relative( get_bk_option( $payment_system ) ) ) |
| 583 |
) { |
| 584 |
update_bk_option( $payment_system, wpbc_make_link_relative( $post_url_relative ) ); |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
// Failed Payment page options ------------------------------------------------------------------------------------- |
| 590 |
|
| 591 |
$post_url_relative = false; |
| 592 |
$slug = 'wpbc-booking-payment-failed'; |
| 593 |
if ( empty( get_page_by_path( $slug ) ) ) { |
| 594 |
// Create page |
| 595 |
$page_params = array( |
| 596 |
'post_title' => esc_html( __( 'Booking Payment Failed', 'booking' ) ), |
| 597 |
'post_content' => esc_html( __( 'Payment Unsuccessful. Please contact us for assistance.', 'booking' ) ), |
| 598 |
'post_name' => $slug |
| 599 |
); |
| 600 |
|
| 601 |
$post_id = wpbc_create_page( $page_params ); |
| 602 |
|
| 603 |
if ( ! empty( $post_id ) ) { |
| 604 |
$post_url = get_permalink( $post_id ); |
| 605 |
$post_url_relative = str_replace( site_url(), '', $post_url ); |
| 606 |
} |
| 607 |
} |
| 608 |
if ( ! empty( $post_url_relative ) ) { |
| 609 |
|
| 610 |
//$post_url_relative = wpbc_make_link_absolute( $post_url_relative ); |
| 611 |
|
| 612 |
$payment_systems = array( |
| 613 |
'booking_stripe_v3_order_failed', |
| 614 |
'booking_paypal_cancel_return_url', |
| 615 |
'booking_authorizenet_order_failed', |
| 616 |
'booking_sage_order_failed', |
| 617 |
'booking_ideal_cancel_return_url', |
| 618 |
'booking_ipay88_cancel_return_url' |
| 619 |
); |
| 620 |
|
| 621 |
foreach ( $payment_systems as $payment_system ) { |
| 622 |
|
| 623 |
if ( |
| 624 |
( false === get_bk_option( $payment_system ) ) |
| 625 |
|| ( '/failed' == wpbc_make_link_relative( get_bk_option( $payment_system ) ) ) |
| 626 |
) { |
| 627 |
update_bk_option( $payment_system, wpbc_make_link_relative( $post_url_relative ) ); |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
} |