PluginProbe ʕ •ᴥ•ʔ
Author Website Templates – Create Writer, Author & Publisher Websites Easily / 1.1.9
Author Website Templates – Create Writer, Author & Publisher Websites Easily v1.1.9
trunk 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9
author-website-templates / includes / demo-setup / import-elementor-template.php
author-website-templates / includes / demo-setup Last commit date
demo-content 2 weeks ago author-portfolio-pro-thumb.png 2 weeks ago demo-setup-admin-notice.php 2 weeks ago demo-setup.js 2 weeks ago demo-setup.php 2 weeks ago handle-ajax-request.php 2 weeks ago import-books-from-json.php 2 weeks ago import-elementor-template.php 2 weeks ago import-posts-from-json.php 2 weeks ago install-activate-plugins.php 2 weeks ago
import-elementor-template.php
125 lines
1 <?php
2 function rswpthemes_awt_setup_demo_pages($demo_pages = []) {
3 if (!did_action('elementor/loaded')) {
4 return;
5 }
6
7 // Get the active theme name
8 $active_theme = wp_get_theme();
9 $is_author_portfolio = ($active_theme->get('Name') === 'Author Portfolio Pro');
10 $page_template = $is_author_portfolio ? 'blankpage.php' : 'elementor_canvas';
11
12 $imported_pages = [];
13 foreach ($demo_pages as $page_title => $template_path) {
14 // Corrected function to fetch the existing page properly
15 $existing_page = rswpthemes_awt_new_get_page_by_title($page_title);
16
17 if ($existing_page) {
18 $existing_page_id = $existing_page->ID;
19 $imported_pages[] = $existing_page->ID;
20 // Check if the existing page already has the same template data
21 $existing_elementor_data = get_post_meta($existing_page_id, '_elementor_data', true);
22
23 if ($existing_elementor_data && file_exists($template_path)) {
24 $json_data = file_get_contents($template_path);
25 $template_data = json_decode($json_data, true);
26
27 // Convert both to JSON for easy comparison
28 $new_template_data = wp_slash(json_encode($template_data['content']));
29
30 if ($existing_elementor_data === $new_template_data) {
31 continue; // Skip if template data is identical
32 }
33 }
34 } else {
35 // Insert new page only if it doesn't exist
36 $page_id = wp_insert_post([
37 'post_title' => $page_title,
38 'post_status' => 'publish',
39 'post_type' => 'page',
40 'post_content' => '',
41 'page_template' => $page_template,
42 ]);
43
44 if ($page_id && file_exists($template_path)) {
45 $json_data = file_get_contents($template_path);
46 $template_data = json_decode($json_data, true);
47
48 if (!empty($template_data['content'])) {
49 update_post_meta($page_id, '_elementor_data', wp_slash(json_encode($template_data['content'])));
50 update_post_meta($page_id, '_elementor_edit_mode', 'builder'); // Enable Elementor builder
51 }
52 }
53 if ($page_id) {
54 $imported_pages[] = $page_id;
55 }
56 }
57 }
58
59 // �
60 Insert "Books" page with Gutenberg blocks (No Elementor)
61 $books_page = rswpthemes_awt_new_get_page_by_title('Books');
62
63 if (!$books_page) {
64 $books_content = '<!-- wp:rswpbs/book-block /-->';
65 $books_page_id = wp_insert_post([
66 'post_title' => 'Books',
67 'post_status' => 'publish',
68 'post_type' => 'page',
69 'post_content' => $books_content, // Gutenberg content
70 'page_template' => 'blankpage.php', // No Elementor template
71 ]);
72
73 if ($books_page_id) {
74 $imported_pages[] = $books_page_id;
75 }
76 }
77
78 $home_page = rswpthemes_awt_new_get_page_by_title('Home'); // Get the first matching page
79 if ($home_page) {
80 update_option('page_on_front', $home_page->ID);
81 update_option('show_on_front', 'page');
82 }
83 // �
84 Call function to create and set menu
85 rswpthemes_awt_create_demo_menu($imported_pages);
86 }
87
88 /**
89 * Create Menu and Assign Imported Pages
90 */
91 function rswpthemes_awt_create_demo_menu($imported_pages) {
92 if (empty($imported_pages)) {
93 return;
94 }
95
96 $menu_name = 'Demo Menu';
97 $menu_exists = wp_get_nav_menu_object($menu_name);
98
99 // Create the menu if it doesn't exist
100 if (!$menu_exists) {
101 $menu_id = wp_create_nav_menu($menu_name);
102 } else {
103 $menu_id = $menu_exists->term_id;
104 }
105
106 // Assign pages to the menu
107 foreach ($imported_pages as $page_id) {
108 wp_update_nav_menu_item($menu_id, 0, [
109 'menu-item-object-id' => $page_id,
110 'menu-item-object' => 'page',
111 'menu-item-type' => 'post_type',
112 'menu-item-status' => 'publish',
113 ]);
114 }
115
116 // Assign the menu to the primary location (if the theme supports it)
117 $locations = get_theme_mod('nav_menu_locations');
118 if (!is_array($locations)) {
119 $locations = [];
120 }
121 $locations['main-menu'] = $menu_id; // Assign menu to 'primary' location
122 set_theme_mod('nav_menu_locations', $locations);
123 }
124
125