'--awo-color1', '--awb-color2' => '--awo-color2', '--awb-color3' => '--awo-color3', '--awb-color4' => '--awo-color4', '--awb-color5' => '--awo-color5', '--awb-color6' => '--awo-color6', '--awb-color7' => '--awo-color7', '--awb-color8' => '--awo-color8', '--awo-color1' => '--awb-color8', '--awo-color2' => '--awb-color7', '--awo-color3' => '--awb-color6', '--awo-color4' => '--awb-color5', '--awo-color5' => '--awb-color4', '--awo-color6' => '--awb-color3', '--awo-color7' => '--awb-color2', '--awo-color8' => '--awb-color1', '-l) -' => '-x) -', '-l) +' => '-l) -', '-x) -' => '-l) +', 'background_blend_mode="lighten' => 'xackground_blend_mode="lighten', 'background_blend_mode="multiply' => 'background_blend_mode="lighten', 'xackground_blend_mode="lighten' => 'background_blend_mode="multiply', ]; /** * Creates or returns an instance of this class. * * @static * @access public * @since 7.4 */ public static function get_instance() { // If an instance hasn't been created and set to $instance create an instance and set it to $instance. if ( null === self::$instance ) { self::$instance = new AWB_Setup_Wizard(); } return self::$instance; } /** * The class constructor * * @access public */ public function __construct() { // Fetches and saves color scheme, typography and maintenance globals. add_action( 'wp_ajax_awb_save_globals', [ $this, 'ajax_save_globals' ] ); // Fetches and saves maintenance globals. add_action( 'wp_ajax_awb_save_globals_maintenance', [ $this, 'ajax_save_globals_maintenance' ] ); // Creates layout sections and assigns. add_action( 'wp_ajax_awb_save_setup_layouts', [ $this, 'ajax_save_layouts' ] ); // Imports setup pages. add_action( 'wp_ajax_awb_import_setup_pages', [ $this, 'ajax_import_pages' ] ); // Finish scratch import. add_action( 'wp_ajax_awb_finalise_scratch_setup', [ $this, 'ajax_finalise_scratch_setup' ] ); // Allow SVG upload in the wizard. add_filter( 'wp_check_filetype_and_ext', [ Avada()->images, 'correct_svg_filetype' ], 10, 5 ); add_filter( 'upload_mimes', [ Avada()->images, 'allow_svg' ], 100 ); if ( ! fusion_doing_ajax() ) { add_action( 'admin_enqueue_scripts', [ $this, 'add_scripts' ] ); } if ( isset( $_GET['page'] ) && 'avada-setup' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended add_filter( 'awb_po_get_value', [ $this, 'global_value' ], 10, 2 ); add_filter( 'awb_po_get_option_name', [ $this, 'global_name' ], 10, 2 ); } } /** * Process the content, replacing logo for example. * * @access public * @since 7.4 * @param mixed $post_data Post data. */ public function process_content( $post_data ) { // Find logo image and replace with text logo or image selection by user. $pattern = get_shortcode_regex( [ 'fusion_imageframe' ] ); $post_data['post_content'] = preg_replace_callback( "/$pattern/", [ $this, 'process_images' ], $post_data['post_content'] ); // Find contact button and use the contact page link. $pattern = get_shortcode_regex( [ 'fusion_button' ] ); $post_data['post_content'] = preg_replace_callback( "/$pattern/", [ $this, 'process_buttons' ], $post_data['post_content'] ); // Find main menu and replace menu ID with created one if we have one. $this->menu_ignore = []; $menu_exists = wp_get_nav_menu_object( $this->menu_name ); if ( $menu_exists ) { $pattern = get_shortcode_regex( [ 'fusion_menu' ] ); $post_data['post_content'] = preg_replace_callback( "/$pattern/", [ $this, 'process_menus' ], $post_data['post_content'] ); } // If we have replaced menus in the content, we don't need to import them, so remove from avada_media. if ( ! empty( $this->menu_ignore ) && isset( $post_data['avada_media']['menus'] ) ) { foreach ( $this->menu_ignore as $menu_slug ) { if ( isset( $post_data['avada_media']['menus'][ $menu_slug ] ) ) { unset( $post_data['avada_media']['menus'][ $menu_slug ] ); } } if ( empty( $post_data['avada_media']['menus'] ) ) { unset( $post_data['avada_media']['menus'] ); } } return $post_data; } /** * Look for the main menu and replace with created menu. * * @access public * @since 7.7 * @param mixed $m The menu. */ public function process_menus( $m ) { global $shortcode_tags; $tag = $m[2]; $attr = shortcode_parse_atts( $m[3] ); // Don't import if menu is flay-out or split. if ( isset( $attr['class'] ) && ( 'avada-flyout-menu' === $attr['class'] || 'avada-split-menu' === $attr['class'] ) ) { $attr['class'] = 'avada-main-menu'; } // Main menu worked out by CSS class. if ( ! isset( $attr['class'] ) || 'avada-main-menu' !== $attr['class'] ) { return $m[0]; } $menu_name = $this->menu_name; // If first menu used, use the second one, for header with split menus. if ( 1 === $this->imported_menus ) { $menu_name = $this->menu_name_2; } $our_menu = wp_get_nav_menu_object( $menu_name ); if ( ! is_object( $our_menu ) ) { return $m[0]; } // No menu set, add it after css class. if ( ! isset( $attr['menu'] ) ) { return str_replace( 'class="avada-main-menu"', 'class="" menu="' . $our_menu->slug . '"', $m[0] ); } // Flag it so the menu is not imported since we don't need it. $this->menu_ignore[] = $attr['menu']; // Increases the imported menus count. $this->imported_menus++; // Menu arg is set, replace. $m[0] = str_replace( 'class="avada-main-menu"', 'class=""', $m[0] ); return str_replace( 'menu="' . $attr['menu'] . '"', 'menu="' . $our_menu->slug . '"', $m[0] ); } /** * Look for buttons and replace markup accordingly. * * @access public * @since 7.7 * @param mixed $m The markup. */ public function process_buttons( $m ) { global $shortcode_tags; $tag = $m[2]; $attr = shortcode_parse_atts( $m[3] ); // check for class. if ( ! isset( $attr['class'] ) || 'avada-contact-button' !== $attr['class'] ) { return $m[0]; } $pages = get_option( 'avada_setup_wizard_new_pages' ); $contact_page_link = isset( $pages['contact'] ) ? get_page_link( $pages['contact'] ) : ''; if ( ! $contact_page_link ) { return $m[0]; } // No link set, add it after css class. if ( ! isset( $attr['link'] ) ) { return str_replace( 'class="avada-contact-button"', 'class="" link="' . $contact_page_link . '"', $m[0] ); } // Link arg is set, replace. $m[0] = str_replace( 'class="avada-contact-button"', 'class=""', $m[0] ); return str_replace( 'link="' . $attr['link'] . '"', 'link="' . $contact_page_link . '"', $m[0] ); } /** * Look for logo images and replace markup accordingly. * * @access public * @since 7.7 * @param mixed $m The markup. */ public function process_images( $m ) { global $shortcode_tags; $tag = $m[2]; $attr = shortcode_parse_atts( $m[3] ); // No dynamic param, its not a logo. if ( ! isset( $attr['dynamic_params'] ) ) { return $m[0]; } $dynamic_params = json_decode( base64_decode( $attr['dynamic_params'] ), true ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions if ( ! isset( $dynamic_params['link']['data'] ) || 'site_url' !== $dynamic_params['link']['data'] ) { return $m[0]; } if ( 'text' === $this->logo_url ) { $color = isset( $dynamic_params['link']['color'] ) && '' !== $dynamic_params['link']['color'] ? $dynamic_params['link']['color'] : 'var(--awb-color8)'; $shortcode_attributes = [ 'font_size' => '36px', 'margin_top' => isset( $attr['margin_top'] ) && '' !== $attr['margin_top'] ? $attr['margin_top'] : '0px', 'margin_bottom' => isset( $attr['margin_bottom'] ) && '' !== $attr['margin_bottom'] ? $attr['margin_bottom'] : '0px', 'content_align' => isset( $attr['align'] ) && '' !== $attr['align'] ? $attr['align'] : 'left', 'title_link' => 'on', 'text_color' => $color, 'link_color' => $color, 'link_hover_color' => $color, 'dynamic_params' => base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions wp_json_encode( [ 'element_content' => [ 'data' => 'site_title' ], 'link_url' => [ 'data' => 'site_url' ], ] ) ), ]; $param_string = ''; foreach ( $shortcode_attributes as $param => $value ) { $param_string .= ' ' . $param . '="' . $value . '"'; } return '[fusion_title' . $param_string . ']' . $this->site_title . '[/fusion_title]'; } $attr['image_id'] = $this->logo_id; $param_string = ''; foreach ( $attr as $param => $value ) { $param_string .= ' ' . $param . '="' . $value . '"'; } return '[fusion_imageframe' . $param_string . ']' . $this->logo_url . '[/fusion_imageframe]'; } /** * Create a menu based on pages that have been created. * * @access public * @since 7.4 * @param mixed $pages The pages. * @param mixed $header_id The header id. */ public function create_menu( $pages = [], $header_id = '' ) { // Create the actual menu. $menu_exists = wp_get_nav_menu_object( $this->menu_name ); if ( $menu_exists ) { wp_delete_nav_menu( $menu_exists ); } $this->menu_id = wp_create_nav_menu( $this->menu_name ); $special_menu = $this->special_menu( $header_id, 'fusion_tb_section' ); $top_item = ''; if ( 'flyout' === $special_menu ) { $top_item_data = [ 'menu-item-title' => 'Icon', 'menu-item-url' => '#', 'menu-item-status' => 'publish', 'menu-item-type' => 'custom', ]; $top_item = wp_update_nav_menu_item( $this->menu_id, 0, $top_item_data ); if ( $top_item && ! is_wp_error( $top_item ) ) { $this->update_fusion_menu_item_meta( $top_item, 'icon', 'fa-bars fas' ); $this->update_fusion_menu_item_meta( $top_item, 'icononly', 'icononly' ); } } if ( 'split' === $special_menu ) { $chunk_size = ceil( count( $pages ) / 2 ); $splitted_pages = array_chunk( $pages, $chunk_size, true ); // Use first chunk to the current menu. $pages = isset( $splitted_pages[0] ) ? $splitted_pages[0] : $pages; // Create new menu for the other side with the second chunk. $menu_exists = wp_get_nav_menu_object( $this->menu_name_2 ); if ( $menu_exists ) { wp_delete_nav_menu( $menu_exists ); } $second_menu_id = wp_create_nav_menu( $this->menu_name_2 ); $second_menu_pages = isset( $splitted_pages[1] ) ? $splitted_pages[1] : []; foreach ( $second_menu_pages as $s_page_id => $s_page_title ) { $s_item_data = [ 'menu-item-title' => esc_html( $s_page_title ), 'menu-item-object' => 'page', 'menu-item-object-id' => (int) str_replace( 'menu-item-', '', $s_page_id ), 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish', ]; wp_update_nav_menu_item( $second_menu_id, 0, $s_item_data ); } } foreach ( $pages as $page_id => $page_title ) { $item_data = [ 'menu-item-title' => esc_html( $page_title ), 'menu-item-object' => 'page', 'menu-item-object-id' => (int) str_replace( 'menu-item-', '', $page_id ), 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish', ]; if ( $top_item && ! is_wp_error( $top_item ) ) { $item_data['menu-item-parent-id'] = $top_item; } wp_update_nav_menu_item( $this->menu_id, 0, $item_data ); } } /** * Create layouts and save layout sections. * * @access public * @since 7.7 */ public function ajax_save_layouts() { // Early exit if AWB is not active. if ( ! class_exists( 'Fusion_Template_Builder' ) || ! class_exists( 'AWB_Studio_Import' ) ) { return wp_send_json_error(); } $this->check_nonce(); $has_setup_run_before = get_option( 'avada_setup_wizard_done', false ); // If its dark mode flip the content variables. $this->dark = isset( $_POST['dark_light'] ) && 'dark' === $_POST['dark_light']; // phpcs:ignore WordPress.Security.NonceVerification $replacements = $this->dark ? $this->color_flip : []; $this->logo_url = isset( $_POST['logo_url'] ) && '' !== $_POST['logo_url'] ? sanitize_text_field( wp_unslash( $_POST['logo_url'] ) ) : 'text'; // phpcs:ignore WordPress.Security.NonceVerification $this->logo_id = isset( $_POST['logo_id'] ) ? sanitize_text_field( wp_unslash( $_POST['logo_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification $this->site_title = isset( $_POST['site_title'] ) ? sanitize_text_field( wp_unslash( $_POST['site_title'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification // Temporary, need to work out how to do this. AWB_Studio_Import()->update_post = true; // Set import options. AWB_Studio_Import()->set_import_options( [ 'images' => 'dont-import-images', ] ); // Layout object. $layouts = Fusion_Template_Builder(); $global_layout = $layouts::get_default_layout(); // Import header. $header_id = isset( $_POST['header'] ) && ! empty( $_POST['header'] ) ? sanitize_text_field( wp_unslash( $_POST['header'] ) ) : '2157'; // phpcs:ignore WordPress.Security.NonceVerification $header_options = isset( $_POST['header_options'] ) && ! empty( $_POST['header_options'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['header_options'] ) ), true ) : []; // phpcs:ignore WordPress.Security.NonceVerification // Set import options. AWB_Studio_Import()->set_import_options( [ 'type' => isset( $header_options['overwrite-type'] ) ? $header_options['overwrite-type'] : 'inherit', 'images' => isset( $header_options['images'] ) ? $header_options['images'] : 'do-import-images', 'invert' => isset( $header_options['invert'] ) ? $header_options['invert'] : 'dont-invert', ] ); $post_details = AWB_Studio_Import()->import_post( [ 'post_id' => $header_id, 'post_type' => 'fusion_tb_section', ], [], true, $replacements ); $global_layout['template_terms']['header'] = $post_details['post_id']; // Import footer. $footer_id = isset( $_POST['footer'] ) && ! empty( $_POST['footer'] ) ? sanitize_text_field( wp_unslash( $_POST['footer'] ) ) : '2160'; // phpcs:ignore WordPress.Security.NonceVerification $footer_options = isset( $_POST['footer_options'] ) && ! empty( $_POST['footer_options'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['footer_options'] ) ), true ) : []; // phpcs:ignore WordPress.Security.NonceVerification // Set import options. AWB_Studio_Import()->set_import_options( [ 'type' => isset( $footer_options['overwrite-type'] ) ? $footer_options['overwrite-type'] : 'inherit', 'images' => isset( $footer_options['images'] ) ? $footer_options['images'] : 'do-import-images', 'invert' => isset( $footer_options['invert'] ) ? $footer_options['invert'] : 'dont-invert', ] ); $post_details = AWB_Studio_Import()->import_post( [ 'post_id' => $footer_id, 'post_type' => 'fusion_tb_section', ], [], true, $replacements ); $global_layout['template_terms']['footer'] = $post_details['post_id']; // Import hidden layouts ( search & 404 ). $hidden_layouts = [ 'section_layouts' => [ [ 'title' => __( 'Search Page Content', 'Avada' ), 'studio_id' => 2233, ], [ 'title' => __( '404 Page Content', 'Avada' ), 'studio_id' => 2232, ], ], 'layouts' => [ [ 'title' => __( 'Search Page', 'Avada' ), 'template_terms' => [ 'content' => 2233, ], 'conditions' => [ 'search_results' => [ 'label' => 'Search Results', 'type' => 'archives', 'mode' => 'include', 'archives' => 'search_results', ], ], ], [ 'title' => __( '404 Page', 'Avada' ), 'template_terms' => [ 'content' => 2232, ], 'conditions' => [ 'not_found' => [ 'label' => '404 Page', 'type' => 'singular', 'mode' => 'include', 'singular' => 'not_found', ], ], ], ], ]; if ( isset( $hidden_layouts['section_layouts'] ) && is_array( $hidden_layouts['section_layouts'] ) ) { foreach ( $hidden_layouts['section_layouts'] as $hl_section ) { $hl_section_title = isset( $hl_section['title'] ) ? $hl_section['title'] : ''; $hl_section_studio_id = isset( $hl_section['studio_id'] ) ? $hl_section['studio_id'] : ''; $hl_section_post_type = 'fusion_tb_section'; AWB_Studio_Import()->import_post( [ 'post_id' => $hl_section_studio_id, 'post_type' => $hl_section_post_type, ], [ 'post_title' => $hl_section_title, ], true, $replacements ); } } if ( $hidden_layouts['layouts'] && is_array( $hidden_layouts['layouts'] ) && ! $has_setup_run_before ) { foreach ( $hidden_layouts['layouts'] as $hl_layout ) { $hl_layout_title = isset( $hl_layout['title'] ) ? $hl_layout['title'] : ''; $hl_layout_template_terms = isset( $hl_layout['template_terms'] ) ? $hl_layout['template_terms'] : []; $hl_layout_conditions = isset( $hl_layout['conditions'] ) ? $hl_layout['conditions'] : []; // get the curren template terms IDs. $hl_updated_template_terms = []; foreach ( $hl_layout_template_terms as $template_name => $template_id ) { $args = [ 'post_type' => 'fusion_tb_section', 'meta_key' => '_avada_studio_post', // phpcs:ignore WordPress.DB.SlowDBQuery 'meta_value' => $template_id, // phpcs:ignore WordPress.DB.SlowDBQuery ]; $template_query = new WP_Query( $args ); if ( $template_query->have_posts() ) { $hl_updated_template_terms[ $template_name ] = $template_query->posts[0]->ID; } } $this->add_layout( $hl_layout_title, $hl_updated_template_terms, $hl_layout_conditions ); } } // Set content imported to true to avoid multiple imports. update_option( 'avada_setup_wizard_done', true ); // Update global layout selection. $layouts::update_default_layout( $global_layout ); wp_send_json_success(); } /** * Imports selected pages. * * @access public * @since 7.7 */ public function ajax_import_pages() { // Early exit if AWB is not active. if ( ! class_exists( 'Fusion_Template_Builder' ) || ! class_exists( 'AWB_Studio_Import' ) ) { return wp_send_json_error(); } $this->check_nonce(); // Temporary, need to work out how to do this. AWB_Studio_Import()->update_post = true; // Set import options. AWB_Studio_Import()->set_import_options( [ 'images' => 'dont-import-images', ] ); // For dummy content import. $pages = isset( $_POST['pages'] ) ? wp_unslash( $_POST['pages'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $this->dark = isset( $_POST['dark_light'] ) && 'dark' === $_POST['dark_light']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $dummy_content = isset( $_POST['dummy_content'] ) ? wp_unslash( $_POST['dummy_content'] ) : false; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $scheme = isset( $_POST['scheme'] ) ? wp_unslash( $_POST['scheme'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $header_id = isset( $_POST['header'] ) && ! empty( $_POST['header'] ) ? sanitize_text_field( wp_unslash( $_POST['header'] ) ) : '2157'; // phpcs:ignore WordPress.Security.NonceVerification $is_dummy_content_imported = get_option( 'avada_setup_wizard_dummy_content', false ); $has_setup_run_before = get_option( 'avada_setup_wizard_done', false ); $this->menu_items = []; $new_pages = []; // If its dark mode flip the content variables. $replacements = $this->dark ? $this->color_flip : []; if ( 'true' === $dummy_content ) { $this->svg_dynamic_placeholder( $scheme ); if ( $is_dummy_content_imported ) { $this->update_dummy_content_image( $pages ); } else { // Add dummy content. $this->import_dummy_content( $pages, $scheme ); } } // For pages import. foreach ( $pages as $page ) { $context = isset( $page['id'] ) ? $page['id'] : ''; $title = isset( $page['title'] ) ? $page['title'] : ''; $studio_id = isset( $page['studio_id'] ) ? $page['studio_id'] : ''; $post_type = isset( $page['post_type'] ) ? $page['post_type'] : 'page'; $content_pages = isset( $page['pages'] ) ? $page['pages'] : ''; $section_layouts = isset( $page['section_layouts'] ) ? $page['section_layouts'] : ''; $layouts = isset( $page['layouts'] ) ? $page['layouts'] : ''; $content = isset( $page['content'] ) ? $page['content'] : ''; if ( $studio_id ) { $new_page = AWB_Studio_Import()->import_post( [ 'post_id' => $studio_id, 'post_type' => 'fusion_template', ], [ 'post_type' => $post_type, 'post_title' => $title, ], true, $replacements ); } else { if ( 'shop' === $context ) { $shop_page_id = get_option( 'woocommerce_shop_page_id' ); $cart_page_id = get_option( 'woocommerce_cart_page_id' ); $checkout_page_id = get_option( 'woocommerce_checkout_page_id' ); if ( $shop_page_id ) { $new_page = [ 'post_id' => $shop_page_id, ]; } else { // Shop page. $new_page = $this->insert_post( $title, $content, $post_type ); $shop_page_id = (int) $new_page['post_id']; update_option( 'woocommerce_shop_page_id', $shop_page_id ); } if ( ! $cart_page_id ) { $cart_page = $this->insert_post( __( 'Cart', 'Avada' ), '[woocommerce_cart]', 'page' ); $cart_page_id = (int) $cart_page['post_id']; update_option( 'woocommerce_cart_page_id', (int) $cart_page['post_id'] ); } if ( ! $checkout_page_id ) { $cart_page = $this->insert_post( __( 'Checkout', 'Avada' ), '[woocommerce_checkout]', 'page' ); $checkout_page_id = (int) $cart_page['post_id']; update_option( 'woocommerce_checkout_page_id', (int) $cart_page['post_id'] ); } $shop_studio_id = isset( $page['shop'] ) ? $page['shop'] : ''; $cart_studio_id = isset( $page['cart'] ) ? $page['cart'] : ''; $checkout_studio_id = isset( $page['checkout'] ) ? $page['checkout'] : ''; // Import cart page. if ( $shop_studio_id ) { AWB_Studio_Import()->import_post( [ 'post_id' => $shop_studio_id, 'post_type' => 'fusion_template', ], [ 'post_id' => $shop_page_id, 'post_type' => 'page', 'post_title' => $title, ], true, $replacements ); fusion_data()->post_meta( $shop_page_id )->set( 'show_wc_shop_loop', 'no' ); } // Import cart page. if ( $cart_studio_id ) { AWB_Studio_Import()->import_post( [ 'post_id' => $cart_studio_id, 'post_type' => 'fusion_template', ], [ 'post_id' => $cart_page_id, 'post_type' => 'page', 'post_title' => __( 'Cart', 'Avada' ), ], true, $replacements ); } // Import checkout page. if ( $checkout_studio_id ) { AWB_Studio_Import()->import_post( [ 'post_id' => $checkout_studio_id, 'post_type' => 'fusion_template', ], [ 'post_id' => $checkout_page_id, 'post_type' => 'page', 'post_title' => __( 'Checkout', 'Avada' ), ], true, $replacements ); } } else { $new_page = $this->insert_post( $title, $content, $post_type ); } } if ( 'homepage' === $context ) { update_option( 'page_on_front', (int) $new_page['post_id'] ); update_option( 'show_on_front', 'page' ); } $this->menu_items[ 'menu-item-' . (string) $new_page['post_id'] ] = $title; // If starter header don't add contact page to the menu. if ( '2157' === $header_id && 'contact' === $context ) { unset( $this->menu_items[ 'menu-item-' . (string) $new_page['post_id'] ] ); } $new_pages[ $context ] = (int) $new_page['post_id']; // Insert Pages if exists. if ( $content_pages && is_array( $content_pages ) ) { foreach ( $content_pages as $page ) { $page_title = isset( $page['title'] ) ? $page['title'] : ''; $page_content = isset( $page['content'] ) ? $page['content'] : ''; $page_post_type = 'page'; $new_page = $this->insert_post( $page_title, $page_content, $page_post_type ); } } // Insert Section layouts if exists. if ( $section_layouts && is_array( $section_layouts ) ) { foreach ( $section_layouts as $section ) { $section_title = isset( $section['title'] ) ? $section['title'] : ''; $section_studio_id = isset( $section['studio_id'] ) ? $section['studio_id'] : ''; $section_post_type = 'fusion_tb_section'; AWB_Studio_Import()->import_post( [ 'post_id' => $section_studio_id, 'post_type' => $section_post_type, ], [ 'post_title' => $section_title, ], true, $replacements ); } } // Insert Layouts if exists. if ( $layouts && is_array( $layouts ) && ! $has_setup_run_before ) { foreach ( $layouts as $layout ) { $layout_title = isset( $layout['title'] ) ? $layout['title'] : ''; $layout_template_terms = isset( $layout['template_terms'] ) ? $layout['template_terms'] : []; $layout_conditions = isset( $layout['conditions'] ) ? $layout['conditions'] : []; // get the curren template terms IDs. $updated_template_terms = []; foreach ( $layout_template_terms as $template_name => $template_id ) { $args = [ 'post_type' => 'fusion_tb_section', 'meta_key' => '_avada_studio_post', // phpcs:ignore WordPress.DB.SlowDBQuery 'meta_value' => $template_id, // phpcs:ignore WordPress.DB.SlowDBQuery ]; $template_query = new WP_Query( $args ); if ( $template_query->have_posts() ) { $updated_template_terms[ $template_name ] = $template_query->posts[0]->ID; } } $this->add_layout( $layout_title, $updated_template_terms, $layout_conditions ); } } } // Create the menu. if ( ! empty( $this->menu_items ) ) { $this->create_menu( $this->menu_items, $header_id ); } // Temporary save new pages. update_option( 'avada_setup_wizard_new_pages', $new_pages ); wp_send_json_success(); } /** * Sets site's title and description, clears cache, flushes permalinks and etc. * * @access public * @since 7.7 */ public function ajax_finalise_scratch_setup() { $this->check_nonce(); $this->site_title = isset( $_POST['site_title'] ) ? sanitize_text_field( wp_unslash( $_POST['site_title'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification $site_tagline = isset( $_POST['site_tagline'] ) ? sanitize_text_field( wp_unslash( $_POST['site_tagline'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification // Update site details. update_option( 'blogname', $this->site_title ); update_option( 'blogdescription', $site_tagline ); // Delete temporary options. delete_option( 'avada_setup_wizard_new_pages' ); // Clear cache. fusion_reset_all_caches(); // Flush permalinks. flush_rewrite_rules(); wp_send_json_success(); } /** * Is string JSON? * * @access public * @since 3.7 * @param string $string The string. * @return boolean */ public function is_json( $string ) { if ( is_array( $string ) ) { return false; } json_decode( $string ); return JSON_ERROR_NONE === json_last_error(); } /** * Save color, typography and maintenance global options. * * @access public * @since 7.7 */ public function ajax_save_globals() { $this->check_nonce(); $scheme = isset( $_POST['scheme'] ) ? wp_unslash( $_POST['scheme'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $typo_set = isset( $_POST['typo_set'] ) ? wp_unslash( $_POST['typo_set'] ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $ratio = isset( $_POST['sizing_ratio'] ) ? (float) $_POST['sizing_ratio'] : 1.333; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput, WordPress.Security.NonceVerification $base = isset( $_POST['base_size'] ) ? (float) $_POST['base_size'] : 16; // phpcs:ignore WordPress.Security.NonceVerification $maintenance = isset( $_POST['maintenance'] ) ? wp_unslash( $_POST['maintenance'] ) : 'false'; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput $dark = ( isset( $_POST['dark_light'] ) && 'dark' === $_POST['dark_light'] ); // phpcs:ignore WordPress.Security.NonceVerification $sizes['h6_typography'] = $base; $sizes['h5_typography'] = ceil( $sizes['h6_typography'] * $ratio ); $sizes['h4_typography'] = ceil( $sizes['h5_typography'] * $ratio ); $sizes['h3_typography'] = ceil( $sizes['h4_typography'] * $ratio ); $sizes['h2_typography'] = ceil( $sizes['h3_typography'] * $ratio ); $sizes['h1_typography'] = ceil( $sizes['h2_typography'] * $ratio ); $small_size = ceil( 0.8125 * $base ); $subheading_size = ceil( 1.5 * $base ); $light_colors_1 = [ 'awb-color1', 'awb-color2', 'awb-color3', 'awb-color4', ]; $light_colors_2 = [ 'awb-color5', 'awb-color6', 'awb-color7', 'awb-color8', ]; $dark_colors_1 = array_reverse( $light_colors_2 ); $dark_colors_2 = array_reverse( $light_colors_1 ); $avada_options = apply_filters( 'fusion_settings_all_fields', [] ); $saved_options = get_option( Fusion_Settings::get_option_name(), [] ); $saved_options_are_empty = ( empty( $saved_options ) ? true : false ); // Set typography and colors back to variables. For dark mode flip and also set heading font size. foreach ( $avada_options as $option ) { if ( 'typography' === $option['type'] ) { // No value saved, it is an array. if ( ! isset( $saved_options[ $option['id'] ] ) ) { $saved_options[ $option['id'] ] = []; } // Set each value from default. if ( is_array( $option['default'] ) ) { foreach ( $option['default'] as $param => $value ) { if ( 'color' === $param && $dark ) { $saved_options[ $option['id'] ][ $param ] = str_replace( $light_colors_1, $dark_colors_1, $value ); // Unchanged, try second half of colors. Split to avoid double replacing. if ( $saved_options[ $option['id'] ][ $param ] === $value ) { $saved_options[ $option['id'] ][ $param ] = str_replace( $light_colors_2, $dark_colors_2, $value ); } } else { $saved_options[ $option['id'] ][ $param ] = $value; } } } // Set font size based on scale. if ( isset( $sizes[ $option['id'] ] ) ) { $saved_options[ $option['id'] ]['font-size'] = (string) round( $sizes[ $option['id'] ], 2 ) . 'px'; } } elseif ( ( 'color-alpha' === $option['type'] || 'color' === $option['type'] ) && isset( $option['default'] ) ) { if ( $dark ) { $saved_options[ $option['id'] ] = str_replace( $light_colors_1, $dark_colors_1, $option['default'] ); // Unchanged, try second half of colors. Split to avoid double replacing. if ( $saved_options[ $option['id'] ] === $option['default'] ) { $saved_options[ $option['id'] ] = str_replace( $light_colors_2, $dark_colors_2, $option['default'] ); } // Reverse the lightness if necessary. if ( false !== strpos( $saved_options[ $option['id'] ], 'hsla' ) ) { $hsla_flip = [ '-l) -' => '-x) -', '-l) +' => '-l) -', '-x) -' => '-l) +', ]; $saved_options[ $option['id'] ] = str_replace( array_keys( $hsla_flip ), array_values( $hsla_flip ), $saved_options[ $option['id'] ] ); } } else { $saved_options[ $option['id'] ] = $option['default']; } } elseif ( isset( $option['default'] ) && $saved_options_are_empty ) { $saved_options[ $option['id'] ] = $option['default']; } } // Set the color palette. $saved_options['color_palette'] = AWB_Global_Colors()->get_palette(); foreach ( $scheme as $color_slug => $value ) { if ( ! is_array( $value ) ) { $value = []; } if ( ! isset( $value['color'] ) ) { $value['color'] = '#ffffff'; } if ( ! isset( $value['label'] ) ) { $value['label'] = __( 'Color', 'Avada' ); } $saved_options['color_palette'][ $color_slug ] = $value; } // Map the option naming. $set_data = [ 'headings' => 'typography1', 'subheadings' => 'typography2', 'lead' => 'typography3', 'body' => 'typography4', 'small' => 'typography5', ]; // Set the typography sets. $saved_options['typography_sets'] = AWB_Global_Typography()->get_typography(); foreach ( $typo_set as $subset => $data ) { $set_name = $set_data[ $subset ]; // We only want italic as style. $data['font-style'] = isset( $data['font-style'] ) && 'italic' === $data['font-style'] ? 'italic' : ''; foreach ( $data as $param => $value ) { $set_parameter = str_replace( '_', '-', $param ); $set_value = $value; if ( 'font-size' === $set_parameter ) { if ( 'body' === $subset || 'lead' === $subset ) { $set_value = round( $base, 2 ) . 'px'; } if ( 'headings' === $subset ) { $set_value = round( $sizes['h1_typography'], 2 ) . 'px'; } if ( 'subheadings' === $subset ) { $set_value = $subheading_size . 'px'; } if ( 'small' === $subset ) { $set_value = $small_size . 'px'; } } $saved_options['typography_sets'][ $set_name ][ $set_parameter ] = $set_value; } $saved_options['typography_sets'][ $set_name ]['variant'] = (int) $saved_options['typography_sets'][ $set_name ]['font-weight'] . $data['font-style']; } if ( 'true' === $maintenance ) { $saved_options['maintenance_mode'] = 'coming_soon'; $saved_options['maintenance_template'] = '0'; $saved_options['maintenance_user_roles'] = [ 'administrator' ]; } // Save the new globals. update_option( Fusion_Settings::get_option_name(), $saved_options ); wp_send_json_success( $saved_options ); } /** * Save maintenance global options. * * @access public * @since 7.9 * @return void */ public function ajax_save_globals_maintenance() { $this->check_nonce(); $is_updated = false; $maintenance = isset( $_POST['maintenance'] ) ? wp_unslash( $_POST['maintenance'] ) : 'false'; // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput if ( 'true' === $maintenance ) { $saved_options = get_option( Fusion_Settings::get_option_name(), [] ); $saved_options['maintenance_mode'] = 'coming_soon'; $saved_options['maintenance_template'] = '0'; $saved_options['maintenance_user_roles'] = [ 'administrator' ]; // Save the new globals. update_option( Fusion_Settings::get_option_name(), $saved_options ); $is_updated = true; } wp_send_json_success( $is_updated ); } /** * Return global value instead of usual page option. * * @access public * @param string $value The value. * @param int $id The ID. * @return string */ public function global_value( $value, $id ) { $settings = awb_get_fusion_settings(); return $settings->get( $id ); } /** * Override root so IDs are correct. * * @access public * @param string $name The name. * @param int $id The ID. * @return string */ public function global_name( $name, $id ) { return str_replace( '[]', '', ltrim( $id, '_' ) ); } /** * Enequeue required scripts. * * @access public * @return void */ public function add_scripts() { $version = Avada::get_theme_version(); wp_enqueue_style( 'awb_wizard_css', trailingslashit( Avada::$template_dir_url ) . 'assets/admin/css/awb-wizard.css', [], $version ); wp_enqueue_style( 'awb_setup_css', trailingslashit( Avada::$template_dir_url ) . 'assets/admin/css/awb-setup-wizard.css', [], $version ); wp_enqueue_script( 'webfont-loader', FUSION_LIBRARY_URL . '/inc/fusion-app/assets/js/webfontloader.js', [], '1.6.28', false ); wp_register_script( 'fuse-script', FUSION_LIBRARY_URL . '/assets/min/js/library/fuse.js', [], AVADA_VERSION, true ); wp_enqueue_script( 'lazysizes', FUSION_LIBRARY_URL . '/assets/min/js/library/lazysizes.js', [], AVADA_VERSION, true ); wp_register_script( 'awb-studio-modal', Avada::$template_dir_url . '/assets/admin/js/awb-studio-modal.js', [ 'jquery', 'fuse-script' ], $version, false ); AWB_Global_Colors()->enqueue(); AWB_Global_Typography()->enqueue(); wp_enqueue_script( 'awb_setup_js', trailingslashit( Avada::$template_dir_url ) . 'assets/admin/js/awb-setup-wizard.js', [ 'jquery', 'webfont-loader', 'fuse-script', 'wp-util', 'shortcode', 'awb-studio-modal', 'jquery-color' ], $version, true ); wp_localize_script( 'awb_setup_js', 'fusionBuilderText', fusion_app_textdomain_strings() ); wp_localize_script( 'awb_setup_js', 'awbSetup', [ 'saveChange' => __( 'Do you want to proceed without saving changes?', 'Avada' ), 'isRegistered' => Avada()->registration->is_registered(), 'studioData' => class_exists( 'AWB_Studio' ) ? AWB_Studio()->get_data() : [], 'studioURL' => class_exists( 'AWB_Studio' ) ? AWB_Studio()->get_studio_url() : '', 'colors404Message' => __( 'Sorry, the color schemes couldn\'t load because the server didn\'t respond.', 'Avada' ), ] ); wp_enqueue_script( 'jquery.biscuit', Avada::$template_dir_url . '/assets/admin/js/jquery.biscuit.js', [ 'jquery' ], $version, false ); wp_register_script( 'avada_upload', Avada::$template_dir_url . '/assets/admin/js/upload.js', [ 'jquery' ], $version, false ); wp_enqueue_media(); // Select field assets. wp_dequeue_script( 'tribe-events-select2' ); wp_enqueue_style( 'select2-css', Avada::$template_dir_url . '/assets/admin/css/select2.css', [], $version, 'all' ); wp_enqueue_script( 'selectwoo-js', Avada::$template_dir_url . '/assets/admin/js/selectWoo.full.min.js', [ 'jquery' ], $version, false ); // Range field assets. wp_enqueue_style( 'avadaredux-nouislider-css', FUSION_LIBRARY_URL . '/inc/redux/framework/FusionReduxCore/inc/fields/slider/vendor/nouislider/fusionredux.jquery.nouislider.css', [], $version, 'all' ); wp_enqueue_script( 'avadaredux-nouislider-js', Avada::$template_dir_url . '/assets/admin/js/jquery.nouislider.min.js', [ 'jquery' ], $version, true ); wp_enqueue_script( 'wnumb-js', Avada::$template_dir_url . '/assets/admin/js/wNumb.js', [ 'jquery' ], $version, true ); // Color fields. if ( function_exists( 'AWB_Global_Colors' ) ) { AWB_Global_Colors()->enqueue(); } // Option type JS. wp_enqueue_script( 'avada-fusion-options', Avada::$template_dir_url . '/assets/admin/js/avada-fusion-options.js', [ 'jquery', 'jquery-ui-sortable', 'avada_upload' ], $version, false ); // Studio preview. wp_enqueue_script( 'fusion-admin-notices', trailingslashit( Fusion_Scripts::$js_folder_url ) . 'general/awb-studio-preview-admin.js', [ 'jquery' ], $version, false ); } /** * Check if nonce is valid. * * @access public */ public function check_nonce() { check_admin_referer( 'awb_setup_nonce', 'awb_setup_nonce' ); } /** * Get typography CSS variables for data. * * @access public * @param array $data The data. */ public function get_typo_vars( $data = [] ) { $variables = 'style="'; foreach ( $data as $key => $values ) { if ( ! empty( $values ) && is_array( $values ) ) { foreach ( $values as $param => $value ) { if ( '' !== $value ) { $variables .= '--' . $key . '_' . $param . ':' . $value . ';'; } } } } return $variables . '"'; } /** * Get typography set data. * * @access public */ public function get_typo_sets() { global $wp_filesystem; if ( null !== $this->typo_data ) { return $this->typo_data; } $response = wp_remote_get( 'https://updates.theme-fusion.com/wp-json/setup_data/typography/', [ 'user-agent' => 'avada-user-agent', ] ); // Check for error. if ( ! is_wp_error( $response ) ) { $response_code = (int) wp_remote_retrieve_response_code( $response ); if ( 200 !== $response_code ) { $this->typo_data = []; return $this->typo_data; } // Parse response. $data = wp_remote_retrieve_body( $response ); // Check for error. if ( '' !== $data ) { $this->typo_data = json_decode( $data, true ); return $this->typo_data; } } return []; } /** * Render header specifically for wizard. * * @param string $screen_classes Classes for page. * @return void */ public function render_header( $screen_classes ) { ?>