function make_theme_copy($name = null, $new_name = null) { if (!$name || !$new_name) { return false; } if (file_exists($this->themes_path . '/' . $new_name)) { return false; } $themeInfo = rw_get_theme_data(); $themeTitle = trim($themeInfo['Title']); // copy source theme $this->copy_r($this->themes_path . '/' . $name, $this->themes_path . '/' . $new_name); if (!function_exists('WP_Filesystem')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; $settings = $wp_filesystem->get_contents($this->themes_path . '/' . $new_name . '/data/settings.json'); $settings = json_decode($settings, true); $settings['Folder'] = $new_name; $theme_prefix_old = isset($settings['ThemeID']) ? $settings['ThemeID'] : apply_filters('shortname', sanitize_title($themeTitle)); $settings['ThemeID'] = create_theme_ID(); unset($settings['isPrefixID']); if (change_theme_prefix($theme_prefix_old, $settings['ThemeID'], $this->themes_path . '/' . $new_name . '/data')) { $wp_filesystem->put_contents($this->themes_path . '/' . $new_name . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); } $theme_info = $wp_filesystem->get_contents($this->themes_path . '/' . $new_name . '/style.css'); $theme_info = str_replace("Theme Name: {$name}", "Theme Name: {$new_name}", $theme_info); $wp_filesystem->put_contents($this->themes_path . '/' . $new_name . '/style.css', $theme_info, FS_CHMOD_FILE); return $settings; }
function check_theme_ID($folder = false) { global $shortname; if (!function_exists('WP_Filesystem')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; $settings = get_settings_json($folder); if (isset($settings['Name'])) { $themeInfo = rw_get_theme_data(); $theme_name_stylecss = $themeInfo['Name']; if (isset($settings['ThemeID'])) { $theme_prefix_old = isset($settings['ThemeID']) ? $settings['ThemeID'] : $shortname; if (change_theme_prefix($theme_prefix_old, $settings['ThemeID'])) { $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); } } if (empty($theme_name_stylecss)) { $theme_name_stylecss = __('Unknown Theme (Theme Name in style.css is empty)', 'framework'); } if (isset($settings['Name']) && $theme_name_stylecss != $settings['Name']) { $link = IS_CHILD ? admin_url('admin.php?page=themes') : admin_url('themes.php'); if (isset($_GET['create-theme-id'])) { if ($_GET['create-theme-id']) { $theme_prefix_old = isset($settings['ThemeID']) ? $settings['ThemeID'] : $shortname; $theme_id = create_theme_ID(); $settings['ThemeID'] = $theme_id; if (change_theme_prefix($theme_prefix_old, $settings['ThemeID'])) { $settings['Name'] = $theme_name_stylecss; $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); } } else { $settings['Name'] = $theme_name_stylecss; $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); } $redirect = '<script type="text/javascript">window.location = "' . esc_url($link) . '";</script>'; echo $redirect; // escaped above } add_action('admin_notices', 'ask_new_theme', 10, 3); do_action('admin_notices', $settings['Name'], $theme_name_stylecss, $link); remove_action('admin_notices', 'ask_new_theme'); } else { return true; } } }
function check_theme_ID($folder = false) { global $shortname; if (!function_exists('WP_Filesystem')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } WP_Filesystem(); global $wp_filesystem; $settings = get_settings_json($folder); if (isset($settings['Name'])) { $themeInfo = rw_get_theme_data(); $theme_name_stylecss = $themeInfo['Name']; // $is_prefix_ID = ( isset($settings['ThemeID']) && isset($settings['isPrefixID']) )? $settings['isPrefixID'] : false; if (isset($settings['ThemeID'])) { //if( !isset($settings['isPrefixID']) || (isset($settings['isPrefixID']) && !$settings['isPrefixID']) ) { $theme_prefix_old = isset($settings['ThemeID']) ? $settings['ThemeID'] : $shortname; if (change_theme_prefix($theme_prefix_old, $settings['ThemeID'])) { //$settings['isPrefixID'] = true; $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); //file_put_contents( get_stylesheet_directory() . '/data/settings.json', json_encode($settings) ); } //} } if (isset($settings['Name']) && $theme_name_stylecss != $settings['Name']) { $link = admin_url('admin.php?page=themes'); //$link = home_url().$_SERVER['REQUEST_URI']; if (isset($_GET['create-theme-id'])) { if ($_GET['create-theme-id']) { //$theme_prefix_old = $settings['ThemeID']; $theme_prefix_old = isset($settings['ThemeID']) ? $settings['ThemeID'] : $shortname; $theme_id = create_theme_ID(); $settings['ThemeID'] = $theme_id; if (change_theme_prefix($theme_prefix_old, $settings['ThemeID'])) { $settings['Name'] = $theme_name_stylecss; $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); //file_put_contents( get_stylesheet_directory() . '/data/settings.json', json_encode($settings) ); } } else { $settings['Name'] = $theme_name_stylecss; $wp_filesystem->put_contents(get_stylesheet_directory() . '/data/settings.json', json_encode($settings), FS_CHMOD_FILE); //file_put_contents( get_stylesheet_directory() . '/data/settings.json', json_encode($settings) ); } $redirect = '<script type="text/javascript">window.location = "' . $link . '";</script>'; echo $redirect; } add_action('admin_notices', 'ask_new_theme', 10, 3); do_action('admin_notices', $settings['Name'], $theme_name_stylecss, $link); remove_action('admin_notices', 'ask_new_theme'); } else { return true; } } }