function get_detheme_number() { global $wp_theme_directories; $stylesheet = get_stylesheet(); $theme_root = get_raw_theme_root($stylesheet); if (false === $theme_root) { $theme_root = WP_CONTENT_DIR . '/themes'; } elseif (!in_array($theme_root, (array) $wp_theme_directories)) { $theme_root = WP_CONTENT_DIR . $theme_root; } $theme = $theme_root . '/' . $stylesheet . '/style.css'; if (!file_exists($theme)) { return __('Stylesheet is missing.', 'billio'); } $themeinfo = get_file_data($theme, array('SN' => 'Serial Number'), ''); return $themeinfo['SN']; }
/** * Retrieve the stylesheet root of the previewed theme. * * @since 3.4.0 * * @return string Theme root. */ public function get_stylesheet_root() { return get_raw_theme_root($this->get_stylesheet(), true); }
/** * Switches current theme to new template and stylesheet names. * * @since 2.5.0 * @uses do_action() Calls 'switch_theme' action, passing the new theme. * * @param string $template Template name * @param string $stylesheet Stylesheet name. */ function switch_theme($template, $stylesheet) { global $wp_theme_directories, $sidebars_widgets; if (is_array($sidebars_widgets)) { set_theme_mod('sidebars_widgets', array('time' => time(), 'data' => $sidebars_widgets)); } $old_theme = wp_get_theme(); $new_theme = wp_get_theme($stylesheet); $new_name = $new_theme->get('Name'); update_option('template', $template); update_option('stylesheet', $stylesheet); if (count($wp_theme_directories) > 1) { update_option('template_root', get_raw_theme_root($template, true)); update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); } update_option('current_theme', $new_name); if (is_admin() && false === get_option('theme_mods_' . $stylesheet)) { $default_theme_mods = (array) get_option('mods_' . $new_name); add_option("theme_mods_{$stylesheet}", $default_theme_mods); } update_option('theme_switched', $old_theme->get_stylesheet()); do_action('switch_theme', $new_name, $new_theme); }
/** * Switches the theme. * * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature * of two arguments: $template then $stylesheet. This is for backwards compatibility. * * @since 2.5.0 * * @global array $wp_theme_directories * @global WP_Customize_Manager $wp_customize * @global array $sidebars_widgets * * @param string $stylesheet Stylesheet name */ function switch_theme($stylesheet) { global $wp_theme_directories, $wp_customize, $sidebars_widgets; $_sidebars_widgets = null; if ('wp_ajax_customize_save' === current_action()) { $_sidebars_widgets = $wp_customize->post_value($wp_customize->get_setting('old_sidebars_widgets_data')); } elseif (is_array($sidebars_widgets)) { $_sidebars_widgets = $sidebars_widgets; } if (is_array($_sidebars_widgets)) { set_theme_mod('sidebars_widgets', array('time' => time(), 'data' => $_sidebars_widgets)); } $nav_menu_locations = get_theme_mod('nav_menu_locations'); if (func_num_args() > 1) { $stylesheet = func_get_arg(1); } $old_theme = wp_get_theme(); $new_theme = wp_get_theme($stylesheet); $template = $new_theme->get_template(); update_option('template', $template); update_option('stylesheet', $stylesheet); if (count($wp_theme_directories) > 1) { update_option('template_root', get_raw_theme_root($template, true)); update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); } else { delete_option('template_root'); delete_option('stylesheet_root'); } $new_name = $new_theme->get('Name'); update_option('current_theme', $new_name); // Migrate from the old mods_{name} option to theme_mods_{slug}. if (is_admin() && false === get_option('theme_mods_' . $stylesheet)) { $default_theme_mods = (array) get_option('mods_' . $new_name); if (!empty($nav_menu_locations) && empty($default_theme_mods['nav_menu_locations'])) { $default_theme_mods['nav_menu_locations'] = $nav_menu_locations; } add_option("theme_mods_{$stylesheet}", $default_theme_mods); } else { /* * Since retrieve_widgets() is called when initializing a theme in the Customizer, * we need to to remove the theme mods to avoid overwriting changes made via * the Customizer when accessing wp-admin/widgets.php. */ if ('wp_ajax_customize_save' === current_action()) { remove_theme_mod('sidebars_widgets'); } if (!empty($nav_menu_locations)) { $nav_mods = get_theme_mod('nav_menu_locations'); if (empty($nav_mods)) { set_theme_mod('nav_menu_locations', $nav_menu_locations); } } } update_option('theme_switched', $old_theme->get_stylesheet()); /** * Fires after the theme is switched. * * @since 1.5.0 * * @param string $new_name Name of the new theme. * @param WP_Theme $new_theme WP_Theme instance of the new theme. */ do_action('switch_theme', $new_name, $new_theme); }
/** * Runs on BuddyPress deactivation * * @since BuddyPress (1.6) * * @uses do_action() Calls 'bp_deactivation' hook */ function bp_deactivation() { // Force refresh theme roots. delete_site_transient('theme_roots'); // Switch to WordPress's default theme if current parent or child theme // depend on bp-default. This is to prevent white screens of doom. if (in_array('bp-default', array(get_template(), get_stylesheet()))) { switch_theme(WP_DEFAULT_THEME, WP_DEFAULT_THEME); update_option('template_root', get_raw_theme_root(WP_DEFAULT_THEME, true)); update_option('stylesheet_root', get_raw_theme_root(WP_DEFAULT_THEME, true)); } // Use as of (1.6) do_action('bp_deactivation'); // @deprecated as of (1.6) do_action('bp_loader_deactivate'); }
/** * Switches the theme. * * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature * of two arguments: $template then $stylesheet. This is for backwards compatibility. * * @since 2.5.0 * * @param string $stylesheet Stylesheet name */ function switch_theme($stylesheet) { global $wp_theme_directories, $sidebars_widgets; if (is_array($sidebars_widgets)) { set_theme_mod('sidebars_widgets', array('time' => time(), 'data' => $sidebars_widgets)); } $old_theme = wp_get_theme(); $new_theme = wp_get_theme($stylesheet); if (func_num_args() > 1) { $template = $stylesheet; $stylesheet = func_get_arg(1); } else { $template = $new_theme->get_template(); } update_option('template', $template); update_option('stylesheet', $stylesheet); if (count($wp_theme_directories) > 1) { update_option('template_root', get_raw_theme_root($template, true)); update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); } else { delete_option('template_root'); delete_option('stylesheet_root'); } $new_name = $new_theme->get('Name'); update_option('current_theme', $new_name); if (is_admin() && false === get_option('theme_mods_' . $stylesheet)) { $default_theme_mods = (array) get_option('mods_' . $new_name); add_option("theme_mods_{$stylesheet}", $default_theme_mods); } update_option('theme_switched', $old_theme->get_stylesheet()); /** * Fires after the theme is switched. * * @since 1.5.0 * * @param string $new_name Name of the new theme. * @param WP_Theme $new_theme WP_Theme instance of the new theme. */ do_action('switch_theme', $new_name, $new_theme); }
/** * Switches current theme to new template and stylesheet names. * * @since 2.5.0 * @uses do_action() Calls 'switch_theme' action on updated theme display name. * * @param string $template Template name * @param string $stylesheet Stylesheet name. */ function switch_theme($template, $stylesheet) { global $wp_theme_directories; update_option('template', $template); update_option('stylesheet', $stylesheet); if (count($wp_theme_directories) > 1) { update_option('template_root', get_raw_theme_root($template, true)); update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); } delete_option('current_theme'); $theme = get_current_theme(); if (is_admin() && false === get_option("theme_mods_{$stylesheet}")) { $default_theme_mods = (array) get_option("mods_{$theme}"); add_option("theme_mods_{$stylesheet}", $default_theme_mods); } do_action('switch_theme', $theme); }
/** * Check to see if the theme is already installed. * * @since 3.4 * @access private * * @param object $theme - A WordPress.org Theme API object. * @return string Theme status. */ private function _wp_get_theme($stylesheet = null, $theme_root = null) { global $wp_theme_directories; if (empty($stylesheet)) { $stylesheet = get_stylesheet(); } if (empty($theme_root)) { $theme_root = get_raw_theme_root($stylesheet); if (false === $theme_root) { $theme_root = WP_CONTENT_DIR . '/themes'; } elseif (!in_array($theme_root, (array) $wp_theme_directories)) { $theme_root = WP_CONTENT_DIR . $theme_root; } } if (class_exists('WP_Theme')) { return new WP_Theme($stylesheet, $theme_root); } else { WPRC_Loader::includeClass('class-wp-theme.php'); return new WP_Theme($stylesheet, $theme_root); } }
function get_theme_root($stylesheet_or_template = false) { global $wp_theme_directories; if ($stylesheet_or_template && ($theme_root = get_raw_theme_root($stylesheet_or_template))) { // Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. // This gives relative theme roots the benefit of the doubt when things go haywire. if (!in_array($theme_root, (array) $wp_theme_directories)) { $theme_root = WP_CONTENT_DIR . $theme_root; } } else { $theme_root = WP_CONTENT_DIR . '/themes'; } return apply_filters('theme_root', $theme_root); }
/** * Get the switched stylesheet (child) theme root path. * Used as a callback for 'pre_option_stylesheet_root' WP filter. * * @return string * @since 0.4 */ public function filter_stylesheet_root($stylesheet_root = '') { $stylesheet = $this->get_stylesheet(); if (!empty($stylesheet)) { $stylesheet_root = get_raw_theme_root($stylesheet, true); } return $stylesheet_root; }
/** * Retrieves the absolute URL to the current file. * Like a WordPress function `plugins_url`. * * @link https://codex.wordpress.org/Function_Reference/plugins_url * @since 1.0.1 * @param string $file_path Optional. Extra path appended to the end of the URL. * @param string $module_path A full path to the core or module file. * @return string */ public static function base_url($file_path = '', $module_path) { $module_path = wp_normalize_path($module_path); $module_dir = dirname($module_path); $plugin_dir = wp_normalize_path(WP_PLUGIN_DIR); $stylesheet = get_stylesheet(); $theme_root = get_raw_theme_root($stylesheet); $theme_dir = "{$theme_root}/{$stylesheet}"; if (0 === strpos($module_path, $plugin_dir)) { $url = plugin_dir_url($module_path); } else { if (false !== strpos($module_path, $theme_dir)) { $explode = explode($theme_dir, $module_dir); $url = get_stylesheet_directory_uri() . end($explode); } else { $site_url = site_url(); $abs_path = wp_normalize_path(ABSPATH); $url = str_replace(untrailingslashit($abs_path), $site_url, $module_dir); } } if ($file_path && is_string($file_path)) { $url = trailingslashit($url); $url .= ltrim($file_path, '/'); } return apply_filters('cherry_core_base_url', $url, $file_path, $module_path); }
/** * Determine if instance already exists and Return Instance * * Attention: The method MUST be called from plugin core file at first to set correct path to plugin! * * @author peshkov@UD */ public static function get_instance($args = array()) { $class = get_called_class(); //** We must be sure that final class contains static property $instance to prevent issues. */ if (!property_exists($class, 'instance')) { exit("{$class} must have property \$instance"); } $prop = new \ReflectionProperty($class, 'instance'); if (!$prop->isStatic()) { exit("Property \$instance must be <b>static</b> for {$class}"); } if (null === $class::$instance) { //** Get custom ( undefined ) Headers from style.css */ global $wp_theme_directories; $stylesheet = get_stylesheet(); $theme_root = get_raw_theme_root($stylesheet); if (false === $theme_root) { $theme_root = WP_CONTENT_DIR . '/themes'; } elseif (!in_array($theme_root, (array) $wp_theme_directories)) { $theme_root = WP_CONTENT_DIR . $theme_root; } $data = get_file_data($theme_root . '/' . get_stylesheet() . '/style.css', array('uservoice_url' => 'UserVoice', 'support_url' => 'Support')); $t = wp_get_theme(get_template()); $args = array_merge((array) $args, $data, array('name' => $t->get('Name'), 'version' => $t->get('Version'), 'template' => $t->get('Template'), 'domain' => $t->get('TextDomain'), 'is_child' => is_child_theme(), 'root_path' => trailingslashit(wp_normalize_path(get_template_directory())), 'root_url' => trailingslashit(wp_normalize_path(get_template_directory_uri())), 'schema_path' => trailingslashit(wp_normalize_path(get_template_directory())) . 'composer.json', 'boot_file' => trailingslashit(wp_normalize_path(get_template_directory())) . 'style.css')); //echo "<pre>"; print_r( $args ); echo "</pre>"; die(); $class::$instance = new $class($args); } return $class::$instance; }