PluginProbe ʕ •ᴥ•ʔ
Flex Import / 1.9
Flex Import v1.9
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / includes / class-template-importer.php
flex-import / includes Last commit date
loader 11 months ago widgets 11 months ago class-template-importer.php 11 months ago flex-dashboard-post-api.php 11 months ago flex-get-api.php 11 months ago flex-get-templates-api.php 11 months ago fleximp-license-functions.php 11 months ago
class-template-importer.php
1410 lines
1 <?php
2 class FLEXIMP_Template_Importer
3 {
4
5 public $text_domain;
6 public function init()
7 {
8 $this->includes();
9
10 add_action('wp_ajax_fleximp_verify_license', array($this, 'fleximp_verify_license'));
11 add_action('wp_ajax_fleximp_deactivate_license', array($this, 'fleximp_deactivate_license'));
12 add_action('admin_menu', array($this, 'fleximp_add_admin_menu'));
13 add_action('admin_enqueue_scripts', array($this, 'fleximp_enqueue_admin_assets'));
14 add_action('wp_enqueue_scripts', array($this, 'fleximp_enqueue_frontend_assets'));
15 add_action('wp_ajax_fleximp_install_elementor', array($this, 'fleximp_install_elementor_ajax'));
16 add_action('wp_ajax_fleximp_import_demo_content', array($this, 'fleximp_import_demo_content'));
17 add_action('wp_ajax_fleximp_install_single_plugin', array($this, 'fleximp_install_single_plugin'));
18 add_action('wp_ajax_fleximp_get_required_plugins', array($this, 'fleximp_get_required_plugins'));
19 add_action('wp_ajax_fleximp_import_inner_pages_data', array($this, 'fleximp_import_inner_pages_data'));
20 add_action('admin_head', array($this, 'fleximp_hide_admin_notices'));//hide admin notice
21 add_action('wp_ajax_fleximp_install_plugin', array($this, 'fleximp_install_plugin'));
22 add_action('wp_ajax_fleximp_get_plugin_statuses', array($this, 'fleximp_get_plugin_statuses'));
23 add_action('wp_ajax_render_fleximp_dashboard_content', [$this, 'render_fleximp_dashboard_content']);
24 add_action('wp_ajax_fleximp_checked_install_plugin', [$this, 'fleximp_checked_install_plugin']);
25 add_action('wp_ajax_fleximp_set_text_domain', array($this, 'fleximp_set_text_domain'));
26
27 $is_premium_user = get_option('fleximp_is_premium', false);
28 $this->text_domain = get_option('fleximp_current_text_domain');
29
30 if ($is_premium_user && $this->text_domain === 'multipurpose-business-pro') {
31
32 add_action('init', array($this, 'register_service_cpt'));
33 add_action('init', array($this, 'register_service_category_taxonomy'));
34
35 add_action('init', [$this, 'register_project_cpt']);
36 add_action('init', [$this, 'register_project_category_taxonomy']);
37 $this->register_service_post_tabs_shortcode();
38
39 add_action('service_category_add_form_fields', array($this, 'add_service_category_image_field'));
40 add_action('service_category_edit_form_fields', array($this, 'edit_service_category_image_field'));
41 add_action('created_service_category', array($this, 'save_service_category_image'));
42 add_action('edited_service_category', array($this, 'save_service_category_image'));
43 add_action('after_setup_theme', array($this, 'fleximp_setup_primary_menu'));
44 // contact form
45 add_action('init', array($this, 'create_custom_cf7_forms'));
46
47
48 } elseif ($this->text_domain === 'flex-ecommerce-store-pro') {
49 add_action('init', [$this, 'setup_content_types']);
50 } else {
51 // add_action('init', array($this, 'create_custom_cf7_forms_new'));
52 }
53 // uninstall template
54 add_action('wp_ajax_fleximp_uninstall_template', [$this, 'fleximp_uninstall_template']);
55 add_action('elementor/widgets/register', [$this, 'register_elementor_widgets']);
56
57
58 }
59
60 public function setup_content_types()
61 {
62
63
64 if (empty($this->text_domain)) {
65 return;
66 }
67 $file_path = dirname(__DIR__) . '/templates-content/' . $this->text_domain . '.php';
68
69 if (file_exists($file_path)) {
70
71 include_once $file_path;
72 } else {
73 error_log("FLEXIMP: Content file not found for text domain: " . $this->text_domain);
74 }
75 }
76
77 // new for domain
78
79 public function fleximp_set_text_domain()
80 {
81 if (!current_user_can('manage_options')) {
82 wp_send_json_error('Unauthorized');
83 }
84
85 $text_domain = sanitize_text_field($_POST['text_domain'] ?? '');
86
87 if ($text_domain) {
88 update_option('fleximp_current_text_domain', $text_domain);
89 wp_send_json_success('Text domain saved');
90 } else {
91 wp_send_json_error('Text domain is empty');
92 }
93 }
94
95 private function includes()
96 {
97 require_once FLEXIMP_PLUGIN_FILE . 'includes/fleximp-license-functions.php';
98 }
99
100 // new
101
102 public function register_elementor_widgets($widgets_manager)
103 {
104 require_once plugin_dir_path(__FILE__) . 'widgets/class-service-category-widget.php';
105 $widgets_manager->register(new \Service_Category_Widget());
106
107 require_once plugin_dir_path(__FILE__) . 'widgets/class-category-products-widget.php';
108 $widgets_manager->register(new \Elementor_Category_Products_Widget());
109
110
111 }
112
113 // new add
114
115 public function fleximp_setup_primary_menu()
116 {
117 $menuname = 'Primary Menu';
118 $bpmenulocation = 'primary-menu';
119 $menu_exists = wp_get_nav_menu_object($menuname);
120
121 if (!$menu_exists) {
122 $menu_id = wp_create_nav_menu($menuname);
123
124 $base_url = home_url('/');
125
126 $menu_items = array(
127 array(
128 'title' => __('Home', 'flex-import'),
129 'url' => $base_url
130 ),
131 array(
132 'title' => __('About', 'flex-import'),
133 'url' => home_url('/index.php/about/')
134 ),
135 array(
136 'title' => __('Services', 'flex-import'),
137 'url' => home_url('/index.php/service/')
138 ),
139 array(
140 'title' => __('Pages', 'flex-import'),
141 'url' => home_url('/index.php/pages/')
142 ),
143 array(
144 'title' => __('Blogs', 'flex-import'),
145 'url' => home_url('/index.php/blog/')
146 )
147 );
148
149 foreach ($menu_items as $item) {
150 wp_update_nav_menu_item($menu_id, 0, array(
151 'menu-item-title' => $item['title'],
152 'menu-item-url' => $item['url'],
153 'menu-item-status' => 'publish',
154 'menu-item-type' => 'custom',
155 ));
156 }
157
158 if (!has_nav_menu($bpmenulocation)) {
159 $locations = get_theme_mod('nav_menu_locations');
160 if (!is_array($locations)) {
161 $locations = array();
162 }
163 $locations[$bpmenulocation] = $menu_id;
164 set_theme_mod('nav_menu_locations', $locations);
165 }
166 }
167
168 }
169
170 // end
171 public function add_service_category_image_field()
172 {
173 ?>
174 <div class="form-field term-group">
175 <label for="service_category_image"><?php esc_html_e('Image', 'flex-import'); ?></label>
176 <input type="hidden" id="service_category_image" name="service_category_image" class="custom_media_url" value="">
177 <div id="service_category_image_preview"></div>
178 <input type="button" class="button button-secondary custom_media_button" value="Upload Image">
179 </div>
180 <?php
181 }
182
183
184 // Add image field to Edit form
185 public function edit_service_category_image_field($term)
186 {
187 $image_id = get_term_meta($term->term_id, 'service_category_image', true);
188 $image_url = $image_id ? wp_get_attachment_url($image_id) : '';
189 ?>
190 <tr class="form-field term-group-wrap">
191 <th scope="row"><label for="service_category_image"><?php _esc_html_e('Image', 'flex-import'); ?></label></th>
192 <td>
193 <input type="hidden" id="service_category_image" name="service_category_image" class="custom_media_url"
194 value="<?php echo esc_attr($image_id); ?>">
195 <div id="service_category_image_preview">
196 <?php if ($image_url): ?>
197 <img src="<?php echo esc_url($image_url); ?>" style="max-width:100px;" />
198 <?php endif; ?>
199 </div>
200 <input type="button" class="button button-secondary custom_media_button" value="Upload Image">
201 </td>
202 </tr>
203 <?php $this->print_media_script(); ?>
204 <?php
205 }
206
207 // Save the image field value
208 public function save_service_category_image($term_id)
209 {
210 if (isset($_POST['service_category_image']) && $_POST['service_category_image'] !== '') {
211 update_term_meta($term_id, 'service_category_image', sanitize_text_field($_POST['service_category_image']));
212 } else {
213 delete_term_meta($term_id, 'service_category_image');
214 }
215 }
216 // end
217
218 // register post type
219 public function register_service_cpt()
220 {
221 $labels = array(
222 'name' => 'Services',
223 'singular_name' => 'Service',
224 'menu_name' => 'Services',
225 'name_admin_bar' => 'Service',
226 'add_new' => 'Add New',
227 'add_new_item' => 'Add New Service',
228 'new_item' => 'New Service',
229 'edit_item' => 'Edit Service',
230 'view_item' => 'View Service',
231 'all_items' => 'All Services',
232 'search_items' => 'Search Services',
233 'not_found' => 'No services found.',
234 'not_found_in_trash' => 'No services found in Trash.',
235 );
236
237 $args = array(
238 'labels' => $labels,
239 'public' => true,
240 'has_archive' => true,
241 'rewrite' => array('slug' => 'services'),
242 'show_in_rest' => true,
243 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
244 'menu_position' => 5,
245 'menu_icon' => 'dashicons-hammer',
246 );
247
248 register_post_type('service', $args);
249 }
250
251
252 // 2. Register Custom Taxonomy: Service Category
253 public function register_service_category_taxonomy()
254 {
255 $labels = array(
256 'name' => 'Service Categories',
257 'singular_name' => 'Service Category',
258 'search_items' => 'Search Service Categories',
259 'all_items' => 'All Service Categories',
260 'edit_item' => 'Edit Service Category',
261 'update_item' => 'Update Service Category',
262 'add_new_item' => 'Add New Service Category',
263 'new_item_name' => 'New Service Category Name',
264 'menu_name' => 'Service Categories',
265 );
266
267 $args = array(
268 'hierarchical' => true,
269 'labels' => $labels,
270 'show_ui' => true,
271 'show_admin_column' => true,
272 'rewrite' => array('slug' => 'service-category'),
273 'show_in_rest' => true,
274 );
275
276 register_taxonomy('service_category', array('service'), $args);
277 }
278
279
280 // new one for project postype
281 public function register_project_cpt()
282 {
283 $labels = array(
284 'name' => 'Projects',
285 'singular_name' => 'Project',
286 'menu_name' => 'Projects',
287 'name_admin_bar' => 'Project',
288 'add_new' => 'Add New',
289 'add_new_item' => 'Add New Project',
290 'new_item' => 'New Project',
291 'edit_item' => 'Edit Project',
292 'view_item' => 'View Project',
293 'all_items' => 'All Projects',
294 'search_items' => 'Search Projects',
295 'not_found' => 'No projects found.',
296 'not_found_in_trash' => 'No projects found in Trash.',
297 );
298
299 $args = array(
300 'labels' => $labels,
301 'public' => true,
302 'has_archive' => true,
303 'rewrite' => array('slug' => 'projects'),
304 'show_in_rest' => true,
305 'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
306 'menu_position' => 6,
307 'menu_icon' => 'dashicons-portfolio',
308 );
309
310 register_post_type('project', $args);
311 }
312
313
314
315 public function register_project_category_taxonomy()
316 {
317 $labels = array(
318 'name' => 'Project Categories',
319 'singular_name' => 'Project Category',
320 'search_items' => 'Search Project Categories',
321 'all_items' => 'All Project Categories',
322 'edit_item' => 'Edit Project Category',
323 'update_item' => 'Update Project Category',
324 'add_new_item' => 'Add New Project Category',
325 'new_item_name' => 'New Project Category Name',
326 'menu_name' => 'Project Categories',
327 );
328
329 $args = array(
330 'hierarchical' => true,
331 'labels' => $labels,
332 'show_ui' => true,
333 'show_admin_column' => true,
334 'rewrite' => array('slug' => 'project-category'),
335 'show_in_rest' => true,
336 );
337
338 register_taxonomy('project_category', array('project'), $args);
339 }
340 // end
341
342 // new add
343
344 public function create_custom_cf7_forms()
345 {
346 $is_premium_user = get_option('fleximp_is_premium', false);
347 if (!$is_premium_user) {
348 return;
349 }
350
351 $forms = array(
352 array(
353 'title' => 'Newsletter',
354 'content' => '<div class="flex-footer-form">
355 <div class="flex-business-theme-input"> [email* your-email class:email placeholder "Email"]</div>
356 <div class="flex-business-theme-input"> [submit class:flex-submit-btn1 "Submit Now"]</div>
357 </div>',
358 'hash' => 'b256161'
359 ),
360 array(
361 'title' => 'Contact Page Form',
362 'shortcode_title' => 'Contact form 1',
363 'content' => '<div class="row">
364 <div class="flex-business-input">
365 <div class="flex-business-theme-input">[text* text-111 class:name placeholder "Name"]</div>
366 <div class="flex-business-theme-input">[tel* tel-24 class:phone placeholder "Phone"]</div>
367 </div>
368 <div class="flex-business-input">
369 <div class="flex-business-theme-input">[email* email-398 class:email placeholder"Email"]</div>
370 <div class="flex-business-theme-input">[text text-159 class:service placeholder"services"]</div>
371 </div>
372 <div class="flex-business-msg">
373 <div class="flex-business-theme-input"> [text text-521 class:msg placeholder"Message"]</div>
374 </div>
375 <div class="flex-business-btn">
376 <div class="flex-business-theme-input"> [submit class:flex-submit-btn "Submit Now"]</div>
377 </div>
378 </div>',
379 'hash' => '80c5c1a'
380 ),
381 );
382
383 foreach ($forms as $form_data) {
384 $title = $form_data['title'];
385 $existing_form = get_page_by_title($title, OBJECT, 'wpcf7_contact_form');
386
387 if ($existing_form) {
388 continue;
389 }
390
391 $form_post = array(
392 'post_title' => wp_strip_all_tags($title),
393 'post_content' => $form_data['content'],
394 'post_status' => 'publish',
395 'post_type' => 'wpcf7_contact_form',
396 );
397
398 $form_id = wp_insert_post($form_post);
399
400 if (is_wp_error($form_id) || !$form_id) {
401 continue;
402 }
403
404 update_post_meta($form_id, '_form', $form_data['content']);
405
406 $mail_data = array(
407 'subject' => '[_site_title] "[your-subject]"',
408 'sender' => '[_site_title] <support@wpelemento.com>',
409 'body' => 'From: [your-name] <[your-email]>
410 Subject: [your-subject]
411
412 Message Body:
413 [your-message]
414
415 --
416 This e-mail was sent from a contact form on [_site_title] ([_site_url])',
417 'recipient' => '[_site_admin_email]',
418 'additional_headers' => 'Reply-To: [your-email]',
419 'attachments' => '',
420 'use_html' => 0,
421 'exclude_blank' => 0
422 );
423
424 update_post_meta($form_id, '_mail', $mail_data);
425 update_post_meta($form_id, '_hash', $form_data['hash']);
426
427 }
428 }
429
430 // end
431
432 //shortcode
433
434 public function register_service_post_tabs_shortcode()
435 {
436 add_shortcode('service_post_tabs', array($this, 'service_post_tabs_shortcode'));
437 }
438
439 public function service_post_tabs_shortcode()
440 {
441 $posts = get_posts([
442 'post_type' => 'service',
443 'posts_per_page' => -1,
444 'orderby' => 'menu_order',
445 'order' => 'ASC',
446 ]);
447
448 if (empty($posts)) {
449 return '<p>No services found.</p>';
450 }
451
452 ob_start();
453 ?>
454 <div class="service-tab-layout">
455 <ul class="service-post-tabs">
456 <?php foreach ($posts as $index => $post): ?>
457 <li class="tab <?php echo $index === 0 ? 'active' : ''; ?>" data-tab="post-<?php echo esc_attr($post->ID); ?>">
458 <?php echo esc_html(get_the_title($post)); ?>
459 </li>
460 <?php endforeach; ?>
461 </ul>
462
463 <div class="service-post-tab-contents">
464 <?php foreach ($posts as $index => $post): ?>
465 <div class="tab-content <?php echo $index === 0 ? 'active' : ''; ?>"
466 id="post-<?php echo esc_attr($post->ID); ?>">
467 <div class="flex-thumbnail-content">
468 <div class="tab-post-thumbnail">
469 <?php if (has_post_thumbnail($post)): ?>
470 <?php echo get_the_post_thumbnail($post); ?>
471 <?php endif; ?>
472 </div>
473 <div class="tab-post-details">
474 <h3 class="flex-tab-title"><?php echo esc_html(get_the_title($post)); ?></h3>
475 <div class="tab-post-content">
476 <?php echo wp_kses_post(apply_filters('the_content', $post->post_content)); ?>
477 </div>
478 <a class="explore-button" href="<?php echo esc_url(get_permalink($post)); ?>">Explore More</a>
479 </div>
480 </div>
481 </div>
482 <?php endforeach; ?>
483 </div>
484 </div>
485
486 <?php
487 return ob_get_clean();
488 }
489
490
491 // for frontend
492 public function fleximp_enqueue_frontend_assets()
493 {
494 if (!is_admin()) {
495 wp_enqueue_script('fleximp-service-tabs-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/front-script.js', array('jquery'), FLEXIMP_VER, true);
496
497
498 }
499 }
500 // end
501
502 public function fleximp_add_admin_menu()
503 {
504 add_menu_page(
505 'Elementor Template Importer',
506 'Flex Importer',
507 'manage_options',
508 'fleximp-template-importer',
509 array($this, 'fleximp_display_dashboard_page'),
510 'dashicons-download',
511 20
512 );
513
514 add_submenu_page(
515 'fleximp-template-importer',
516 'License Key',
517 'License Key',
518 'manage_options',
519 'fleximp-license-key',
520 array($this, 'fleximp_display_license_page')
521 );
522 }
523
524
525 // hide admin notice
526 public function fleximp_hide_admin_notices()
527 {
528 $screen = get_current_screen();
529 if ($screen->id === 'toplevel_page_fleximp-template-importer') {
530 remove_all_actions('admin_notices');
531 remove_all_actions('all_admin_notices');
532 }
533 }
534 //end
535
536 // for license key
537 function fleximp_display_license_page()
538 {
539 if (!current_user_can('manage_options')) {
540 wp_die(esc_html__('Sorry, you are not allowed to access this page.', 'flex-import'));
541 }
542 ?>
543 <!-- License key code start -->
544 <div class="license-key-wrap">
545 <form id="fleximp-license-key-form" action="<?php echo esc_url(admin_url('admin.php?page=')); ?>" method="POST">
546 <div class="license-key-input-wrap">
547 <label><?php esc_html_e('Enter Your Plugin License Key:', 'flex-import'); ?></label>
548 <div class="license-key-input">
549 <input type="text" name="fleximp_is_premium" required placeholder="License Key"
550 value="<?php echo esc_attr(get_fleximp_key()); ?>" />
551 </div>
552 <button class="button" name="key-activation" value="<?php esc_html_e('Activate', 'flex-import'); ?>"
553 type="submit">Activate</button>
554 <button class="button deactivate-domain" value="<?php esc_html_e('Deactivate', 'flex-import'); ?>"
555 type="button">Deactivate</button>
556 <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?>
557 <br><small id="license">License Key Activated Successfully</small>
558 <?php } ?>
559 </div>
560 </form>
561 </div>
562
563 <!-- Server Info Section -->
564 <div class="fleximp-server-info" style="margin-top: 30px; padding: 15px; background: #f9f9f9; border: 1px solid #ddd;">
565 <h3><?php esc_html_e('Recommended Server Settings for Importing Demo Content', 'flex-import'); ?></h3>
566 <ul>
567 <li><strong>PHP Time Limit:</strong> <?php echo esc_html(ini_get('max_execution_time')); ?> (Recommended:
568 5000)</li>
569 <li><strong>PHP Memory Limit:</strong> <?php echo esc_html(ini_get('memory_limit')); ?> (Recommended: 9512M or
570 more)</li>
571 <li><strong>Max Input Vars:</strong> <?php echo esc_html(ini_get('max_input_vars')); ?> (Recommended: 6000)
572 </li>
573 <li><strong>Max Upload Size:</strong> <?php echo esc_html(size_format(wp_max_upload_size())); ?>
574 (Recommended: 200MB or more)</li>
575 </ul>
576 <p style="color: #d63638;"><strong>Note:</strong>
577 <?php esc_html_e('Contact your hosting provider to increase these values if needed for successful demo content import.', 'flex-import'); ?>
578 </p>
579 </div>
580
581 <?php // } ?>
582
583 <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?>
584 <div class="fleximp-elems-next" style="display:none;">
585
586 </div>
587 <?php } ?>
588 <?php
589
590 }
591 // end
592
593
594 //for deactivate license key
595 public function fleximp_deactivate_license()
596 {
597 // Clear the license key and update the status
598 delete_option('fleximp_plugin_license_key');
599 delete_option('fleximp_plugin_license_validation_status');
600 wp_send_json_success(['message' => 'License deactivated successfully.']);
601 }
602 //end
603
604 //new add handler from home
605 function fleximp_install_plugin_handler()
606 {
607 check_ajax_referer('fleximp_quick_setup_nonce', 'security');
608
609 if (!current_user_can('install_plugins')) {
610 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
611 }
612
613 $template = sanitize_text_field($_POST['template']);
614 $plugins = $_POST['plugins']; // Array of plugins
615
616 if (empty($template) || empty($plugins)) {
617 wp_send_json_error(['message' => 'Template or plugins data missing.']);
618 }
619
620 wp_send_json_success(['message' => 'Plugins installed successfully.']);
621 }
622 //end
623
624
625 //new for checking plugin status'
626 public function fleximp_get_plugin_statuses()
627 {
628
629 check_ajax_referer('fleximp_quick_setup_nonce', 'security');
630
631 if (!current_user_can('manage_options')) {
632 wp_send_json_error(['message' => 'Unauthorized'], 403);
633 return;
634 }
635
636 // Decode plugins array
637 $plugins = isset($_POST['plugins']) ? json_decode(stripslashes($_POST['plugins']), true) : [];
638
639 if (empty($plugins)) {
640 wp_send_json_error(['message' => 'No plugins provided'], 400);
641 return;
642 }
643
644 // Retrieve statuses
645 $installed_plugins = get_plugins();
646 $active_plugins = get_option('active_plugins', []);
647 $response = [];
648
649 foreach ($plugins as $plugin) {
650 $slug = $plugin['slug'] ?? '';
651 $main_file = $plugin['main_file'] ?? '';
652
653 if (!$slug || !$main_file)
654 continue;
655
656 $plugin_path = "{$slug}/{$main_file}";
657 $response[$slug] = in_array($plugin_path, $active_plugins) ? 'Activated' : (isset($installed_plugins[$plugin_path]) ? 'Installed' : 'Not Installed');
658 }
659
660 // Send the response
661 wp_send_json_success($response);
662 }
663 //end
664
665 //new add from old flex
666 public function fleximp_import_inner_pages_data()
667 {
668 // check_ajax_referer('fleximp_import_pages_nonce', 'nonce');
669
670 if (!current_user_can('manage_options')) {
671 wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import'));
672 }
673
674 $content_path = isset($_POST['content_path']) ? sanitize_text_field($_POST['content_path']) : '';
675 $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : '';
676 $template_css = isset($_POST['template_css']) ? esc_url_raw($_POST['template_css']) : '';
677 $template_js = isset($_POST['template_js']) ? esc_url_raw($_POST['template_js']) : '';
678
679 // redirect by taking css
680 if (!empty($template_css)) {
681 $this->fleximp_handle_template_css_redirect($template_css);
682 }
683
684 // redirect by taking js
685 if (!empty($template_js)) {
686 $this->fleximp_handle_template_js_redirect($template_js);
687 }
688
689 if (empty($content_path)) {
690 wp_send_json_error(__('Content path is missing or invalid.', 'flex-import'));
691 }
692 $response = wp_remote_get($content_path);
693
694 if (is_wp_error($response)) {
695 wp_send_json_error(__('Error fetching demo content from the server.', 'flex-import'));
696 }
697
698 $content = wp_remote_retrieve_body($response);
699
700 //for image
701 $content = str_replace(
702 'http://example.com/assets/images/',
703 FLEXIMP_MAIN_URL . 'demo-content/' . $text_domain . '/assets/images/',
704 $content
705 );
706
707 if (!function_exists('WP_Filesystem')) {
708 require_once ABSPATH . 'wp-admin/includes/file.php';
709 }
710
711 global $wp_filesystem;
712 WP_Filesystem();
713
714 $upload_dir = wp_upload_dir();
715 $temp_file = $upload_dir['basedir'] . '/temp-content-import.php';
716
717 if (!$wp_filesystem->put_contents($temp_file, $content, FS_CHMOD_FILE)) {
718 wp_send_json_error(__('Failed to save temporary file for demo content.', 'flex-import'));
719 }
720
721 try {
722 include $temp_file;
723 } catch (Exception $e) {
724 wp_send_json_error(__('Error executing demo content.', 'flex-import'));
725 }
726
727 wp_delete_file($temp_file);
728
729 wp_send_json_success(__('Demo content imported successfully!', 'flex-import'));
730 wp_die();
731 }
732 //end
733
734 // dynamic js enqueue
735 public function fleximp_handle_template_js_redirect($template_js = '')
736 {
737 if (!empty($template_js)) {
738 update_option('fleximp_dynamic_template_js', esc_url_raw($template_js));
739 }
740 }
741 //end
742
743 // dynamic css enqueue
744 public function fleximp_handle_template_css_redirect($template_css = '')
745 {
746 if (!empty($template_css)) {
747 update_option('fleximp_dynamic_template_css', esc_url_raw($template_css));
748 }
749 }
750 //end
751
752 // Get required plugins
753 public function fleximp_get_required_plugins()
754 {
755 if (!current_user_can('install_plugins')) {
756 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
757 }
758
759 // Initialize WP_Filesystem API
760 global $wp_filesystem;
761 if (empty($wp_filesystem)) {
762 require_once(ABSPATH . 'wp-admin/includes/file.php');
763 WP_Filesystem();
764 }
765
766 $plugins_file = get_template_directory() . '/inc/plugins.json';
767
768 if ($wp_filesystem->exists($plugins_file)) {
769 $plugins_json = $wp_filesystem->get_contents($plugins_file);
770
771
772 if (empty($plugins_json)) {
773 wp_send_json_error(['message' => 'Plugins configuration file is empty.']);
774 }
775
776 $plugins = json_decode($plugins_json, true);
777
778 if (json_last_error() !== JSON_ERROR_NONE) {
779 wp_send_json_error(['message' => 'Invalid JSON format in plugins configuration file.']);
780 }
781
782 foreach ($plugins as $key => $plugin) {
783 $main_file = !empty($plugin['main_file']) ? $plugin['main_file'] : $plugin['slug'] . '.php';
784 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin['slug'] . '/' . $main_file;
785
786 // Check if the plugin is installed and active
787 $plugins[$key]['status'] = file_exists($plugin_file) && is_plugin_active($plugin_file) ? 'installed' : 'required';
788 }
789
790 wp_send_json_success($plugins);
791 } else {
792 wp_send_json_error(['message' => 'Plugins configuration file not found.']);
793 }
794 }
795
796
797 // from templates tab plugins
798 public function fleximp_checked_install_plugin()
799 {
800 // check_ajax_referer('fleximp_quick_setup_nonce', 'security');
801
802 if (!current_user_can('install_plugins')) {
803 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
804 }
805
806 global $wp_filesystem;
807 if (empty($wp_filesystem)) {
808 require_once ABSPATH . 'wp-admin/includes/file.php';
809 WP_Filesystem();
810 }
811
812 $plugin_slug = sanitize_text_field($_POST['plugin_slug']);
813 $plugin_name = sanitize_text_field($_POST['plugin_name']);
814 $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']);
815
816 if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) {
817 wp_send_json_error(['message' => 'Plugin details are missing.']);
818 }
819
820 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file;
821
822 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
823 $upgrader = new Plugin_Upgrader();
824
825 // Install the plugin if it's not already installed
826 if (!file_exists($plugin_file)) {
827 $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip';
828 $install_result = $upgrader->install($plugin_url);
829
830 if (is_wp_error($install_result)) {
831 wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]);
832 }
833
834 if (file_exists($plugin_file)) {
835 // Activate the plugin
836 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
837 if (is_wp_error($activation)) {
838 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
839 }
840 wp_send_json_success(['message' => 'Plugin installed and activated successfully.']);
841 } else {
842 wp_send_json_error(['message' => 'Plugin installation failed.']);
843 }
844 } else {
845 // Activate if already installed but not active
846 if (!is_plugin_active($plugin_file)) {
847 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
848 if (is_wp_error($activation)) {
849 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
850 }
851 }
852 wp_send_json_success(['message' => 'Plugin is already installed and activated.']);
853 }
854 }
855 // end
856
857 //more new one
858 public function fleximp_install_plugin()
859 {
860 // check_ajax_referer('fleximp_quick_setup_nonce', 'security');
861
862 if (!current_user_can('install_plugins')) {
863 wp_send_json_error(['message' => 'You do not have permission to install plugins.']);
864 }
865
866 global $wp_filesystem;
867 if (empty($wp_filesystem)) {
868 require_once ABSPATH . 'wp-admin/includes/file.php';
869 WP_Filesystem();
870 }
871
872 $plugin_slug = sanitize_text_field($_POST['plugin_slug']);
873 $plugin_name = sanitize_text_field($_POST['plugin_name']);
874 $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']);
875
876 if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) {
877 wp_send_json_error(['message' => 'Plugin details are missing.']);
878 }
879
880 $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file;
881
882 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
883 $upgrader = new Plugin_Upgrader();
884
885 // Install the plugin if it's not already installed
886 if (!file_exists($plugin_file)) {
887 $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip';
888 $install_result = $upgrader->install($plugin_url);
889
890 if (is_wp_error($install_result)) {
891 wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]);
892 }
893
894 if (file_exists($plugin_file)) {
895 // Activate the plugin
896 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
897 if (is_wp_error($activation)) {
898 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
899 }
900 wp_send_json_success(['message' => 'Plugin installed and activated successfully.']);
901 } else {
902 wp_send_json_error(['message' => 'Plugin installation failed.']);
903 }
904 } else {
905 // Activate if already installed but not active
906 if (!is_plugin_active($plugin_file)) {
907 $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file);
908 if (is_wp_error($activation)) {
909 wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]);
910 }
911 }
912 wp_send_json_success(['message' => 'Plugin is already installed and activated.']);
913 }
914 }
915
916
917 //changes start from here for dashboard
918 public function fleximp_display_dashboard_page()
919 { ?>
920 <div class="container-fluid flex-imp-nav-box" style="margin-top:30px;">
921 <div class="row w-100">
922 <div class="col-xl-2 col-sm-2 col-4">
923 <div class="flex-dash-plugin-logo ">
924 <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/flex-logo.svg'); ?>"
925 alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" class="logo-img">
926 </div>
927 </div>
928
929 <div class="col-xl-10 col-sm-10 col-8 flex-container-1">
930 <div class="row">
931 <div class="col-lg-12 col-xl-8 align-self-center">
932 <div>
933 <ul class="nav nav-tabs mr-auto flex-nav-tab-links" role="tablist">
934 <li class="nav-item flex-icons ">
935 <!-- <a class="nav-link active" data-toggle="tab" href="#dashboard"> -->
936 <a class="nav-link" data-toggle="tab" href="#dashboard">
937
938
939 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
940 <path
941 d="M543.8 287.6c17 0 32-14 32-32.1c1-9-3-17-11-24L512 185l0-121c0-17.7-14.3-32-32-32l-32 0c-17.7 0-32 14.3-32 32l0 36.7L309.5 7c-6-5-14-7-21-7s-15 1-22 8L10 231.5c-7 7-10 15-10 24c0 18 14 32.1 32 32.1l32 0 0 69.7c-.1 .9-.1 1.8-.1 2.8l0 112c0 22.1 17.9 40 40 40l16 0c1.2 0 2.4-.1 3.6-.2c1.5 .1 3 .2 4.5 .2l31.9 0 24 0c22.1 0 40-17.9 40-40l0-24 0-64c0-17.7 14.3-32 32-32l64 0c17.7 0 32 14.3 32 32l0 64 0 24c0 22.1 17.9 40 40 40l24 0 32.5 0c1.4 0 2.8 0 4.2-.1c1.1 .1 2.2 .1 3.3 .1l16 0c22.1 0 40-17.9 40-40l0-16.2c.3-2.6 .5-5.3 .5-8.1l-.7-160.2 32 0z" />
942 </svg>
943 <?php esc_html_e('Dashboard', 'flex-import'); ?>
944 </a>
945 </li>
946 <li class="nav-item flex-icons ">
947 <!-- <a class="nav-link" data-toggle="tab" href="#templates"> -->
948 <a class="nav-link active" data-toggle="tab" href="#templates">
949 <svg id="Group_65" data-name="Group 65" xmlns="http://www.w3.org/2000/svg"
950 width="18.571" height="20" viewBox="0 0 18.571 20">
951 <path id="Path_46" data-name="Path 46"
952 d="M51.182,49.415h10.96v-.354A1.061,1.061,0,0,0,61.081,48H49.061A1.061,1.061,0,0,0,48,49.062V62.509a1.061,1.061,0,0,0,1.061,1.062h.354V51.185A1.771,1.771,0,0,1,51.182,49.415Zm0,0"
953 transform="translate(-45.785 -45.785)" />
954 <path id="Path_47" data-name="Path 47"
955 d="M110.766,160H96v12.182a1.108,1.108,0,0,0,1.107,1.107h12.551a1.108,1.108,0,0,0,1.107-1.107Zm0,0"
956 transform="translate(-92.195 -153.29)" />
957 <path id="Path_48" data-name="Path 48"
958 d="M3.322,1.477H14.766V1.107A1.108,1.108,0,0,0,13.659,0H1.107A1.108,1.108,0,0,0,0,1.107V15.135a1.108,1.108,0,0,0,1.107,1.107h.369V3.322A1.848,1.848,0,0,1,3.322,1.477Zm0,0" />
959 <path id="Path_49" data-name="Path 49"
960 d="M110.766,97.107A1.108,1.108,0,0,0,109.659,96H97.107A1.108,1.108,0,0,0,96,97.107v1.107h14.766Zm-13.319.14a.429.429,0,0,1-.078.122.365.365,0,0,1-.4.078.381.381,0,0,1-.122-.078.429.429,0,0,1-.078-.122.348.348,0,0,1,0-.28.381.381,0,0,1,.078-.122.386.386,0,0,1,.524,0,.381.381,0,0,1,.078.122A.347.347,0,0,1,97.447,97.248Zm1.107,0a.43.43,0,0,1-.078.122.365.365,0,0,1-.4.078.333.333,0,0,1-.2-.2.309.309,0,0,1-.03-.14.368.368,0,0,1,.03-.14.381.381,0,0,1,.078-.122.386.386,0,0,1,.524,0,.381.381,0,0,1,.078.122A.347.347,0,0,1,98.555,97.248Zm1.03.122a.369.369,0,0,1-.631-.262.309.309,0,0,1,.03-.14.381.381,0,0,1,.078-.122.386.386,0,0,1,.524,0,.381.381,0,0,1,.078.122A.365.365,0,0,1,99.584,97.37Zm0,0"
961 transform="translate(-92.195 -91.732)" />
962 </svg>
963
964
965 <?php esc_html_e('Templates', 'flex-import'); ?>
966 </a>
967 </li>
968 <li class="nav-item flex-icons">
969 <a class="nav-link" data-toggle="tab" href="#plugins">
970 <svg id="Group_66" data-name="Group 66" xmlns="http://www.w3.org/2000/svg"
971 width="20" height="20" viewBox="0 0 20 20">
972 <g id="extension">
973 <path id="Path_50" data-name="Path 50"
974 d="M17.619,9.524H16.19V5.714a1.91,1.91,0,0,0-1.9-1.9h-3.81V2.381a2.381,2.381,0,1,0-4.762,0V3.81H1.9A1.91,1.91,0,0,0,0,5.714V9.333H1.429a2.571,2.571,0,0,1,0,5.143H0V18.1A1.91,1.91,0,0,0,1.9,20H5.524V18.571a2.571,2.571,0,0,1,5.143,0V20h3.619a1.91,1.91,0,0,0,1.9-1.9v-3.81h1.429a2.381,2.381,0,1,0,0-4.762Z" />
975 </g>
976 </svg>
977 <?php esc_html_e('Plugins', 'flex-import'); ?>
978 </a>
979 </li>
980 <li class="nav-item flex-icons">
981 <a class="nav-link" data-toggle="tab" href="#widgets">
982 <svg xmlns="http://www.w3.org/2000/svg" width="20.504" height="20.508"
983 viewBox="0 0 20.504 20.508">
984 <g id="Group_72" data-name="Group 72" transform="translate(-1121.166 -308.672)">
985 <g id="Group_71" data-name="Group 71"
986 transform="translate(1121.166 308.672)">
987 <g id="Icon" transform="translate(0 0)">
988 <g id="Group_67" data-name="Group 67"
989 transform="translate(0 0.004)">
990 <path id="Path_51" data-name="Path 51"
991 d="M9.949,47.368a1.9,1.9,0,0,0-1.9-1.9H2.336a1.9,1.9,0,0,0-1.9,1.9v5.709a1.9,1.9,0,0,0,1.9,1.9H8.046a1.9,1.9,0,0,0,1.9-1.9Z"
992 transform="translate(-0.433 -45.465)" fill=""
993 fill-rule="evenodd" />
994 </g>
995 <g id="Group_68" data-name="Group 68"
996 transform="translate(0 10.992)">
997 <path id="Path_52" data-name="Path 52"
998 d="M9.949,47.368a1.9,1.9,0,0,0-1.9-1.9H2.336a1.9,1.9,0,0,0-1.9,1.9v5.709a1.9,1.9,0,0,0,1.9,1.9H8.046a1.9,1.9,0,0,0,1.9-1.9Z"
999 transform="translate(-0.433 -45.465)" fill=""
1000 fill-rule="evenodd" />
1001 </g>
1002 <g id="Group_69" data-name="Group 69"
1003 transform="translate(10.988 10.992)">
1004 <path id="Path_53" data-name="Path 53"
1005 d="M9.949,47.368a1.9,1.9,0,0,0-1.9-1.9H2.336a1.9,1.9,0,0,0-1.9,1.9v5.709a1.9,1.9,0,0,0,1.9,1.9H8.046a1.9,1.9,0,0,0,1.9-1.9Z"
1006 transform="translate(-0.433 -45.465)" fill=""
1007 fill-rule="evenodd" />
1008 </g>
1009 <g id="Group_70" data-name="Group 70"
1010 transform="translate(10.984 0)">
1011 <path id="Path_54" data-name="Path 54"
1012 d="M18.718,91.171a1.889,1.889,0,0,0-2.669,0l-2.872,2.872a1.887,1.887,0,0,0,0,2.669l2.872,2.872a1.887,1.887,0,0,0,2.669,0l2.872-2.872a1.887,1.887,0,0,0,0-2.669l-2.872-2.872Z"
1013 transform="translate(-12.624 -90.619)" fill=""
1014 fill-rule="evenodd" />
1015 </g>
1016 </g>
1017 </g>
1018 </g>
1019 </svg>
1020 <?php esc_html_e('Widgets', 'flex-import'); ?>
1021 </a>
1022 </li>
1023 </ul>
1024 </div>
1025 </div>
1026 <div class="col-lg-12 col-xl-4 text-right flex-demo-btns mt-xl-0 mt-3">
1027 <div class="ml-auto flex-demo-buttons">
1028 <a href="https://www.flextheme.net/products/flex-pro-wordpress-theme"
1029 class="btn flex-demo-btn flex-btn-space" target="_blank" rel="noopener">
1030 <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png'); ?>"
1031 alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" style="">
1032 <?php esc_html_e('Get Pro', 'flex-import'); ?>
1033 </a>
1034 </div>
1035 </div>
1036 </div>
1037 </div>
1038 </div>
1039 </div>
1040 <!-- Tab Content -->
1041 <div class="tab-content mt-3">
1042 <!-- <div id="dashboard" class="tab-pane fade"> -->
1043 <div id="dashboard" class="tab-pane fade">
1044 <?php include FLEXIMP_PLUGIN_FILE . '/templates/dashboard-content.php'; ?>
1045 </div>
1046 <!-- <div id="templates" class="tab-pane fade fleximp-template-main-box"> -->
1047 <div id="templates" class="tab-pane fade show active fleximp-template-main-box">
1048 <?php include FLEXIMP_PLUGIN_FILE . '/templates/templates-content.php'; ?>
1049 </div>
1050 <div id="plugins" class="tab-pane fade fleximp-plugin-main-box">
1051 <?php include FLEXIMP_PLUGIN_FILE . '/templates/plugins-content.php'; ?>
1052 </div>
1053 <div id="widgets" class="tab-pane fade fleximp-widgets-main-box">
1054 <?php include FLEXIMP_PLUGIN_FILE . '/templates/widgets-content.php'; ?>
1055 </div>
1056 </div>
1057 <?php }
1058
1059 //changes end from here for bootstrap
1060 public function fleximp_enqueue_admin_assets()
1061 {
1062 $screen = get_current_screen();
1063 if ($screen->id === 'toplevel_page_fleximp-template-importer') {
1064 wp_enqueue_style('fleximp-admin-styles', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/admin-style.css', array(), FLEXIMP_VER);
1065
1066 // Enqueue Bootstrap CSS and JS
1067 wp_enqueue_style('bootstrap-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.css', [], FLEXIMP_VER);
1068 wp_enqueue_script('bootstrap-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.js', ['jquery'], FLEXIMP_VER, true);
1069 wp_enqueue_script('flex-swiper-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/swiper-bundle.min.js', ['jquery'], FLEXIMP_VER, true);
1070 wp_enqueue_script('fleximp-admin-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/admin-script.js', array('jquery'), FLEXIMP_VER, true);
1071 wp_enqueue_style('font-awesome', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/all.min.css', [], FLEXIMP_VER);
1072
1073 $is_premium_theme = defined('GET_PREMIUM_THEME');
1074
1075 wp_localize_script('fleximp-admin-scripts', 'fleximp_admin_ajax_object', array(
1076 'ajax_url' => admin_url('admin-ajax.php'),
1077 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'),
1078 'plugin_url' => plugins_url('', __FILE__),
1079 'is_premium_theme' => $is_premium_theme
1080 ));
1081
1082 //for plugin
1083 wp_enqueue_script(
1084 'fleximp-plugin-js',
1085 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/plugin-admin.js',
1086 array('jquery'),
1087 FLEXIMP_VER,
1088 true
1089 );
1090
1091 wp_localize_script('fleximp-plugin-js', 'fleximp_ajax_object', array(
1092 'ajax_url' => admin_url('admin-ajax.php'),
1093 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'),
1094 'plugin_url' => plugins_url('', __FILE__),
1095 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-api.php',
1096 ));
1097 //end
1098
1099 //for templates
1100 wp_enqueue_script(
1101 'fleximp-template-js',
1102 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/template-admin.js',
1103 array('jquery'),
1104 FLEXIMP_VER,
1105 true
1106 );
1107
1108 $is_elementor_active = is_plugin_active('elementor/elementor.php');
1109
1110 wp_localize_script('fleximp-template-js', 'fleximp_template_ajax_object', array(
1111 'ajax_url' => admin_url('admin-ajax.php'),
1112 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'),
1113 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-templates-api.php',
1114 'isPremiumUser' => get_option('fleximp_is_premium', false),
1115 'imported_template' => get_option('flex_template_is_imported', ''),
1116 'pro_image_url' => FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png',
1117 'fleximp_current_text_domain' => get_option('fleximp_current_text_domain'),
1118 'isElementorActive' => $is_elementor_active ? '1' : '0',
1119 ));
1120 //end
1121
1122 //for dashboard
1123 wp_enqueue_script(
1124 'fleximp-dashposts-js',
1125 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/dashboard-posts.js',
1126 array('jquery'),
1127 FLEXIMP_VER,
1128 true
1129 );
1130
1131 wp_localize_script('fleximp-dashposts-js', 'fleximp_dashposts_ajax_object', array(
1132 'ajax_url' => admin_url('admin-ajax.php'),
1133 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'),
1134 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-dashboard-post-api.php',
1135 ));
1136 }
1137 }
1138
1139 //for license key
1140
1141 public function fleximp_verify_license()
1142 {
1143 $license_key = sanitize_text_field($_POST['fleximp_license_key']);
1144 $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'verifyTheme';
1145
1146 $body = json_encode([
1147 'theme_license_key' => $license_key,
1148 'site_url' => site_url(),
1149 'theme_text_domain' => wp_get_theme()->get('TextDomain'),
1150 ]);
1151
1152 $response = wp_remote_post($endpoint, [
1153 'body' => $body,
1154 'headers' => ['Content-Type' => 'application/json']
1155 ]);
1156
1157 if (is_wp_error($response)) {
1158 wp_send_json_error(['message' => 'Connection error.']);
1159 return;
1160 }
1161
1162 $response_body = json_decode(wp_remote_retrieve_body($response), true);
1163
1164 if (isset($response_body['is_suspended']) && $response_body['is_suspended'] == 1) {
1165 wp_send_json_error(['message' => 'License is suspended.']);
1166 return;
1167 }
1168
1169 if (isset($response_body['status']) && $response_body['status'] === true) {
1170 update_option('fleximp_plugin_license_key', $license_key);
1171 update_option('fleximp_plugin_license_validation_status', 'true');
1172 wp_send_json_success(['message' => 'License activated successfully!']);
1173 } else {
1174 $error_message = isset($response_body['message']) ? $response_body['message'] : 'License activation failed. Please try again.';
1175 wp_send_json_error(['message' => $error_message]);
1176 }
1177 }
1178 //end
1179
1180 public function fleximp_import_demo_content()
1181 {
1182
1183 if (!current_user_can('manage_options')) {
1184 wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import'));
1185 }
1186
1187 if (!is_plugin_active('elementor/elementor.php')) {
1188 wp_send_json_error(__('Elementor must be installed and activated before importing demo content.', 'flex-import'));
1189 }
1190
1191 $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : 'flex-import';
1192
1193 $import_success = $this->fleximp_elementor_importer_setup_pages();
1194
1195 if ($import_success) {
1196 update_option('flex_template_is_imported', $text_domain);
1197 wp_send_json_success(__('imported successfully!', 'flex-import'));
1198 } else {
1199 wp_send_json_error(__('Error occurred during the import process.', 'flex-import'));
1200 }
1201
1202 wp_die();
1203 }
1204
1205 //new add for import pages from old flex
1206 public function fleximp_elementor_importer_setup_pages()
1207 {
1208 $active_theme = wp_get_theme();
1209 $active_theme_textdomain = $active_theme->get('TextDomain');
1210
1211 $pages_arr = [];
1212 $imported_pages = 0;
1213
1214 $fallback_json_url = isset($_POST['json_path']) ? sanitize_text_field($_POST['json_path']) : FLEXIMP_MAIN_URL . '/themes-json/multipurpose-business/multipurpose-business.json';
1215 $fallback_content = $this->fetch_remote_content($fallback_json_url);
1216
1217 if ($fallback_content) {
1218 $fallback_data = json_decode($fallback_content, true);
1219 if ($fallback_data) {
1220 foreach ($fallback_data as $page) {
1221 $pages_arr[] = [
1222 'title' => $page['name'],
1223 'ishome' => ($page['type'] === 'home') ? 1 : 0,
1224 'post_type' => $page['posttype'],
1225 'source' => $page['source'],
1226 'type' => $page['type']
1227 ];
1228 }
1229 }
1230 }
1231
1232 foreach ($pages_arr as $page) {
1233 $page_content_response = wp_remote_get($page['source']);
1234
1235 if (is_wp_error($page_content_response) || wp_remote_retrieve_response_code($page_content_response) !== 200) {
1236 continue;
1237 }
1238
1239 $page_content_arr = isset($page['content']) ? ['content' => $page['content']] : json_decode(wp_remote_retrieve_body($page_content_response), true);
1240
1241 if ($page_content_arr === null || !isset($page_content_arr['content'])) {
1242 continue;
1243 }
1244
1245 $post_data = [
1246 'post_title' => $page['title'],
1247 'post_type' => $page['post_type'],
1248 'post_status' => 'publish',
1249 'post_author' => get_current_user_id(),
1250 'post_content' => '',
1251 ];
1252
1253 $post_id = wp_insert_post($post_data);
1254
1255 if (is_wp_error($post_id)) {
1256 continue;
1257 }
1258 update_post_meta($post_id, '_elementor_data', wp_slash(wp_json_encode($page_content_arr['content'])));
1259 update_post_meta($post_id, '_elementor_edit_mode', 'builder');
1260
1261 if ($page['post_type'] === 'elementskit_template') {
1262
1263 update_post_meta($post_id, '_wp_page_template', 'elementor_canvas');
1264 $template_type = $page['type'] === 'header' ? 'header' : ($page['type'] === 'footer' ? 'footer' : 'general');
1265 update_post_meta($post_id, 'elementskit_template_activation', 'yes');
1266 update_post_meta($post_id, 'elementskit_template_type', $template_type);
1267 update_post_meta($post_id, 'elementskit_template_condition_a', 'entire_site');
1268 }
1269
1270 update_post_meta($post_id, '_wp_page_template', 'elementor_header_footer');
1271
1272 // Set homepage if applicable
1273 if ($page['ishome'] === 1) {
1274 update_option('page_on_front', $post_id);
1275 update_option('show_on_front', 'page');
1276 }
1277
1278 $imported_pages++;
1279 }
1280
1281 return $imported_pages > 0;
1282 }
1283 // end
1284
1285 private function get_free_themes_text_domain()
1286 {
1287 $api_url = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_array_records_datatable';
1288 $options = ['headers' => ['Content-Type' => 'application/json']];
1289 $response = wp_remote_get($api_url, $options);
1290 $wpei_free_text_domain = [];
1291 if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) {
1292 $json = json_decode(wp_remote_retrieve_body($response), true);
1293
1294 if (is_array($json)) {
1295 foreach ($json as $value) {
1296 if (is_array($value)) {
1297 foreach ($value as $values) {
1298 if (is_array($values) && isset($values['theme_domain_array'])) {
1299 $get_all_domains = $values['theme_domain_array'];
1300 array_push($wpei_free_text_domain, $get_all_domains);
1301 } elseif (is_object($values) && isset($values->theme_domain_array)) {
1302 $get_all_domains = $values->theme_domain_array;
1303 array_push($wpei_free_text_domain, $get_all_domains);
1304 }
1305 }
1306 }
1307 }
1308 }
1309 }
1310
1311 return $wpei_free_text_domain;
1312 }
1313
1314 // Function to fetch theme data from API
1315 private function get_theme_data()
1316 {
1317 $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_records';
1318 $options = ['headers' => ['Content-Type' => 'application/json']];
1319 $response = wp_remote_get($endpoint, $options);
1320
1321 if (is_wp_error($response)) {
1322 return ['status' => 100, 'msg' => 'Something went wrong!', 'data' => []];
1323 } else {
1324 $response_body = wp_remote_retrieve_body($response);
1325 $response_data = json_decode($response_body);
1326 return ['status' => 200, 'msg' => 'Theme data retrieved', 'data' => $response_data->data];
1327 }
1328 }
1329
1330 // Function to fetch remote content
1331 private function fetch_remote_content($url)
1332 {
1333 $response = wp_remote_get($url);
1334 if (is_wp_error($response)) {
1335 return false;
1336 }
1337 return wp_remote_retrieve_body($response);
1338 }
1339
1340
1341 //uninstall template
1342 public function fleximp_uninstall_template()
1343 {
1344 if (!current_user_can('manage_options')) {
1345 wp_send_json_error(['message' => 'You do not have permission to uninstall.']);
1346 }
1347
1348 $plugins = isset($_POST['plugins']) ? $_POST['plugins'] : [];
1349 $text_domain = sanitize_text_field($_POST['text_domain']);
1350
1351 // Deactivate and delete plugins
1352 if (!empty($plugins) && is_array($plugins)) {
1353 foreach ($plugins as $plugin) {
1354 $slug = sanitize_text_field($plugin['text_domain']);
1355 $main_file = sanitize_text_field($plugin['main_file']);
1356
1357 if (is_plugin_active("$slug/$main_file")) {
1358 deactivate_plugins("$slug/$main_file");
1359 }
1360
1361 delete_plugins(["$slug/$main_file"]);
1362 }
1363 }
1364
1365 // Delete imported pages by text domain marker
1366 $imported_pages = get_posts([
1367 'post_type' => ['page', 'elementskit_template'],
1368 'post_status' => 'publish',
1369 'numberposts' => -1,
1370 'meta_query' => [
1371 [
1372 'key' => '_elementor_data',
1373 'compare' => 'EXISTS'
1374 ]
1375 ]
1376 ]);
1377
1378 foreach ($imported_pages as $page) {
1379 wp_delete_post($page->ID, true);
1380 }
1381
1382 // Delete option
1383 delete_option('flex_template_is_imported');
1384 delete_option('fleximp_current_text_domain');
1385
1386 $locations = get_theme_mod('nav_menu_locations');
1387
1388 if (is_array($locations)) {
1389 foreach ($locations as $location => $menu_id) {
1390
1391 if ($location === 'primary-menu') {
1392 unset($locations[$location]);
1393 }
1394 }
1395 set_theme_mod('nav_menu_locations', $locations);
1396 }
1397
1398 $menus = wp_get_nav_menus();
1399 foreach ($menus as $menu) {
1400 if (stripos($menu->name, 'Primary Menu') !== false) {
1401 wp_delete_nav_menu($menu->term_id);
1402 }
1403 }
1404
1405
1406 wp_send_json_success(['message' => 'Plugins deactivated, content deleted successfully.']);
1407 }
1408
1409
1410 }