loader
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
967 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 | // uninstall template |
| 30 | add_action('wp_ajax_fleximp_uninstall_template', [$this, 'fleximp_uninstall_template']); |
| 31 | } |
| 32 | |
| 33 | // new for domain |
| 34 | |
| 35 | public function fleximp_set_text_domain() { |
| 36 | if (!current_user_can('manage_options')) { |
| 37 | wp_send_json_error('Unauthorized'); |
| 38 | } |
| 39 | |
| 40 | $template_php = isset($_POST['template_php']) ? esc_url_raw($_POST['template_php']) : ''; |
| 41 | |
| 42 | if (!empty($template_php)) { |
| 43 | $this->fleximp_handle_template_php_redirect($template_php); |
| 44 | } |
| 45 | |
| 46 | $text_domain = sanitize_text_field($_POST['text_domain'] ?? ''); |
| 47 | |
| 48 | if ($text_domain) { |
| 49 | update_option('fleximp_current_text_domain', $text_domain); |
| 50 | wp_send_json_success('Text domain saved'); |
| 51 | } else { |
| 52 | wp_send_json_error('Text domain is empty'); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private function includes() |
| 57 | { |
| 58 | require_once FLEXIMP_PLUGIN_FILE . 'includes/fleximp-license-functions.php'; |
| 59 | } |
| 60 | |
| 61 | // for frontend |
| 62 | public function fleximp_enqueue_frontend_assets() |
| 63 | { |
| 64 | if (!is_admin()) { |
| 65 | wp_enqueue_script('fleximp-service-tabs-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/front-script.js', array('jquery'), FLEXIMP_VER, true); |
| 66 | |
| 67 | |
| 68 | } |
| 69 | } |
| 70 | // end |
| 71 | |
| 72 | public function fleximp_add_admin_menu() |
| 73 | { |
| 74 | add_menu_page( |
| 75 | 'Elementor Template Importer', |
| 76 | 'Flex Importer', |
| 77 | 'manage_options', |
| 78 | 'fleximp-template-importer', |
| 79 | array($this, 'fleximp_display_dashboard_page'), |
| 80 | 'dashicons-download', |
| 81 | 20 |
| 82 | ); |
| 83 | |
| 84 | add_submenu_page( |
| 85 | 'fleximp-template-importer', |
| 86 | 'License Key', |
| 87 | 'License Key', |
| 88 | 'manage_options', |
| 89 | 'fleximp-license-key', |
| 90 | array($this, 'fleximp_display_license_page') |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | // hide admin notice |
| 96 | public function fleximp_hide_admin_notices() |
| 97 | { |
| 98 | $screen = get_current_screen(); |
| 99 | if ($screen->id === 'toplevel_page_fleximp-template-importer') { |
| 100 | remove_all_actions('admin_notices'); |
| 101 | remove_all_actions('all_admin_notices'); |
| 102 | } |
| 103 | } |
| 104 | //end |
| 105 | |
| 106 | // for license key |
| 107 | function fleximp_display_license_page() |
| 108 | { |
| 109 | if (!current_user_can('manage_options')) { |
| 110 | wp_die(esc_html__('Sorry, you are not allowed to access this page.', 'flex-import')); |
| 111 | } |
| 112 | ?> |
| 113 | <!-- License key code start --> |
| 114 | <div class="license-key-wrap"> |
| 115 | <form id="fleximp-license-key-form" action="<?php echo esc_url(admin_url('admin.php?page=')); ?>" method="POST"> |
| 116 | <div class="license-key-input-wrap"> |
| 117 | <label><?php esc_html_e('Enter Your Plugin License Key:', 'flex-import'); ?></label> |
| 118 | <div class="license-key-input"> |
| 119 | <input type="text" name="fleximp_is_premium" required placeholder="License Key" |
| 120 | value="<?php echo esc_attr(get_fleximp_key()); ?>" /> |
| 121 | </div> |
| 122 | <button class="button" name="key-activation" value="<?php esc_html_e('Activate', 'flex-import'); ?>" |
| 123 | type="submit">Activate</button> |
| 124 | <button class="button deactivate-domain" value="<?php esc_html_e('Deactivate', 'flex-import'); ?>" |
| 125 | type="button">Deactivate</button> |
| 126 | <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?> |
| 127 | <br><small id="license">License Key Activated Successfully</small> |
| 128 | <?php } ?> |
| 129 | </div> |
| 130 | </form> |
| 131 | </div> |
| 132 | |
| 133 | <!-- Server Info Section --> |
| 134 | <div class="fleximp-server-info" style="margin-top: 30px; padding: 15px; background: #f9f9f9; border: 1px solid #ddd;"> |
| 135 | <h3><?php esc_html_e('Recommended Server Settings for Importing Demo Content', 'flex-import'); ?></h3> |
| 136 | <ul> |
| 137 | <li><strong>PHP Time Limit:</strong> <?php echo esc_html(ini_get('max_execution_time')); ?> (Recommended: |
| 138 | 5000)</li> |
| 139 | <li><strong>PHP Memory Limit:</strong> <?php echo esc_html(ini_get('memory_limit')); ?> (Recommended: 9512M or |
| 140 | more)</li> |
| 141 | <li><strong>Max Input Vars:</strong> <?php echo esc_html(ini_get('max_input_vars')); ?> (Recommended: 6000) |
| 142 | </li> |
| 143 | <li><strong>Max Upload Size:</strong> <?php echo esc_html(size_format(wp_max_upload_size())); ?> |
| 144 | (Recommended: 200MB or more)</li> |
| 145 | </ul> |
| 146 | <p style="color: #d63638;"><strong>Note:</strong> |
| 147 | <?php esc_html_e('Contact your hosting provider to increase these values if needed for successful demo content import.', 'flex-import'); ?> |
| 148 | </p> |
| 149 | </div> |
| 150 | |
| 151 | <?php // } ?> |
| 152 | |
| 153 | <?php if (get_fleximp_suspension_status() == 'false' && get_fleximp_validation_status() !== 'false') { ?> |
| 154 | <div class="fleximp-elems-next" style="display:none;"> |
| 155 | |
| 156 | </div> |
| 157 | <?php } ?> |
| 158 | <?php |
| 159 | |
| 160 | } |
| 161 | // end |
| 162 | |
| 163 | |
| 164 | //for deactivate license key |
| 165 | public function fleximp_deactivate_license() |
| 166 | { |
| 167 | // Clear the license key and update the status |
| 168 | delete_option('fleximp_plugin_license_key'); |
| 169 | delete_option('fleximp_plugin_license_validation_status'); |
| 170 | wp_send_json_success(['message' => 'License deactivated successfully.']); |
| 171 | } |
| 172 | //end |
| 173 | |
| 174 | //new add handler from home |
| 175 | function fleximp_install_plugin_handler() |
| 176 | { |
| 177 | check_ajax_referer('fleximp_quick_setup_nonce', 'security'); |
| 178 | |
| 179 | if (!current_user_can('install_plugins')) { |
| 180 | wp_send_json_error(['message' => 'You do not have permission to install plugins.']); |
| 181 | } |
| 182 | |
| 183 | $template = sanitize_text_field($_POST['template']); |
| 184 | $plugins = $_POST['plugins']; // Array of plugins |
| 185 | |
| 186 | if (empty($template) || empty($plugins)) { |
| 187 | wp_send_json_error(['message' => 'Template or plugins data missing.']); |
| 188 | } |
| 189 | |
| 190 | wp_send_json_success(['message' => 'Plugins installed successfully.']); |
| 191 | } |
| 192 | //end |
| 193 | |
| 194 | |
| 195 | //new for checking plugin status' |
| 196 | public function fleximp_get_plugin_statuses() |
| 197 | { |
| 198 | |
| 199 | check_ajax_referer('fleximp_quick_setup_nonce', 'security'); |
| 200 | |
| 201 | if (!current_user_can('manage_options')) { |
| 202 | wp_send_json_error(['message' => 'Unauthorized'], 403); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | // Decode plugins array |
| 207 | $plugins = isset($_POST['plugins']) ? json_decode(stripslashes($_POST['plugins']), true) : []; |
| 208 | |
| 209 | if (empty($plugins)) { |
| 210 | wp_send_json_error(['message' => 'No plugins provided'], 400); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // Retrieve statuses |
| 215 | $installed_plugins = get_plugins(); |
| 216 | $active_plugins = get_option('active_plugins', []); |
| 217 | $response = []; |
| 218 | |
| 219 | foreach ($plugins as $plugin) { |
| 220 | $slug = $plugin['slug'] ?? ''; |
| 221 | $main_file = $plugin['main_file'] ?? ''; |
| 222 | |
| 223 | if (!$slug || !$main_file) |
| 224 | continue; |
| 225 | |
| 226 | $plugin_path = "{$slug}/{$main_file}"; |
| 227 | $response[$slug] = in_array($plugin_path, $active_plugins) ? 'Activated' : (isset($installed_plugins[$plugin_path]) ? 'Installed' : 'Not Installed'); |
| 228 | } |
| 229 | |
| 230 | // Send the response |
| 231 | wp_send_json_success($response); |
| 232 | } |
| 233 | //end |
| 234 | |
| 235 | //new add from old flex |
| 236 | public function fleximp_import_inner_pages_data() |
| 237 | { |
| 238 | // check_ajax_referer('fleximp_import_pages_nonce', 'nonce'); |
| 239 | |
| 240 | if (!current_user_can('manage_options')) { |
| 241 | wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import')); |
| 242 | } |
| 243 | |
| 244 | $content_path = isset($_POST['content_path']) ? sanitize_text_field($_POST['content_path']) : ''; |
| 245 | $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : ''; |
| 246 | $template_css = isset($_POST['template_css']) ? esc_url_raw($_POST['template_css']) : ''; |
| 247 | $template_js = isset($_POST['template_js']) ? esc_url_raw($_POST['template_js']) : ''; |
| 248 | $template_php = isset($_POST['template_php']) ? esc_url_raw($_POST['template_php']) : ''; |
| 249 | |
| 250 | // Redirect for template assets |
| 251 | if (!empty($template_php)) { |
| 252 | $this->fleximp_handle_template_php_redirect($template_php); |
| 253 | } |
| 254 | if (!empty($template_css)) { |
| 255 | $this->fleximp_handle_template_css_redirect($template_css); |
| 256 | } |
| 257 | if (!empty($template_js)) { |
| 258 | $this->fleximp_handle_template_js_redirect($template_js); |
| 259 | } |
| 260 | |
| 261 | if (empty($content_path)) { |
| 262 | wp_send_json_error(__('Content path is missing or invalid.', 'flex-import')); |
| 263 | } |
| 264 | |
| 265 | $response = wp_remote_get($content_path); |
| 266 | if (is_wp_error($response)) { |
| 267 | wp_send_json_error(__('Error fetching demo content from the server.', 'flex-import')); |
| 268 | } |
| 269 | $content = wp_remote_retrieve_body($response); |
| 270 | |
| 271 | $hash_response = wp_remote_get($content_path . '.sha256'); |
| 272 | if (is_wp_error($hash_response)) { |
| 273 | wp_send_json_error(__('Failed to fetch content hash from server.', 'flex-import')); |
| 274 | } |
| 275 | $expected_hash = trim(wp_remote_retrieve_body($hash_response)); |
| 276 | $actual_hash = hash('sha256', $content); |
| 277 | |
| 278 | if ($expected_hash !== $actual_hash) { |
| 279 | wp_send_json_error(__('Hash mismatch — content may be tampered with.', 'flex-import')); |
| 280 | } |
| 281 | |
| 282 | $content = str_replace( |
| 283 | 'http://example.com/assets/images/', |
| 284 | FLEXIMP_MAIN_URL . 'demo-content/' . $text_domain . '/assets/images/', |
| 285 | $content |
| 286 | ); |
| 287 | |
| 288 | if (!function_exists('WP_Filesystem')) { |
| 289 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 290 | } |
| 291 | |
| 292 | global $wp_filesystem; |
| 293 | WP_Filesystem(); |
| 294 | |
| 295 | $upload_dir = wp_upload_dir(); |
| 296 | $temp_file = $upload_dir['basedir'] . '/temp-content-import.php'; |
| 297 | |
| 298 | if (!$wp_filesystem->put_contents($temp_file, $content, FS_CHMOD_FILE)) { |
| 299 | wp_send_json_error(__('Failed to save temporary file for demo content.', 'flex-import')); |
| 300 | } |
| 301 | |
| 302 | try { |
| 303 | include $temp_file; |
| 304 | } catch (Exception $e) { |
| 305 | wp_send_json_error(__('Error executing demo content.', 'flex-import')); |
| 306 | } |
| 307 | |
| 308 | wp_delete_file($temp_file); |
| 309 | |
| 310 | wp_send_json_success(__('Demo content imported successfully!', 'flex-import')); |
| 311 | wp_die(); |
| 312 | } |
| 313 | |
| 314 | //end |
| 315 | |
| 316 | // dynamic js enqueue |
| 317 | public function fleximp_handle_template_js_redirect($template_js = '') |
| 318 | { |
| 319 | if (!empty($template_js)) { |
| 320 | update_option('fleximp_dynamic_template_js', esc_url_raw($template_js)); |
| 321 | } |
| 322 | } |
| 323 | //end |
| 324 | |
| 325 | // dynamic php enqueue |
| 326 | public function fleximp_handle_template_php_redirect($template_php = '') |
| 327 | { |
| 328 | if (!empty($template_php)) { |
| 329 | update_option('fleximp_dynamic_template_php', esc_url_raw($template_php)); |
| 330 | } |
| 331 | } |
| 332 | //end |
| 333 | |
| 334 | // dynamic css enqueue |
| 335 | public function fleximp_handle_template_css_redirect($template_css = '') |
| 336 | { |
| 337 | if (!empty($template_css)) { |
| 338 | update_option('fleximp_dynamic_template_css', esc_url_raw($template_css)); |
| 339 | } |
| 340 | } |
| 341 | //end |
| 342 | |
| 343 | // Get required plugins |
| 344 | public function fleximp_get_required_plugins() |
| 345 | { |
| 346 | if (!current_user_can('install_plugins')) { |
| 347 | wp_send_json_error(['message' => 'You do not have permission to install plugins.']); |
| 348 | } |
| 349 | |
| 350 | // Initialize WP_Filesystem API |
| 351 | global $wp_filesystem; |
| 352 | if (empty($wp_filesystem)) { |
| 353 | require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 354 | WP_Filesystem(); |
| 355 | } |
| 356 | |
| 357 | $plugins_file = get_template_directory() . '/inc/plugins.json'; |
| 358 | |
| 359 | if ($wp_filesystem->exists($plugins_file)) { |
| 360 | $plugins_json = $wp_filesystem->get_contents($plugins_file); |
| 361 | |
| 362 | |
| 363 | if (empty($plugins_json)) { |
| 364 | wp_send_json_error(['message' => 'Plugins configuration file is empty.']); |
| 365 | } |
| 366 | |
| 367 | $plugins = json_decode($plugins_json, true); |
| 368 | |
| 369 | if (json_last_error() !== JSON_ERROR_NONE) { |
| 370 | wp_send_json_error(['message' => 'Invalid JSON format in plugins configuration file.']); |
| 371 | } |
| 372 | |
| 373 | foreach ($plugins as $key => $plugin) { |
| 374 | $main_file = !empty($plugin['main_file']) ? $plugin['main_file'] : $plugin['slug'] . '.php'; |
| 375 | $plugin_file = WP_PLUGIN_DIR . '/' . $plugin['slug'] . '/' . $main_file; |
| 376 | |
| 377 | // Check if the plugin is installed and active |
| 378 | $plugins[$key]['status'] = file_exists($plugin_file) && is_plugin_active($plugin_file) ? 'installed' : 'required'; |
| 379 | } |
| 380 | |
| 381 | wp_send_json_success($plugins); |
| 382 | } else { |
| 383 | wp_send_json_error(['message' => 'Plugins configuration file not found.']); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | |
| 388 | // from templates tab plugins |
| 389 | public function fleximp_checked_install_plugin() |
| 390 | { |
| 391 | // check_ajax_referer('fleximp_quick_setup_nonce', 'security'); |
| 392 | |
| 393 | if (!current_user_can('install_plugins')) { |
| 394 | wp_send_json_error(['message' => 'You do not have permission to install plugins.']); |
| 395 | } |
| 396 | |
| 397 | global $wp_filesystem; |
| 398 | if (empty($wp_filesystem)) { |
| 399 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 400 | WP_Filesystem(); |
| 401 | } |
| 402 | |
| 403 | $plugin_slug = sanitize_text_field($_POST['plugin_slug']); |
| 404 | $plugin_name = sanitize_text_field($_POST['plugin_name']); |
| 405 | $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']); |
| 406 | |
| 407 | if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) { |
| 408 | wp_send_json_error(['message' => 'Plugin details are missing.']); |
| 409 | } |
| 410 | |
| 411 | $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file; |
| 412 | |
| 413 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 414 | $upgrader = new Plugin_Upgrader(); |
| 415 | |
| 416 | // Install the plugin if it's not already installed |
| 417 | if (!file_exists($plugin_file)) { |
| 418 | $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip'; |
| 419 | $install_result = $upgrader->install($plugin_url); |
| 420 | |
| 421 | if (is_wp_error($install_result)) { |
| 422 | wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]); |
| 423 | } |
| 424 | |
| 425 | if (file_exists($plugin_file)) { |
| 426 | // Activate the plugin |
| 427 | $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file); |
| 428 | if (is_wp_error($activation)) { |
| 429 | wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]); |
| 430 | } |
| 431 | wp_send_json_success(['message' => 'Plugin installed and activated successfully.']); |
| 432 | } else { |
| 433 | wp_send_json_error(['message' => 'Plugin installation failed.']); |
| 434 | } |
| 435 | } else { |
| 436 | // Activate if already installed but not active |
| 437 | if (!is_plugin_active($plugin_file)) { |
| 438 | $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file); |
| 439 | if (is_wp_error($activation)) { |
| 440 | wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]); |
| 441 | } |
| 442 | } |
| 443 | wp_send_json_success(['message' => 'Plugin is already installed and activated.']); |
| 444 | } |
| 445 | } |
| 446 | // end |
| 447 | |
| 448 | //more new one |
| 449 | public function fleximp_install_plugin() |
| 450 | { |
| 451 | // check_ajax_referer('fleximp_quick_setup_nonce', 'security'); |
| 452 | |
| 453 | if (!current_user_can('install_plugins')) { |
| 454 | wp_send_json_error(['message' => 'You do not have permission to install plugins.']); |
| 455 | } |
| 456 | |
| 457 | global $wp_filesystem; |
| 458 | if (empty($wp_filesystem)) { |
| 459 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 460 | WP_Filesystem(); |
| 461 | } |
| 462 | |
| 463 | $plugin_slug = sanitize_text_field($_POST['plugin_slug']); |
| 464 | $plugin_name = sanitize_text_field($_POST['plugin_name']); |
| 465 | $plugin_main_file = sanitize_text_field($_POST['plugin_main_file']); |
| 466 | |
| 467 | if (empty($plugin_slug) || empty($plugin_name) || empty($plugin_main_file)) { |
| 468 | wp_send_json_error(['message' => 'Plugin details are missing.']); |
| 469 | } |
| 470 | |
| 471 | $plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_main_file; |
| 472 | |
| 473 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 474 | $upgrader = new Plugin_Upgrader(); |
| 475 | |
| 476 | // Install the plugin if it's not already installed |
| 477 | if (!file_exists($plugin_file)) { |
| 478 | $plugin_url = 'https://downloads.wordpress.org/plugin/' . $plugin_slug . '.latest-stable.zip'; |
| 479 | $install_result = $upgrader->install($plugin_url); |
| 480 | |
| 481 | if (is_wp_error($install_result)) { |
| 482 | wp_send_json_error(['message' => 'Installation error: ' . $install_result->get_error_message()]); |
| 483 | } |
| 484 | |
| 485 | if (file_exists($plugin_file)) { |
| 486 | // Activate the plugin |
| 487 | $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file); |
| 488 | if (is_wp_error($activation)) { |
| 489 | wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]); |
| 490 | } |
| 491 | wp_send_json_success(['message' => 'Plugin installed and activated successfully.']); |
| 492 | } else { |
| 493 | wp_send_json_error(['message' => 'Plugin installation failed.']); |
| 494 | } |
| 495 | } else { |
| 496 | // Activate if already installed but not active |
| 497 | if (!is_plugin_active($plugin_file)) { |
| 498 | $activation = activate_plugin($plugin_slug . '/' . $plugin_main_file); |
| 499 | if (is_wp_error($activation)) { |
| 500 | wp_send_json_error(['message' => 'Activation error: ' . $activation->get_error_message()]); |
| 501 | } |
| 502 | } |
| 503 | wp_send_json_success(['message' => 'Plugin is already installed and activated.']); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | |
| 508 | //changes start from here for dashboard |
| 509 | public function fleximp_display_dashboard_page() |
| 510 | { ?> |
| 511 | <div class="container-fluid flex-imp-nav-box" style="margin-top:30px;"> |
| 512 | <div class="row w-100"> |
| 513 | <div class="col-xl-2 col-sm-2 col-4"> |
| 514 | <div class="flex-dash-plugin-logo "> |
| 515 | <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/flex-logo.svg'); ?>" |
| 516 | alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" class="logo-img"> |
| 517 | </div> |
| 518 | </div> |
| 519 | |
| 520 | <div class="col-xl-10 col-sm-10 col-8 flex-container-1"> |
| 521 | <div class="row"> |
| 522 | <div class="col-lg-12 col-xl-8 align-self-center"> |
| 523 | <div> |
| 524 | <ul class="nav nav-tabs mr-auto flex-nav-tab-links" role="tablist"> |
| 525 | <li class="nav-item flex-icons "> |
| 526 | <!-- <a class="nav-link active" data-toggle="tab" href="#dashboard"> --> |
| 527 | <a class="nav-link" data-toggle="tab" href="#dashboard"> |
| 528 | |
| 529 | |
| 530 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"> |
| 531 | <path |
| 532 | 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" /> |
| 533 | </svg> |
| 534 | <?php esc_html_e('Dashboard', 'flex-import'); ?> |
| 535 | </a> |
| 536 | </li> |
| 537 | <li class="nav-item flex-icons "> |
| 538 | <!-- <a class="nav-link" data-toggle="tab" href="#templates"> --> |
| 539 | <a class="nav-link active" data-toggle="tab" href="#templates"> |
| 540 | <svg id="Group_65" data-name="Group 65" xmlns="http://www.w3.org/2000/svg" |
| 541 | width="18.571" height="20" viewBox="0 0 18.571 20"> |
| 542 | <path id="Path_46" data-name="Path 46" |
| 543 | 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" |
| 544 | transform="translate(-45.785 -45.785)" /> |
| 545 | <path id="Path_47" data-name="Path 47" |
| 546 | 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" |
| 547 | transform="translate(-92.195 -153.29)" /> |
| 548 | <path id="Path_48" data-name="Path 48" |
| 549 | 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" /> |
| 550 | <path id="Path_49" data-name="Path 49" |
| 551 | 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" |
| 552 | transform="translate(-92.195 -91.732)" /> |
| 553 | </svg> |
| 554 | |
| 555 | |
| 556 | <?php esc_html_e('Templates', 'flex-import'); ?> |
| 557 | </a> |
| 558 | </li> |
| 559 | <li class="nav-item flex-icons"> |
| 560 | <a class="nav-link" data-toggle="tab" href="#plugins"> |
| 561 | <svg id="Group_66" data-name="Group 66" xmlns="http://www.w3.org/2000/svg" |
| 562 | width="20" height="20" viewBox="0 0 20 20"> |
| 563 | <g id="extension"> |
| 564 | <path id="Path_50" data-name="Path 50" |
| 565 | 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" /> |
| 566 | </g> |
| 567 | </svg> |
| 568 | <?php esc_html_e('Plugins', 'flex-import'); ?> |
| 569 | </a> |
| 570 | </li> |
| 571 | <li class="nav-item flex-icons"> |
| 572 | <a class="nav-link" data-toggle="tab" href="#widgets"> |
| 573 | <svg xmlns="http://www.w3.org/2000/svg" width="20.504" height="20.508" |
| 574 | viewBox="0 0 20.504 20.508"> |
| 575 | <g id="Group_72" data-name="Group 72" transform="translate(-1121.166 -308.672)"> |
| 576 | <g id="Group_71" data-name="Group 71" |
| 577 | transform="translate(1121.166 308.672)"> |
| 578 | <g id="Icon" transform="translate(0 0)"> |
| 579 | <g id="Group_67" data-name="Group 67" |
| 580 | transform="translate(0 0.004)"> |
| 581 | <path id="Path_51" data-name="Path 51" |
| 582 | 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" |
| 583 | transform="translate(-0.433 -45.465)" fill="" |
| 584 | fill-rule="evenodd" /> |
| 585 | </g> |
| 586 | <g id="Group_68" data-name="Group 68" |
| 587 | transform="translate(0 10.992)"> |
| 588 | <path id="Path_52" data-name="Path 52" |
| 589 | 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" |
| 590 | transform="translate(-0.433 -45.465)" fill="" |
| 591 | fill-rule="evenodd" /> |
| 592 | </g> |
| 593 | <g id="Group_69" data-name="Group 69" |
| 594 | transform="translate(10.988 10.992)"> |
| 595 | <path id="Path_53" data-name="Path 53" |
| 596 | 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" |
| 597 | transform="translate(-0.433 -45.465)" fill="" |
| 598 | fill-rule="evenodd" /> |
| 599 | </g> |
| 600 | <g id="Group_70" data-name="Group 70" |
| 601 | transform="translate(10.984 0)"> |
| 602 | <path id="Path_54" data-name="Path 54" |
| 603 | 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" |
| 604 | transform="translate(-12.624 -90.619)" fill="" |
| 605 | fill-rule="evenodd" /> |
| 606 | </g> |
| 607 | </g> |
| 608 | </g> |
| 609 | </g> |
| 610 | </svg> |
| 611 | <?php esc_html_e('Widgets', 'flex-import'); ?> |
| 612 | </a> |
| 613 | </li> |
| 614 | </ul> |
| 615 | </div> |
| 616 | </div> |
| 617 | <div class="col-lg-12 col-xl-4 text-right flex-demo-btns mt-xl-0 mt-3"> |
| 618 | <div class="ml-auto flex-demo-buttons"> |
| 619 | <a href="https://www.flextheme.net/products/flex-pro-wordpress-theme" |
| 620 | class="btn flex-demo-btn flex-btn-space" target="_blank" rel="noopener"> |
| 621 | <img src="<?php echo esc_url(FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png'); ?>" |
| 622 | alt="<?php esc_attr_e('Plugin Logo', 'flex-import'); ?>" style=""> |
| 623 | <?php esc_html_e('Get Pro', 'flex-import'); ?> |
| 624 | </a> |
| 625 | </div> |
| 626 | </div> |
| 627 | </div> |
| 628 | </div> |
| 629 | </div> |
| 630 | </div> |
| 631 | <!-- Tab Content --> |
| 632 | <div class="tab-content mt-3"> |
| 633 | <!-- <div id="dashboard" class="tab-pane fade"> --> |
| 634 | <div id="dashboard" class="tab-pane fade"> |
| 635 | <?php include FLEXIMP_PLUGIN_FILE . '/templates/dashboard-content.php'; ?> |
| 636 | </div> |
| 637 | <!-- <div id="templates" class="tab-pane fade fleximp-template-main-box"> --> |
| 638 | <div id="templates" class="tab-pane fade show active fleximp-template-main-box"> |
| 639 | <?php include FLEXIMP_PLUGIN_FILE . '/templates/templates-content.php'; ?> |
| 640 | </div> |
| 641 | <div id="plugins" class="tab-pane fade fleximp-plugin-main-box"> |
| 642 | <?php include FLEXIMP_PLUGIN_FILE . '/templates/plugins-content.php'; ?> |
| 643 | </div> |
| 644 | <div id="widgets" class="tab-pane fade fleximp-widgets-main-box"> |
| 645 | <?php include FLEXIMP_PLUGIN_FILE . '/templates/widgets-content.php'; ?> |
| 646 | </div> |
| 647 | </div> |
| 648 | <?php } |
| 649 | |
| 650 | //changes end from here for bootstrap |
| 651 | public function fleximp_enqueue_admin_assets() |
| 652 | { |
| 653 | wp_enqueue_style('fleximp-dashboard-banner', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/dashboard-banner.css', array(), FLEXIMP_VER); |
| 654 | |
| 655 | $screen = get_current_screen(); |
| 656 | if ($screen->id === 'toplevel_page_fleximp-template-importer') { |
| 657 | wp_enqueue_style('fleximp-admin-styles', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/admin-style.css', array(), FLEXIMP_VER); |
| 658 | |
| 659 | // Enqueue Bootstrap CSS and JS |
| 660 | wp_enqueue_style('bootstrap-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.css', [], FLEXIMP_VER); |
| 661 | wp_enqueue_script('bootstrap-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/bootstrap.min.js', ['jquery'], FLEXIMP_VER, true); |
| 662 | wp_enqueue_script('flex-swiper-js', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/swiper-bundle.min.js', ['jquery'], FLEXIMP_VER, true); |
| 663 | wp_enqueue_script('fleximp-admin-scripts', FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/admin-script.js', array('jquery'), FLEXIMP_VER, true); |
| 664 | wp_enqueue_style('font-awesome', FLEXIMP_PLUGIN_DIR_FILE . 'assets/lib/all.min.css', [], FLEXIMP_VER); |
| 665 | |
| 666 | $is_premium_theme = defined('GET_PREMIUM_THEME'); |
| 667 | |
| 668 | wp_localize_script('fleximp-admin-scripts', 'fleximp_admin_ajax_object', array( |
| 669 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 670 | 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'), |
| 671 | 'plugin_url' => plugins_url('', __FILE__), |
| 672 | 'is_premium_theme' => $is_premium_theme |
| 673 | )); |
| 674 | |
| 675 | //for plugin |
| 676 | wp_enqueue_script( |
| 677 | 'fleximp-plugin-js', |
| 678 | FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/plugin-admin.js', |
| 679 | array('jquery'), |
| 680 | FLEXIMP_VER, |
| 681 | true |
| 682 | ); |
| 683 | |
| 684 | wp_localize_script('fleximp-plugin-js', 'fleximp_ajax_object', array( |
| 685 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 686 | 'fleximp_nonce' => wp_create_nonce('fleximp_quick_setup_nonce'), |
| 687 | 'plugin_url' => plugins_url('', __FILE__), |
| 688 | 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-api.php', |
| 689 | )); |
| 690 | //end |
| 691 | |
| 692 | //for templates |
| 693 | wp_enqueue_script( |
| 694 | 'fleximp-template-js', |
| 695 | FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/template-admin.js', |
| 696 | array('jquery'), |
| 697 | FLEXIMP_VER, |
| 698 | true |
| 699 | ); |
| 700 | |
| 701 | $is_elementor_active = is_plugin_active('elementor/elementor.php'); |
| 702 | |
| 703 | wp_localize_script('fleximp-template-js', 'fleximp_template_ajax_object', array( |
| 704 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 705 | 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'), |
| 706 | 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-get-templates-api.php', |
| 707 | 'isPremiumUser' => get_option('fleximp_is_premium', false), |
| 708 | 'imported_template' => get_option('flex_template_is_imported', ''), |
| 709 | 'pro_image_url' => FLEXIMP_PLUGIN_DIR_FILE . 'assets/images/pro.png', |
| 710 | 'fleximp_current_text_domain' => get_option('fleximp_current_text_domain'), |
| 711 | 'isElementorActive' => $is_elementor_active ? '1' : '0', |
| 712 | )); |
| 713 | //end |
| 714 | |
| 715 | //for dashboard |
| 716 | wp_enqueue_script( |
| 717 | 'fleximp-dashposts-js', |
| 718 | FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/dashboard-posts.js', |
| 719 | array('jquery'), |
| 720 | FLEXIMP_VER, |
| 721 | true |
| 722 | ); |
| 723 | |
| 724 | wp_localize_script('fleximp-dashposts-js', 'fleximp_dashposts_ajax_object', array( |
| 725 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 726 | 'fleximp_nonce' => wp_create_nonce('fleximp_nonce'), |
| 727 | 'apiEndpoint' => FLEXIMP_PLUGIN_DIR_FILE . 'includes/flex-dashboard-post-api.php', |
| 728 | )); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | //for license key |
| 733 | |
| 734 | public function fleximp_verify_license() |
| 735 | { |
| 736 | $license_key = sanitize_text_field($_POST['fleximp_license_key']); |
| 737 | $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'verifyTheme'; |
| 738 | |
| 739 | $body = json_encode([ |
| 740 | 'theme_license_key' => $license_key, |
| 741 | 'site_url' => site_url(), |
| 742 | 'theme_text_domain' => wp_get_theme()->get('TextDomain'), |
| 743 | ]); |
| 744 | |
| 745 | $response = wp_remote_post($endpoint, [ |
| 746 | 'body' => $body, |
| 747 | 'headers' => ['Content-Type' => 'application/json'] |
| 748 | ]); |
| 749 | |
| 750 | if (is_wp_error($response)) { |
| 751 | wp_send_json_error(['message' => 'Connection error.']); |
| 752 | return; |
| 753 | } |
| 754 | |
| 755 | $response_body = json_decode(wp_remote_retrieve_body($response), true); |
| 756 | |
| 757 | if (isset($response_body['is_suspended']) && $response_body['is_suspended'] == 1) { |
| 758 | wp_send_json_error(['message' => 'License is suspended.']); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | if (isset($response_body['status']) && $response_body['status'] === true) { |
| 763 | update_option('fleximp_plugin_license_key', $license_key); |
| 764 | update_option('fleximp_plugin_license_validation_status', 'true'); |
| 765 | wp_send_json_success(['message' => 'License activated successfully!']); |
| 766 | } else { |
| 767 | $error_message = isset($response_body['message']) ? $response_body['message'] : 'License activation failed. Please try again.'; |
| 768 | wp_send_json_error(['message' => $error_message]); |
| 769 | } |
| 770 | } |
| 771 | //end |
| 772 | |
| 773 | public function fleximp_import_demo_content() |
| 774 | { |
| 775 | |
| 776 | if (!current_user_can('manage_options')) { |
| 777 | wp_send_json_error(__('You do not have permission to import demo content.', 'flex-import')); |
| 778 | } |
| 779 | |
| 780 | if (!is_plugin_active('elementor/elementor.php')) { |
| 781 | wp_send_json_error(__('Elementor must be installed and activated before importing demo content.', 'flex-import')); |
| 782 | } |
| 783 | |
| 784 | $text_domain = isset($_POST['text_domain']) ? sanitize_text_field($_POST['text_domain']) : 'flex-import'; |
| 785 | |
| 786 | $import_success = $this->fleximp_elementor_importer_setup_pages(); |
| 787 | |
| 788 | if ($import_success) { |
| 789 | update_option('flex_template_is_imported', $text_domain); |
| 790 | wp_send_json_success(__('imported successfully!', 'flex-import')); |
| 791 | } else { |
| 792 | wp_send_json_error(__('Error occurred during the import process.', 'flex-import')); |
| 793 | } |
| 794 | |
| 795 | wp_die(); |
| 796 | } |
| 797 | |
| 798 | //new add for import pages from old flex |
| 799 | public function fleximp_elementor_importer_setup_pages() |
| 800 | { |
| 801 | $active_theme = wp_get_theme(); |
| 802 | $active_theme_textdomain = $active_theme->get('TextDomain'); |
| 803 | |
| 804 | $pages_arr = []; |
| 805 | $imported_pages = 0; |
| 806 | |
| 807 | $fallback_json_url = isset($_POST['json_path']) ? sanitize_text_field($_POST['json_path']) : FLEXIMP_MAIN_URL . '/themes-json/multipurpose-business/multipurpose-business.json'; |
| 808 | $fallback_content = $this->fetch_remote_content($fallback_json_url); |
| 809 | |
| 810 | if ($fallback_content) { |
| 811 | $fallback_data = json_decode($fallback_content, true); |
| 812 | if ($fallback_data) { |
| 813 | foreach ($fallback_data as $page) { |
| 814 | $pages_arr[] = [ |
| 815 | 'title' => $page['name'], |
| 816 | 'ishome' => ($page['type'] === 'home') ? 1 : 0, |
| 817 | 'post_type' => $page['posttype'], |
| 818 | 'source' => $page['source'], |
| 819 | 'type' => $page['type'] |
| 820 | ]; |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | foreach ($pages_arr as $page) { |
| 826 | $page_content_response = wp_remote_get($page['source']); |
| 827 | |
| 828 | if (is_wp_error($page_content_response) || wp_remote_retrieve_response_code($page_content_response) !== 200) { |
| 829 | continue; |
| 830 | } |
| 831 | |
| 832 | $page_content_arr = isset($page['content']) ? ['content' => $page['content']] : json_decode(wp_remote_retrieve_body($page_content_response), true); |
| 833 | |
| 834 | if ($page_content_arr === null || !isset($page_content_arr['content'])) { |
| 835 | continue; |
| 836 | } |
| 837 | |
| 838 | $post_data = [ |
| 839 | 'post_title' => $page['title'], |
| 840 | 'post_type' => $page['post_type'], |
| 841 | 'post_status' => 'publish', |
| 842 | 'post_author' => get_current_user_id(), |
| 843 | 'post_content' => '', |
| 844 | ]; |
| 845 | |
| 846 | $post_id = wp_insert_post($post_data); |
| 847 | |
| 848 | if (is_wp_error($post_id)) { |
| 849 | continue; |
| 850 | } |
| 851 | update_post_meta($post_id, '_elementor_data', wp_slash(wp_json_encode($page_content_arr['content']))); |
| 852 | update_post_meta($post_id, '_elementor_edit_mode', 'builder'); |
| 853 | |
| 854 | if ($page['post_type'] === 'elementskit_template') { |
| 855 | |
| 856 | update_post_meta($post_id, '_wp_page_template', 'elementor_canvas'); |
| 857 | $template_type = $page['type'] === 'header' ? 'header' : ($page['type'] === 'footer' ? 'footer' : 'general'); |
| 858 | update_post_meta($post_id, 'elementskit_template_activation', 'yes'); |
| 859 | update_post_meta($post_id, 'elementskit_template_type', $template_type); |
| 860 | update_post_meta($post_id, 'elementskit_template_condition_a', 'entire_site'); |
| 861 | } |
| 862 | |
| 863 | update_post_meta($post_id, '_wp_page_template', 'elementor_header_footer'); |
| 864 | |
| 865 | // Set homepage if applicable |
| 866 | if ($page['ishome'] === 1) { |
| 867 | update_option('page_on_front', $post_id); |
| 868 | update_option('show_on_front', 'page'); |
| 869 | } |
| 870 | |
| 871 | $imported_pages++; |
| 872 | } |
| 873 | |
| 874 | return $imported_pages > 0; |
| 875 | } |
| 876 | // end |
| 877 | |
| 878 | private function get_free_themes_text_domain() |
| 879 | { |
| 880 | $api_url = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_array_records_datatable'; |
| 881 | $options = ['headers' => ['Content-Type' => 'application/json']]; |
| 882 | $response = wp_remote_get($api_url, $options); |
| 883 | $wpei_free_text_domain = []; |
| 884 | if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) == 200) { |
| 885 | $json = json_decode(wp_remote_retrieve_body($response), true); |
| 886 | |
| 887 | if (is_array($json)) { |
| 888 | foreach ($json as $value) { |
| 889 | if (is_array($value)) { |
| 890 | foreach ($value as $values) { |
| 891 | if (is_array($values) && isset($values['theme_domain_array'])) { |
| 892 | $get_all_domains = $values['theme_domain_array']; |
| 893 | array_push($wpei_free_text_domain, $get_all_domains); |
| 894 | } elseif (is_object($values) && isset($values->theme_domain_array)) { |
| 895 | $get_all_domains = $values->theme_domain_array; |
| 896 | array_push($wpei_free_text_domain, $get_all_domains); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | return $wpei_free_text_domain; |
| 905 | } |
| 906 | |
| 907 | // Function to fetch theme data from API |
| 908 | private function get_theme_data() |
| 909 | { |
| 910 | $endpoint = WPEI_SHOPIFY_LICENCE_ENDPOINT . 'get_elemento_themes_records'; |
| 911 | $options = ['headers' => ['Content-Type' => 'application/json']]; |
| 912 | $response = wp_remote_get($endpoint, $options); |
| 913 | |
| 914 | if (is_wp_error($response)) { |
| 915 | return ['status' => 100, 'msg' => 'Something went wrong!', 'data' => []]; |
| 916 | } else { |
| 917 | $response_body = wp_remote_retrieve_body($response); |
| 918 | $response_data = json_decode($response_body); |
| 919 | return ['status' => 200, 'msg' => 'Theme data retrieved', 'data' => $response_data->data]; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | // Function to fetch remote content |
| 924 | private function fetch_remote_content($url) |
| 925 | { |
| 926 | $response = wp_remote_get($url); |
| 927 | if (is_wp_error($response)) { |
| 928 | return false; |
| 929 | } |
| 930 | return wp_remote_retrieve_body($response); |
| 931 | } |
| 932 | |
| 933 | |
| 934 | //uninstall template |
| 935 | public function fleximp_uninstall_template() |
| 936 | { |
| 937 | if (!current_user_can('manage_options')) { |
| 938 | wp_send_json_error(['message' => 'You do not have permission to uninstall.']); |
| 939 | } |
| 940 | |
| 941 | // Delete option |
| 942 | delete_option('flex_template_is_imported'); |
| 943 | delete_option('fleximp_current_text_domain'); |
| 944 | delete_option('fleximp_dynamic_template_php'); |
| 945 | delete_option('fleximp_dynamic_template_js'); |
| 946 | delete_option('fleximp_dynamic_template_css'); |
| 947 | |
| 948 | if (!function_exists('WP_Filesystem')) { |
| 949 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 950 | } |
| 951 | |
| 952 | global $wp_filesystem; |
| 953 | WP_Filesystem(); |
| 954 | |
| 955 | // Empty the fleximp-temp-template.php file |
| 956 | $temp_template = trailingslashit(FLEXIMP_PLUGIN_FILE) . 'templates-content/fleximp-temp-template.php'; |
| 957 | if (file_exists($temp_template)) { |
| 958 | if (!$wp_filesystem->put_contents($temp_template, '', FS_CHMOD_FILE)) { |
| 959 | wp_send_json_error(['message' => 'Something went wrong!']); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | wp_send_json_success(['message' => 'Plugins deactivated, content deleted successfully.']); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | } |