init_globals(); $this->init_actions(); } /** * Get the site logo URL. * * @see Envato_Theme_Setup_Wizard::instance() * * @since 3.15.2 * @access public */ public function get_site_logo() { $image_url = get_template_directory_uri().'/assets/img/logo.png'; $site_logo = do_shortcode(get_theme_mod( 'site_logo', $image_url)); if (is_numeric($site_logo)) { $image_src = wp_get_attachment_image_src($site_logo, 'large'); if (!empty($image_src)) { $image_url = $image_src[0]; } } else if (is_string($site_logo)) { $image_url = $site_logo; } return apply_filters('envato_setup_logo_image',$image_url); } /** * Get the default style. Can be overriden by theme init scripts. * * @see Envato_Theme_Setup_Wizard::instance() * * @since 1.1.9 * @access public */ public function get_header_logo_width(){ return '200px'; } /** * Setup the class globals. * * @since 1.1.1 * @access public */ public function init_globals() { $current_theme = wp_get_theme(); $this->theme_name = strtolower( preg_replace( '#[^a-zA-Z]#','',$current_theme->get( 'Name' ) ) ); $this->page_slug = apply_filters( 'flatsome_theme_setup_wizard_page_slug', 'flatsome-setup' ); $this->parent_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_parent_slug', '' ); //If we have parent slug - set correct url if( $this->parent_slug !== '' ){ $this->page_url = 'admin.php?page='.$this->page_slug; }else{ $this->page_url = 'admin.php?page='.$this->page_slug; } $this->page_url = apply_filters( $this->theme_name . '_theme_setup_wizard_page_url', $this->page_url ); //set relative plugin path url $this->plugin_path = trailingslashit( $this->cleanFilePath( dirname( __FILE__ ) ) ); $relative_url = str_replace( $this->cleanFilePath( get_template_directory() ), '', $this->plugin_path ); $this->plugin_url = trailingslashit( get_template_directory_uri() . $relative_url ); } /** * Setup the hooks, actions and filters. * * @uses add_action() To add actions. * @uses add_filter() To add filters. * * @since 1.1.1 * @access public */ public function init_actions() { if ( apply_filters( $this->theme_name . '_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) { if(!is_child_theme()){ add_action( 'after_switch_theme', array( $this, 'switch_theme' ) ); } if(class_exists( 'TGM_Plugin_Activation' ) && isset($GLOBALS['tgmpa'])) { add_action( 'init', array( $this, 'get_tgmpa_instanse' ), 30 ); add_action( 'init', array( $this, 'set_tgmpa_url' ), 40 ); } add_action( 'admin_menu', array( $this, 'admin_menus' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_init', array( $this, 'admin_redirects' ), 30 ); add_action( 'admin_init', array( $this, 'init_wizard_steps' ), 30 ); add_action( 'admin_init', array( $this, 'setup_wizard' ), 30 ); add_filter( 'tgmpa_load', array( $this, 'tgmpa_load' ), 10, 1 ); add_action( 'wp_ajax_envato_setup_plugins', array( $this, 'ajax_plugins' ) ); add_action( 'wp_ajax_envato_setup_content', array( $this, 'ajax_content' ) ); } add_action('upgrader_post_install', array($this,'upgrader_post_install'), 10, 2); } /** * After a theme update we clear the setup_complete option. This prompts the user to visit the update page again. * * @since 1.1.8 * @access public */ public function upgrader_post_install($return, $theme) { if ( is_wp_error( $return ) ) { return $return; } if ( $theme != get_stylesheet() ) { return $return; } update_option( 'envato_setup_complete', false ); return $return; } /** * We determine if the user already has theme content installed. This can happen if swapping from a previous theme or updated the current theme. We change the UI a bit when updating / swapping to a new theme. * * @since 1.1.8 * @access public */ public function is_possible_upgrade(){ return false; } public function enqueue_scripts() { } public function tgmpa_load( $status ) { return is_admin() || current_user_can( 'install_themes' ); } public function switch_theme() { set_transient( '_'.$this->theme_name.'_activation_redirect', 1 ); } public function admin_redirects() { ob_start(); if ( ! get_transient( '_'.$this->theme_name.'_activation_redirect' ) || get_option( 'envato_setup_complete', false ) ) { return; } delete_transient( '_'.$this->theme_name.'_activation_redirect' ); if(flatsome_is_upgrading()){ wp_safe_redirect( admin_url('admin.php?page=flatsome-panel') ); } else { wp_safe_redirect( admin_url( $this->page_url ) ); } exit; } /** * Get configured TGMPA instance * * @access public * @since 1.1.2 */ public function get_tgmpa_instanse(){ $this->tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); } /** * Update $tgmpa_menu_slug and $tgmpa_parent_slug from TGMPA instance * * @access public * @since 1.1.2 */ public function set_tgmpa_url(){ $this->tgmpa_menu_slug = ( property_exists($this->tgmpa_instance, 'menu') ) ? $this->tgmpa_instance->menu : $this->tgmpa_menu_slug; $this->tgmpa_menu_slug = apply_filters($this->theme_name . '_theme_setup_wizard_tgmpa_menu_slug', $this->tgmpa_menu_slug); $tgmpa_parent_slug = ( property_exists($this->tgmpa_instance, 'parent_slug') && $this->tgmpa_instance->parent_slug !== 'themes.php' ) ? 'admin.php' : 'themes.php'; $this->tgmpa_url = apply_filters($this->theme_name . '_theme_setup_wizard_tgmpa_url', $tgmpa_parent_slug.'?page='.$this->tgmpa_menu_slug); } /** * Add admin menus/screens. */ public function admin_menus() { add_submenu_page('flatsome-panel', __( 'Setup Wizard','envato_setup' ), __( 'Setup Wizard','envato_setup' ), 'manage_options', $this->page_slug, array( $this, $this->page_slug) ); } /** * Setup steps. * * @since 1.1.1 * @access public * @return array */ public function init_wizard_steps() { $this->steps = array( 'introduction' => array( 'name' => __( 'Introduction', 'envato_setup' ), 'view' => array( $this, 'envato_setup_introduction' ), 'handler' => array( $this, 'envato_setup_introduction_save' ), ), ); $this->steps['updates'] = array( 'name' => __( 'Register', 'envato_setup' ), 'view' => array( $this, 'envato_setup_updates' ), 'handler' => array( $this, 'envato_setup_updates_save' ), ); $this->steps['customize'] = array( 'name' => __( 'Child Theme', 'envato_setup' ), 'view' => array( $this, 'envato_setup_customize' ), 'handler' => '', ); if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) { $this->steps['default_plugins'] = array( 'name' => __( 'Plugins', 'envato_setup' ), 'view' => array( $this, 'envato_setup_default_plugins' ), 'handler' => '', ); } $this->steps['default_content'] = array( 'name' => __( 'Content', 'envato_setup' ), 'view' => array( $this, 'envato_setup_default_content' ), 'handler' => '', ); $this->steps['design'] = array( 'name' => __( 'Logo & Design', 'envato_setup' ), 'view' => array( $this, 'envato_setup_logo_design' ), 'handler' => array( $this, 'envato_setup_logo_design_save' ), ); $this->steps['help_support'] = array( 'name' => __( 'Support', 'envato_setup' ), 'view' => array( $this, 'envato_setup_help_support' ), 'handler' => '', ); $this->steps['next_steps'] = array( 'name' => __( 'Ready!', 'envato_setup' ), 'view' => array( $this, 'envato_setup_ready' ), 'handler' => '', ); $this->steps = apply_filters( $this->theme_name . '_theme_setup_wizard_steps', $this->steps ); } /** * Show the setup wizard */ public function setup_wizard() { if ( empty( $_GET['page'] ) || $this->page_slug !== $_GET['page'] ) { return; } ob_end_clean(); $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); wp_register_script( 'jquery-blockui', $this->plugin_url . 'js/jquery.blockUI.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'envato-setup', $this->plugin_url . 'js/envato-setup.js', array( 'jquery', 'jquery-blockui' ), $this->version ); wp_localize_script( 'envato-setup', 'envato_setup_params', array( 'tgm_plugin_nonce' => array( 'update' => wp_create_nonce( 'tgmpa-update' ), 'install' => wp_create_nonce( 'tgmpa-install' ), ), 'tgm_bulk_url' => admin_url( $this->tgmpa_url ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'wpnonce' => wp_create_nonce( 'envato_setup_nonce' ), 'verify_text' => __( '...verifying','envato_setup' ), ) ); //wp_enqueue_style( 'envato_wizard_admin_styles', $this->plugin_url . '/css/admin.css', array(), $this->version ); wp_enqueue_style( 'envato-setup', $this->plugin_url . 'css/envato-setup.css', array( 'wp-admin', 'dashicons', 'install' ), $this->version ); //enqueue style for admin notices wp_enqueue_style( 'wp-admin' ); wp_enqueue_media(); wp_enqueue_script( 'media' ); ob_start(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $show_content = true; echo '
default.json:
widget_positions.json
widget_options.json:
menu.json:
options.json:
Copy these values into your PHP code when distributing/updating the theme.
is_possible_upgrade() ){ ?>It should only take 3-5 minutes.' ), wp_get_theme()); ?>
get_results( "SELECT * FROM $wpdb->posts WHERE post_title = '$str' ", OBJECT ); if($posts) return $posts[0]->ID; } private function _get_plugins() { $instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); $plugins = array( 'all' => array(), // Meaning: all plugins which still have open actions. 'install' => array(), 'update' => array(), 'activate' => array(), ); foreach ( $instance->plugins as $slug => $plugin ) { if ( $instance->is_plugin_active( $slug ) && false === $instance->does_plugin_have_update( $slug ) ) { // No need to display plugins if they are installed, up-to-date and active. continue; } else { $plugins['all'][ $slug ] = $plugin; if ( ! $instance->is_plugin_installed( $slug ) ) { $plugins['install'][ $slug ] = $plugin; } else { if ( false !== $instance->does_plugin_have_update( $slug ) ) { $plugins['update'][ $slug ] = $plugin; } if ( $instance->can_plugin_activate( $slug ) ) { $plugins['activate'][ $slug ] = $plugin; } } } } return $plugins; } /** * Page setup */ public function envato_setup_default_plugins() { tgmpa_load_bulk_installer(); // install plugins with TGM. if ( ! class_exists( 'TGM_Plugin_Activation' ) || ! isset( $GLOBALS['tgmpa'] ) ) { die( 'Failed to find TGM' ); } $url = wp_nonce_url( add_query_arg( array( 'plugins' => 'go' ) ), 'envato-setup' ); $plugins = $this->_get_plugins(); // copied from TGM $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. $fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem. if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) { return true; // Stop the normal page form from displaying, credential request form will be shown. } // Now we have some credentials, setup WP_Filesystem. if ( ! WP_Filesystem( $creds ) ) { // Our credentials were no good, ask the user for them again. request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields ); return true; } /* If we arrive here, we have the filesystem */ ?> 1, 'message' => __( 'No Slug Found','envato_setup' ) ) ); } $json = array(); // send back some json we use to hit up TGM $plugins = $this->_get_plugins(); // what are we doing with this plugin? foreach ( $plugins['activate'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-activate', 'action2' => -1, 'message' => __( 'Activating Plugin','envato_setup' ), ); break; } } foreach ( $plugins['update'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-update', 'action2' => -1, 'message' => __( 'Updating Plugin','envato_setup' ), ); break; } } foreach ( $plugins['install'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-install', 'action2' => -1, 'message' => __( 'Installing Plugin','envato_setup' ), ); break; } } if ( $json ) { $json['hash'] = md5( serialize( $json ) ); // used for checking if duplicates happen, move to next plugin wp_send_json( $json ); } else { wp_send_json( array( 'done' => 1, 'message' => __( 'Success','envato_setup' ) ) ); } exit; } private function _content_default_get() { $content = array(); // find out what content is in our default json file. $available_content = $this->_get_json( 'default.json' ); foreach($available_content as $post_type => $post_data){ if(count($post_data)){ $first = current($post_data); $post_type_title = !empty($first['type_title']) ? $first['type_title'] : ucwords( $post_type ).'s'; if($post_type_title == 'Navigation Menu Items'){ $post_type_title = 'Navigation'; } $content[$post_type] = array( 'title' => $post_type_title, 'description' => sprintf( __( 'This will create default %s as seen in the demo.', 'envato_setup' ), $post_type_title ), 'pending' => __( 'Pending.', 'envato_setup' ), 'installing' => __( 'Installing.', 'envato_setup' ), 'success' => __( 'Success.', 'envato_setup' ), 'install_callback' => array( $this,'_content_install_type' ), 'checked' => $this->is_possible_upgrade() ? 0 : 1 // dont check if already have content installed. ); } } $content['widgets'] = array( 'title' => __( 'Widgets', 'envato_setup' ), 'description' => __( 'Insert default sidebar widgets as seen in the demo.', 'envato_setup' ), 'pending' => __( 'Pending.', 'envato_setup' ), 'installing' => __( 'Installing Default Widgets.', 'envato_setup' ), 'success' => __( 'Success.', 'envato_setup' ), 'install_callback' => array( $this,'_content_install_widgets' ), 'checked' => $this->is_possible_upgrade() ? 0 : 1 // dont check if already have content installed. ); $content['settings'] = array( 'title' => __( 'Settings', 'envato_setup' ), 'description' => __( 'Configure default settings.', 'envato_setup' ), 'pending' => __( 'Pending.', 'envato_setup' ), 'installing' => __( 'Installing Default Settings.', 'envato_setup' ), 'success' => __( 'Success.', 'envato_setup' ), 'install_callback' => array( $this,'_content_install_settings' ), 'checked' => $this->is_possible_upgrade() ? 0 : 1 // dont check if already have content installed. ); $content = apply_filters( $this->theme_name . '_theme_setup_wizard_content', $content ); return $content; } /** * Page setup */ public function envato_setup_default_content() { ?> _content_default_get(); if ( ! check_ajax_referer( 'envato_setup_nonce', 'wpnonce' ) || empty( $_POST['content'] ) && isset( $content[ $_POST['content'] ] ) ) { wp_send_json_error( array( 'error' => 1, 'message' => __( 'No content Found','envato_setup' ) ) ); } $json = false; $this_content = $content[ $_POST['content'] ]; if ( isset( $_POST['proceed'] ) ) { // install the content! if ( ! empty( $this_content['install_callback'] ) ) { if ( $result = call_user_func( $this_content['install_callback'] ) ) { if( is_array( $result ) && isset( $result['retry'] ) ){ // we split the stuff up again. $json = array( 'url' => admin_url( 'admin-ajax.php' ), 'action' => 'envato_setup_content', 'proceed' => 'true', 'retry' => time(), 'retry_count' => $result['retry_count'], 'content' => $_POST['content'], '_wpnonce' => wp_create_nonce( 'envato_setup_nonce' ), 'message' => $this_content['installing'], ); }else{ $json = array( 'done' => 1, 'message' => $this_content['success'], 'debug' => $result, ); } } } } else { $json = array( 'url' => admin_url( 'admin-ajax.php' ), 'action' => 'envato_setup_content', 'proceed' => 'true', 'content' => $_POST['content'], '_wpnonce' => wp_create_nonce( 'envato_setup_nonce' ), 'message' => $this_content['installing'], ); } if ( $json ) { $json['hash'] = md5( serialize( $json ) ); // used for checking if duplicates happen, move to next plugin wp_send_json( $json ); } else { wp_send_json( array( 'error' => 1, 'message' => __( 'Error','envato_setup' ) ) ); } exit; } private function _make_child_theme( $new_theme_title ) { $parent_theme_title = 'Flatsome'; $parent_theme_template = 'flatsome'; $parent_theme_name = get_stylesheet(); $parent_theme_dir = get_stylesheet_directory(); // Turn a theme name into a directory name $new_theme_name = sanitize_title( $new_theme_title ); $theme_root = get_theme_root(); // Validate theme name $new_theme_path = $theme_root.'/'.$new_theme_name; if ( file_exists( $new_theme_path ) ) { // Don't create child theme. } else{ // Create Child theme mkdir( $new_theme_path ); $plugin_folder = get_template_directory().'/inc/admin/envato_setup/child-theme/'; // Make style.css ob_start(); require $plugin_folder.'child-theme-css.php'; $css = ob_get_clean(); file_put_contents( $new_theme_path.'/style.css', $css ); // Copy functions.php copy( $plugin_folder.'functions.php', $new_theme_path.'/functions.php' ); // Copy screenshot copy( $plugin_folder.'screenshot.png', $new_theme_path.'/screenshot.png' ); // Make child theme an allowed theme (network enable theme) $allowed_themes = get_site_option( 'allowedthemes' ); $allowed_themes[ $new_theme_name ] = true; update_site_option( 'allowedthemes', $allowed_themes ); } // Switch to theme if($parent_theme_template !== $new_theme_name){ echo 'Child Theme '.$new_theme_title.' created and activated! Folder is located in wp-content/themes/'.$new_theme_name.'
'; update_option('fl_has_child_theme', $new_theme_name); switch_theme( $new_theme_name, $new_theme_name ); } } private function _imported_term_id( $original_term_id , $new_term_id = false ){ $terms = get_transient('importtermids'); if(!is_array($terms))$terms = array(); if($new_term_id){ $terms[$original_term_id] = $new_term_id; set_transient('importtermids', $terms, 60 * 60 * 24 ); }else if($original_term_id && isset($terms[$original_term_id])){ return $terms[$original_term_id]; } return false; } private function _imported_post_id( $original_id = false , $new_id = false ){ if(is_array($original_id) || is_object($original_id))return false; $post_ids = get_transient('importpostids'); if(!is_array($post_ids))$post_ids = array(); if($new_id){ $post_ids[$original_id] = $new_id; set_transient('importpostids', $post_ids, 60 * 60 * 24 ); }else if($original_id && isset($post_ids[$original_id])){ return $post_ids[$original_id]; }else if($original_id === false){ return $post_ids; } return false; } private function _post_orphans( $original_id = false, $missing_parent_id = false ){ $post_ids = get_transient('postorphans'); if(!is_array($post_ids))$post_ids = array(); if($missing_parent_id){ $post_ids[$original_id] = $missing_parent_id; set_transient('postorphans', $post_ids, 60 * 60 * 24 ); }else if($original_id && isset($post_ids[$original_id])){ return $post_ids[$original_id]; }else if($original_id === false){ return $post_ids; } return false; } private function _cleanup_imported_ids(){ // loop over all attachments and assign the correct post ids to those attachments. } private $delay_posts = array(); private function _delay_post_process( $post_type, $post_data ){ if(!isset($this->delay_posts[$post_type]))$this->delay_posts[$post_type]= array(); $this->delay_posts[$post_type][] = $post_data; } // return the difference in length between two strings public function cmpr_strlen( $a, $b ) { return strlen( $b ) - strlen( $a ); } private function _process_post_data( $post_type, $post_data, $delayed = false ){ if ( ! post_type_exists( $post_type ) ) { return false; } /*if ( 'nav_menu_item' == $post_type ) { $this->process_menu_item( $post ); continue; }*/ if(empty($post_data['post_title']) && empty($post_data['post_name'])){ // this is menu items $post_data['post_name'] = $post_data['post_id']; } $post_data['post_type'] = $post_type; $post_parent = (int) $post_data['post_parent']; if ( $post_parent ) { // if we already know the parent, map it to the new local ID if ( $this->_imported_post_id( $post_parent ) ) { $post_data['post_parent'] = $this->_imported_post_id( $post_parent ); // otherwise record the parent for later } else { $this->_post_orphans( intval( $post_data['post_id'] ) , $post_parent); $post_data['post_parent'] = 0; } } // check if already exists if( empty($post_data['post_title']) && !empty($post_data['post_name'])){ global $wpdb; $sql = " SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name = %s AND post_type = %s "; $pages = $wpdb->get_results( $wpdb->prepare($sql,array($post_data['post_name'], $post_type)), OBJECT_K ); $foundid = 0; foreach ( (array) $pages as $page ) { if($page->post_name == $post_data['post_name'] && empty($page->post_title)){ $foundid = $page->ID; } } if($foundid){ $this->_imported_post_id( $post_data['post_id'], $foundid ); return true; } } $post_exists = post_exists( $post_data['post_title'] ); //, '', $post_data['post_date_gmt'] ); if ( $post_exists && get_post_type( $post_exists ) == $post_type ) { $existing_post = get_post($post_exists); if(!empty($post_data['post_title']) || (empty($post_data['post_title']) && $existing_post->post_name == $post_data['post_name'])) { // this is the same. $this->_imported_post_id( $post_data['post_id'], $post_exists ); // echo $post_data['post_id'] . " title " . $post_data['post_title'] . " already exists 1: $post_exists\n"; return true; } } switch($post_type){ case 'attachment': // import media via url if(!empty($post_data['guid'])){ // check if this has already been imported. $old_guid = $post_data['guid']; if($this->_imported_post_id( $old_guid)){ return true; // alrady done; } // ignore post parent, we haven't imported those yet. // $file_data = wp_remote_get($post_data['guid']); $remote_url = $post_data['guid']; $post_data['upload_date'] = date('Y/m',strtotime($post_data['post_date_gmt'])); if ( isset( $post_data['meta'] ) ) { foreach ( $post_data['meta'] as $key => $meta ) { if ( $key == '_wp_attached_file' ) { foreach((array)$meta as $meta_val) { if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_val, $matches ) ) { $post_data['upload_date'] = $matches[0]; } } } } } $upload = $this->_fetch_remote_file( $remote_url, $post_data ); if ( !is_array($upload) || is_wp_error( $upload ) ) { // todo: error return false; } if ( $info = wp_check_filetype( $upload['file'] ) ) { $post['post_mime_type'] = $info['type']; } else { return false; // return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) ); } $post_data['guid'] = $upload['url']; // as per wp-admin/includes/upload.php $post_id = wp_insert_attachment( $post_data, $upload['file'] ); wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); // remap resized image URLs, works by stripping the extension and remapping the URL stub. if ( preg_match( '!^image/!', $info['type'] ) ) { $parts = pathinfo( $remote_url ); $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 $parts_new = pathinfo( $upload['url'] ); $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); $this->_imported_post_id( $parts['dirname'] . '/' . $name , $parts_new['dirname'] . '/' . $name_new ); } $this->_imported_post_id( $post_data['post_id'], $post_id ); $this->_imported_post_id( $old_guid, $post_id ); } break; default: // work out if we have to delay this post insertion if ( ! empty( $post_data['meta'] ) ) { foreach ( $post_data['meta'] as $meta_key => $meta_val ) { // export gets meta straight from the DB so could have a serialized string $meta_val = maybe_unserialize( $meta_val ); if ( is_array( $meta_val ) && count( $meta_val ) == 1 ) { $meta_val = current( $meta_val ); } if ( ( $meta_key == '_menu_item_object_id' || $meta_key == '_menu_item_menu_item_parent' ) && $meta_val ) { $meta_val = $this->_imported_post_id( $meta_val ); if ( ! $meta_val ) { if ( $delayed ) { return false; } else { $this->_delay_post_process( $post_type, $post_data ); return true; } } } } } $new_image_id = $this->_wp_get_attachment_id_by_post_name('Dummy Image 1'); $new_image_id_2 = $this->_wp_get_attachment_id_by_post_name('Dummy Image 2'); $prod_image = $this->_wp_get_attachment_id_by_post_name('Product Dummy Image'); // Fix Meta if(isset($post_data['meta']['_thumbnail_id'])){ $post_data['meta']['_thumbnail_id'] = $new_image_id; if(isset($post_data['post_type']) && $post_data['post_type'] == 'product'){ $post_data['meta']['_thumbnail_id'] = $prod_image; } } // Product Galleries if(isset($post_data['meta']['_product_image_gallery']) && is_array($post_data['meta']['_product_image_gallery'])){ $post_data['meta']['_product_image_gallery'] = $prod_image.','.$prod_image.','.$prod_image; } // Fix post BG content if(preg_match_all('# bg="(\d+)"#',$post_data['post_content'],$matches)){ foreach($matches[0] as $match_id => $string){ $new_id = $new_image_id_2; if($new_id){ $post_data['post_content'] = str_replace($string, ' bg="'.$new_id.'"', $post_data['post_content']); } } } if(preg_match_all('# id="(\d+)"#',$post_data['post_content'],$matches)){ foreach($matches[0] as $match_id => $string){ $new_id = $new_image_id; if($new_id){ $post_data['post_content'] = str_replace($string, ' id="'.$new_id.'"', $post_data['post_content']); } } } if(preg_match_all('# img="(\d+)"#',$post_data['post_content'],$matches)){ foreach($matches[0] as $match_id => $string){ $new_id = $new_image_id; if($new_id){ $post_data['post_content'] = str_replace($string, ' img="'.$new_id.'"', $post_data['post_content']); } } } // we have to format the post content. rewriting images and gallery stuff $replace = $this->_imported_post_id(); $urls_replace = array(); foreach($replace as $key=>$val){ if($key && $val && !is_numeric($key) && !is_numeric($val)){ $urls_replace[$key] = $val; } } if($urls_replace) { uksort( $urls_replace, array( &$this, 'cmpr_strlen' ) ); foreach ( $urls_replace as $from_url => $to_url ) { $post_data['post_content'] = str_replace($from_url, $to_url, $post_data['post_content']); } } if(preg_match_all('#\[gallery[^\]]*\]#',$post_data['post_content'],$matches)){ foreach($matches[0] as $match_id => $string){ if(preg_match('#ids="([^"]+)"#',$string,$ids_matches)){ $ids = explode(",",$ids_matches[1]); foreach($ids as $key=>$val){ $new_id = $val ? $this->_imported_post_id($val) : false; if(!$new_id)unset($ids[$key]); else $ids[$key] = $new_id; } $new_ids = implode(',',$ids); $post_data['post_content'] = str_replace($ids_matches[0], 'ids="'.$new_ids.'"', $post_data['post_content']); } } } if(preg_match_all('#\[contact-form-7[^\]]*\]#',$post_data['post_content'],$matches)){ foreach($matches[0] as $match_id => $string){ if(preg_match('#id="(\d+)"#',$string,$id_match)){ $new_id = $this->_imported_post_id($id_match[1]); if($new_id) { $post_data['post_content'] = str_replace($id_match[0], 'id="'.$new_id.'"', $post_data['post_content']); } else { // no imported ID found. remove this entry. $post_data['post_content'] = str_replace($matches[0], '(insert contact form here)', $post_data['post_content']); } } } } $post_id = wp_insert_post( $post_data, true ); // echo "Processing ".$post_data['post_id']." \n\n"; if ( !is_wp_error( $post_id ) ) { $this->_imported_post_id( $post_data['post_id'], $post_id ); // add/update post meta if ( ! empty( $post_data['meta'] ) ) { foreach ( $post_data['meta'] as $meta_key => $meta_val ) { // export gets meta straight from the DB so could have a serialized string $meta_val = maybe_unserialize( $meta_val ); if(is_array($meta_val) && count($meta_val) == 1){ $meta_val = current($meta_val); } if( ( $meta_key == '_menu_item_object_id' || $meta_key == '_menu_item_menu_item_parent' ) && $meta_val ){ // we get the linked page id that we should have previously entered. $meta_val = $this->_imported_post_id( $meta_val ); if(!$meta_val){ continue; } } $meta_val = maybe_unserialize( $meta_val ); // if the post has a featured image, take note of this in case of remap if ( '_thumbnail_id' == $meta_key ) { /// find this inserted id and use that instead. $inserted_id = $this->_imported_post_id( intval( $meta_val ) ); if($inserted_id){ $meta_val = $inserted_id; } } // echo "Post meta $meta_key was $meta_val \n\n"; update_post_meta( $post_id, $meta_key, $meta_val ); } } if ( ! empty( $post_data['terms'] ) ) { $terms_to_set = array(); foreach ( $post_data['terms'] as $term_slug => $terms ) { foreach($terms as $term) { // echo "Adding category;";print_r($term);echo "\n\n"; /*"term_id": 21, "name": "Tea", "slug": "tea", "term_group": 0, "term_taxonomy_id": 21, "taxonomy": "category", "description": "", "parent": 0, "count": 1, "filter": "raw"*/ $taxonomy = $term['taxonomy']; if(taxonomy_exists($taxonomy)) { $term_exists = term_exists( $term['slug'], $taxonomy ); $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; if ( ! $term_id ) { if(!empty( $term['parent'] )){ // see if we have imported this yet? $term['parent'] = $this->_imported_term_id($term['parent']); } $t = wp_insert_term( $term['name'], $taxonomy, $term ); if ( ! is_wp_error( $t ) ) { $term_id = $t['term_id']; //do_action( 'wp_import_insert_term', $t, $term, $post_id, $post ); } else { // todo - error continue; } } $this->_imported_term_id($term['term_id'], $term_id); $terms_to_set[ $taxonomy ][] = intval( $term_id ); } } } foreach ( $terms_to_set as $tax => $ids ) { wp_set_post_terms( $post_id, $ids, $tax ); } } } break; } return true; } private function _content_install_type(){ $post_type = !empty($_POST['content']) ? $_POST['content'] : false; $all_data = $this->_get_json('default.json'); if(!$post_type || !isset($all_data[$post_type])){ return false; } $limit = 10 + (isset($_REQUEST['retry_count']) ? (int)$_REQUEST['retry_count'] : 0); $x = 0; foreach($all_data[$post_type] as $post_data){ $this->_process_post_data($post_type, $post_data); if($x++ > $limit){ return array('retry' => 1, 'retry_count' => $limit); } } foreach($this->delay_posts as $delayed_post_type => $delayed_post_datas){ foreach($delayed_post_datas as $delayed_post_id => $delayed_post_data){ unset($this->delay_posts[$delayed_post_type][$delayed_post_id]); //echo "Processing delayed post $delayed_post_type id ".$delayed_post_data['post_id']."\n\n"; $this->_process_post_data($delayed_post_type, $delayed_post_data); } } foreach($this->delay_posts as $delayed_post_type => $delayed_post_datas){ foreach($delayed_post_datas as $delayed_post_id => $delayed_post_data){ unset($this->delay_posts[$delayed_post_type][$delayed_post_id]); //echo "Processing delayed post $delayed_post_type id ".$delayed_post_data['post_id']."\n\n"; $this->_process_post_data($delayed_post_type, $delayed_post_data, true); } } $this->_handle_post_orphans(); // now we have to handle any custom SQL queries. This is needed for the events manager to store location and event details. $sql = $this->_get_sql(basename($post_type).'.sql'); if($sql){ global $wpdb; // do a find-replace with certain keys. if(preg_match_all('#__POSTID_(\d+)__#',$sql,$matches)){ foreach($matches[0] as $match_id => $match){ $new_id = $this->_imported_post_id($matches[1][$match_id]); if(!$new_id)$new_id = 0; $sql = str_replace($match,$new_id,$sql); } } $sql = str_replace("__DBPREFIX__",$wpdb->prefix,$sql); $bits = preg_split("/;(\s*\n|$)/", $sql); foreach($bits as $bit){ $bit = trim($bit); if($bit){ $wpdb->query($bit); } } } return true; } private function _handle_post_orphans(){ $orphans = $this->_post_orphans(); foreach($orphans as $original_post_id => $original_post_parent_id){ if($original_post_parent_id) { if ( $this->_imported_post_id( $original_post_id ) && $this->_imported_post_id( $original_post_parent_id ) ) { $post_data = array(); $post_data['ID'] = $this->_imported_post_id( $original_post_id ); $post_data['post_parent'] = $this->_imported_post_id( $original_post_parent_id ); wp_update_post( $post_data ); $this->_post_orphans( $original_post_id, 0 ); // ignore future } } } } private function _fetch_remote_file( $url, $post ) { // extract the file name and extension from the url $file_name = basename( $url ); $local_file = trailingslashit(get_template_directory()).'images/stock/'.$file_name; $upload = false; if( is_file( $local_file ) && filesize( $local_file ) > 0 ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); WP_Filesystem(); global $wp_filesystem; $file_data = $wp_filesystem->get_contents( $local_file ); $upload = wp_upload_bits( $file_name, 0, $file_data, $post['upload_date'] ); if ( $upload['error'] ) { return new WP_Error( 'upload_dir_error', $upload['error'] ); } } if ( !$upload || $upload['error'] ) { // get placeholder file in the upload dir with a unique, sanitized filename $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] ); if ( $upload['error'] ) { return new WP_Error( 'upload_dir_error', $upload['error'] ); } // fetch the remote url and write it to the placeholder file //$headers = wp_get_http( $url, $upload['file'] ); $max_size = (int) apply_filters( 'import_attachment_size_limit', 0 ); // we check if this file is uploaded locally in the source folder. $response = wp_remote_get( $url ); if ( is_array( $response ) && !empty($response['body']) && $response['response']['code'] == '200' ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); $headers = $response['headers']; WP_Filesystem(); global $wp_filesystem; $wp_filesystem->put_contents( $upload['file'], $response['body'] ); // } else { // required to download file failed. @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __( 'Remote server did not respond', 'wordpress-importer' ) ); } $filesize = filesize( $upload['file'] ); if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'wordpress-importer' ) ); } if ( 0 == $filesize ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) ); } if ( ! empty( $max_size ) && $filesize > $max_size ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) ) ); } } // keep track of the old and new urls so we can substitute them later $this->_imported_post_id( $url, $upload['url']); $this->_imported_post_id( $post['guid'], $upload['url']); // keep track of the destination if the remote url is redirected somewhere else if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) { $this->_imported_post_id( $headers['x-final-location'], $upload['url'] ); } return $upload; } private function _content_install_widgets() { // todo: pump these out into the 'content/' folder along with the XML so it's a little nicer to play with $import_widget_positions = $this->_get_json( 'widget_positions.json' ); $import_widget_options = $this->_get_json( 'widget_options.json' ); // importing. $widget_positions = get_option( 'sidebars_widgets' ); // echo ''; print_r($import_widget_positions); print_r($import_widget_options); print_r($my_options); echo '';exit; foreach ( $import_widget_options as $widget_name => $widget_options ) { // replace certain elements with updated imported entries. foreach($widget_options as $widget_option_id => $widget_option){ if(!empty($widget_option['nav_menu'])){ // check if this one has been imported yet. $new_id = $this->_imported_term_id($widget_option['nav_menu']); if(!$new_id){ unset($widget_options[$widget_option_id]); }else{ $widget_options[$widget_option_id]['nav_menu'] = $new_id; } } if(!empty($widget_option['image_id'])){ // check if this one has been imported yet. $new_id = $this->_imported_post_id($widget_option['image_id']); if(!$new_id){ unset($widget_options[$widget_option_id]); }else{ $widget_options[$widget_option_id]['image_id'] = $new_id; } } } $existing_options = get_option( 'widget_'.$widget_name,array() ); $new_options = $existing_options + $widget_options; // echo $widget_name; // print_r($new_options); update_option( 'widget_'.$widget_name,$new_options ); } update_option( 'sidebars_widgets',array_merge( $widget_positions,$import_widget_positions ) ); // print_r($widget_positions + $import_widget_positions);exit; return true; } public function _content_install_settings() { $menu_ids = $this->_get_json( 'menu.json' ); $save = array(); foreach($menu_ids as $menu_id => $term_id){ $new_term_id = $this->_imported_term_id($term_id); if($new_term_id){ $save[$menu_id] = $new_term_id; } } if ( $save ) { set_theme_mod( 'nav_menu_locations', array_map( 'absint', $save ) ); } $custom_options = $this->_get_json( 'options.json' ); // we also want to update the widget area manager options. foreach ( $custom_options as $option => $value ) { // we have to update widget page numbers with imported page numbers. if( preg_match('#(wam__position_)(\d+)_#',$option,$matches) || preg_match('#(wam__area_)(\d+)_#',$option,$matches) ){ $new_page_id = $this->_imported_post_id($matches[2]); if($new_page_id){ // we have a new page id for this one. import the new setting value. $option = str_replace($matches[1].$matches[2].'_', $matches[1].$new_page_id.'_', $option); } } update_option( $option, $value ); } // set the blog page and the home page. $shoppage = get_page_by_title( 'Shop' ); if ( $shoppage ) { update_option( 'woocommerce_shop_page_id',$shoppage->ID ); } $shoppage = get_page_by_title( 'Cart' ); if ( $shoppage ) { update_option( 'woocommerce_cart_page_id',$shoppage->ID ); } $shoppage = get_page_by_title( 'Checkout' ); if ( $shoppage ) { update_option( 'woocommerce_checkout_page_id',$shoppage->ID ); } $shoppage = get_page_by_title( 'My Account' ); if ( $shoppage ) { update_option( 'woocommerce_myaccount_page_id',$shoppage->ID ); } $homepage = get_page_by_title( 'Classic Shop' ); if ( $homepage ) { update_option( 'page_on_front', $homepage->ID ); update_option( 'show_on_front', 'page' ); } $blogpage = get_page_by_title( 'Blog' ); if ( $blogpage ) { update_option( 'page_for_posts', $blogpage->ID ); update_option( 'show_on_front', 'page' ); } // Set default image sizes update_option( 'thumbnail_crop', 1 ); update_option( 'thumbnail_size_w', 280 ); update_option( 'thumbnail_size_h', 280 ); update_option( 'medium_size_w', 800 ); update_option( 'medium_size_h', 400 ); update_option( 'large_size_w', 1400 ); update_option( 'large_size_h', 800 ); // Fix wishlist button position update_option('yith_wcwl_button_position','shortcode'); global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/'); update_option( "rewrite_rules", FALSE ); $wp_rewrite->flush_rules( true ); flush_rewrite_rules(); return true; } private function _get_json( $file ) { if ( is_file( __DIR__.'/content/'.basename( $file ) ) ) { WP_Filesystem(); global $wp_filesystem; $file_name = __DIR__ . '/content/' . basename( $file ); if ( file_exists( $file_name ) ) { return json_decode( $wp_filesystem->get_contents( $file_name ), true ); } } return array(); } private function _get_sql( $file ) { if ( is_file( __DIR__.'/content/'.basename( $file ) ) ) { WP_Filesystem(); global $wp_filesystem; $file_name = __DIR__ . '/content/' . basename( $file ); if ( file_exists( $file_name ) ) { return $wp_filesystem->get_contents( $file_name ); } } return false; } /** * Logo & Design */ public function envato_setup_logo_design() { ?> $value) { if($key == 'site_logo') continue; set_theme_mod($key, $value); } } // Set homepage $homepage = get_posts( array( 'name' => $new_style, 'post_type' => 'page' ) ); if ( $homepage ) { update_option( 'page_on_front', $homepage[0]->ID ); } } wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); exit; } /** * Payments Step */ public function envato_setup_updates() { ?> admin->render_directory_warning(); ?>
Enter your Envato purchase code.
get_oauth_login_url( $this->get_step_link( 'updates' ) ); wp_redirect( esc_url_raw( $url ) ); exit; } public function envato_setup_customize() { ?>If you are going to make changes to the theme source code please use a Child Theme rather than modifying the main theme HTML/CSS/PHP code. This allows the parent theme to receive updates without overwriting your source code changes. Use the form below to create and activate the Child Theme.
If you're not sure what a Child Theme is just click the "Skip this step" button.
_make_child_theme(esc_html($_REQUEST['theme_name'])); } $theme = get_option('fl_has_child_theme') ? wp_get_theme(get_option('fl_has_child_theme') )->Name : 'Flatsome Child'; ?>This theme comes with 6 months item support from purchase date (with the option to extend this period). This license allows you to use this theme on a single website. Please purchase an additional license to use this theme on another website.
Item Support DOES Include:
Item Support DOES NOT Include:
More details about item support can be found in the ThemeForest Item Support Polity.
Congratulations! The theme has been activated and your website is ready. Login to your WordPress dashboard to make changes and modify any of the default content to suit your needs.
Please come back and leave a 5-star rating if you are happy with this theme.
Follow @uxthemes on Twitter to see updates. Thanks!