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