plugin_page_setup = apply_filters('af-companion/plugin_page_setup', array( 'parent_slug' => 'themes.php', 'page_title' => esc_html__('AF Companion', 'af-companion'), 'menu_title' => esc_html__('AF Companion', 'af-companion'), 'capability' => 'import', 'menu_slug' => 'af-companion', )); $aft_logo_svg = ''; $this->plugin_page = add_menu_page( $this->plugin_page_setup['page_title'], $this->plugin_page_setup['menu_title'], $this->plugin_page_setup['capability'], $this->plugin_page_setup['menu_slug'], apply_filters('af-companion/plugin_page_display_callback_function', array($this, 'display_plugin_page')), 'data:image/svg+xml;base64,' . base64_encode($aft_logo_svg), 60 ); add_submenu_page( 'af-companion', esc_html__('Import Demo', 'af-companion'), esc_html__('Import Demo', 'af-companion'), 'import', 'af-companion', apply_filters('af-companion/plugin_page_display_callback_function', array($this, 'display_plugin_page')) ); add_submenu_page( 'af-companion', esc_html__('Documentation', 'af-companion'), esc_html__('Documentation', 'af-companion'), 'manage_options', esc_url('https://docs.afthemes.com/') ); add_submenu_page( 'af-companion', esc_html__('Free Themes', 'af-companion'), esc_html__('Free Themes', 'af-companion'), 'manage_options', esc_url('https://afthemes.com/products/category/free/') ); add_submenu_page( 'af-companion', esc_html__('Pro Themes', 'af-companion'), esc_html__('Pro Themes', 'af-companion'), 'manage_options', esc_url('https://afthemes.com/products/category/pro/') ); add_submenu_page( 'af-companion', esc_html__('Plugins', 'af-companion'), esc_html__('Plugins', 'af-companion'), 'manage_options', esc_url('https://afthemes.com/plugins/') ); add_submenu_page( 'af-companion', esc_html__('Videos', 'af-companion'), esc_html__('Videos', 'af-companion'), 'manage_options', esc_url('https://www.youtube.com/channel/UCCJKF25c3HZpfaELha-86Hw/') ); add_submenu_page( 'af-companion', esc_html__('Blog', 'af-companion'), esc_html__('Blog', 'af-companion'), 'manage_options', esc_url('https://afthemes.com/blog/') ); register_importer($this->plugin_page_setup['menu_slug'], $this->plugin_page_setup['page_title'], $this->plugin_page_setup['menu_title'], apply_filters('af-companion/plugin_page_display_callback_function', array($this, 'display_plugin_page'))); } /** * Plugin page display. */ public function display_plugin_page() { $predefined_themes = $this->import_files; if (!empty($this->import_files) && isset($_GET['import-mode']) && 'manual' === $_GET['import-mode']) { $predefined_themes = array(); } ?>
' ); } ?>plugin_page === $hook) { wp_enqueue_script('jquery-ui-dialog'); wp_enqueue_style('wp-jquery-ui-dialog'); wp_enqueue_script('aftc-main-js', AFTC_URL . 'assets/js/main.js', array('jquery', 'jquery-form'), AFTC_VERSION); wp_enqueue_script('aftc-activate-install', AFTC_URL . 'assets/js/activate-plugins.js', array('jquery', 'aftc-main-js'), AFTC_VERSION); $theme = wp_get_theme(); wp_localize_script( 'aftc-main-js', 'aftc', array( 'ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce('aftc-ajax-verification'), 'import_files' => $this->import_files, 'wp_customize_on' => apply_filters('af-companion/enable_wp_customize_save_hooks', false), 'import_popup' => apply_filters('af-companion/enable_grid_layout_import_popup_confirmation', true), 'theme_screenshot' => $theme->get_screenshot(), 'texts' => array( 'missing_preview_image' => esc_html__('No preview image defined for this import.', 'af-companion'), 'dialog_title' => esc_html__('Are you sure?', 'af-companion'), 'dialog_no' => esc_html__('Cancel', 'af-companion'), 'dialog_yes' => esc_html__('Yes, import!', 'af-companion'), 'selected_import_title' => esc_html__('Selected demo for the import', 'af-companion'), ), 'dialog_options' => apply_filters('af-companion/confirmation_dialog_options', array()) ) ); wp_enqueue_style('aftc-main-css', AFTC_URL . 'assets/css/main.css', array(), AFTC_VERSION); } wp_enqueue_style('aftc-notice-css', AFTC_URL . 'assets/css/notice.css', array(), AFTC_VERSION); } /** * Main AJAX callback function for: * 1. prepare import files (uploaded or predefined via filters) * 2. import content * 3. before widgets import setup (optional) * 4. import widgets (optional) * 5. import customizer options (optional) * 6. after import setup (optional) */ public function import_demo_data_ajax_callback() { // Try to update PHP memory limit (so that it does not run out of it). ini_set('memory_limit', apply_filters('af-companion/import_memory_limit', '350M')); // Verify if the AJAX call is valid (checks nonce and current_user_can). AFTC_Helpers::verify_ajax_call(); // Is this a new AJAX call to continue the previous import? $use_existing_importer_data = $this->get_importer_data(); if (!$use_existing_importer_data) { // Set the AJAX call number. $this->ajax_call_number = empty($this->ajax_call_number) ? 0 : $this->ajax_call_number; // Error messages displayed on front page. $this->frontend_error_messages = ''; // Create a date and time string to use for demo and log file names. $demo_import_start_time = date(apply_filters('af-companion/date_format_for_file_names', 'Y-m-d__H-i-s')); // Define log file path. $this->log_file_path = AFTC_Helpers::get_log_path($demo_import_start_time); // Get selected file index or set it to 0. $this->selected_index = empty($_POST['selected']) ? 0 : absint($_POST['selected']); /** * 1. Prepare import files. * Manually uploaded import files or predefined import files via filter: af-companion/import_files */ if (!empty($_FILES)) { // Using manual file uploads? // Get paths for the uploaded files. $this->selected_import_files = AFTC_Helpers::process_uploaded_files($_FILES, $this->log_file_path); // Set the name of the import files, because we used the uploaded files. $this->import_files[$this->selected_index]['import_file_name'] = esc_html__('Manually uploaded files', 'af-companion'); } elseif (!empty($this->import_files[$this->selected_index])) { // Use predefined import files from wp filter: af-companion/import_files. // Download the import files (content and widgets files) and save it to variable for later use. $this->selected_import_files = AFTC_Helpers::download_import_files( $this->import_files[$this->selected_index], $demo_import_start_time ); // Check Errors. if (is_wp_error($this->selected_import_files)) { // Write error to log file and send an AJAX response with the error. AFTC_Helpers::log_error_and_send_ajax_response( $this->selected_import_files->get_error_message(), $this->log_file_path, esc_html__('Downloaded files', 'af-companion') ); } // Add this message to log file. $log_added = AFTC_Helpers::append_to_file( sprintf( __('The import files for: %s were successfully downloaded!', 'af-companion'), $this->import_files[$this->selected_index]['import_file_name'] ) . AFTC_Helpers::import_file_info($this->selected_import_files), $this->log_file_path, esc_html__('Downloaded files', 'af-companion') ); } else { // Send JSON Error response to the AJAX call. wp_send_json(esc_html__('No import files specified!', 'af-companion')); } } /** * 2. Import content. * Returns any errors greater then the "error" logger level, that will be displayed on front page. */ $this->frontend_error_messages .= $this->import_content($this->selected_import_files['content']); /** * 3. Before widgets import setup. */ $action = 'af-companion/before_widgets_import'; if ((false !== has_action($action)) && empty($this->frontend_error_messages)) { // Run the before_widgets_import action to setup other settings. $this->do_import_action($action, $this->import_files[$this->selected_index]); } /** * 4. Import widgets. */ if (!empty($this->selected_import_files['widgets']) && empty($this->frontend_error_messages)) { $this->import_widgets($this->selected_import_files['widgets']); } /** * 5. Import customize options. */ if (!empty($this->selected_import_files['customizer']) && empty($this->frontend_error_messages)) { $this->import_customizer($this->selected_import_files['customizer']); } /** * 6. After import setup. */ $action = 'af-companion/after_import'; if ((false !== has_action($action)) && empty($this->frontend_error_messages)) { // Run the after_import action to setup other settings. $this->do_import_action($action, $this->import_files[$this->selected_index]); } // Display final messages (success or error messages). if (empty($this->frontend_error_messages)) { $response['message'] = sprintf( __('%1$sThat\'s it, all done!%2$sThe demo import has finished. Please check your page and make sure that everything has imported correctly. For more other beautiful WordPress products please visit %3$sAF themes%4$s. %5$s', 'af-companion'), '
',
'
',
'',
'',
'
',
'
',
'',
'',
'',
'',
'