PluginProbe
Easy Hotel – Powerful Hotel Booking / trunk
Easy Hotel – Powerful Hotel Booking vtrunk
2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.9.9 1.9.8 1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 All 110 releases
easy-hotel / admin / includes / activation.php

activation.php in Easy Hotel – Powerful Hotel Booking trunk, at admin/includes/activation.php

39 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 function eshb_create_easy_hotel_pages() {
4
5 // Define pages and templates
6 $pages = [
7 'Easy Hotel Archive' => array('title' => 'Easy Hotel Archive', 'shortcode' => '[eshb_accomodation_grid]'),
8 'Easy Hotel Search' => array('title' => 'Easy Hotel Search', 'shortcode' => '[eshb_search_form]'),
9 'Easy Hotel Search Result' => array('title' => 'Easy Hotel Search Result', 'shortcode' => '[eshb_accomodation_search_result]'),
10 ];
11
12 foreach ($pages as $page_title => $page_data) {
13 // Check if the page already exists using WP_Query
14 $query = new WP_Query([
15 'post_type' => 'page',
16 'title' => $page_title,
17 'posts_per_page' => 1, // Only need one result
18 ]);
19
20 // If no page found, create it
21 if (!$query->have_posts()) {
22 // Create the page with the shortcode in the content
23 $page_id = wp_insert_post([
24 'post_title' => $page_data['title'],
25 'post_content' => $page_data['shortcode'], // Add shortcode as content
26 'post_status' => 'publish',
27 'post_type' => 'page',
28 ]);
29
30 // Check for errors in post creation
31 if (is_wp_error($page_id)) {
32 //error_log('Error creating page "' . $page_data['title'] . '": ' . $page_id->get_error_message());
33 } else {
34 // Assign the page template
35 update_post_meta($page_id, '_wp_page_template', $page_data['title']);
36 }
37 }
38 }
39 }