コード例 #1
0
ファイル: candela-utility.php プロジェクト: BCcampus/candela
function add_theme($themes)
{
    $merge_themes = array();
    if (\Pressbooks\Book::isBook()) {
        $registered_themes = search_theme_directories();
        foreach ($registered_themes as $key => $val) {
            if ($val['theme_root'] == __DIR__ . '/themes') {
                $merge_themes[$key] = 1;
            }
        }
        // add our theme
        $themes = array_merge($themes, $merge_themes);
    }
    return $themes;
}
コード例 #2
0
 private function core_build_folders_array()
 {
     $theme_directories = search_theme_directories();
     foreach ($theme_directories as $k => $v) {
         $dir = explode('/', $k);
         if (isset($dir[1])) {
             if (!in_array($dir[0], $this->folders_array)) {
                 $this->folders_array[] = $dir[0];
             }
         } else {
             if (!in_array('root', $this->folders_array)) {
                 $this->folders_array[] = 'root';
             }
         }
     }
 }
 /**
  * Add the plugin's specific themes to the PressBooks theme filter.
  * Inspirated from Textbook's one.
  *
  * @since    0.1
  * @param    array $themes The currently allowed themes in PressBooks
  * @return   array The array from the input, with the plugin's themes
  */
 public function add_themes_to_filter($themes)
 {
     $pbt_themes = array();
     if (\Pressbooks\Book::isBook()) {
         $registered_themes = search_theme_directories();
         foreach ($registered_themes as $key => $val) {
             if ($val['theme_root'] == plugin_dir_path(dirname(__FILE__)) . 'themes') {
                 $pbt_themes[$key] = 1;
             }
         }
         // add our theme to the whitelist
         $themes = array_merge($themes, $pbt_themes);
         return $themes;
     } else {
         return $themes;
     }
 }
コード例 #4
0
function rzct_options_page()
{
    include_once RZCT_BASE_DIR . '/admin/rzct-process.php';
    $results = rzct_create_theme();
    if ($results === true) {
        return;
    }
    ?>
	<div class="wrap">
		<?php 
    screen_icon();
    ?>
		<h2><?php 
    esc_html_e('Create a Child Theme', 'rzct');
    ?>
</h2>
		<?php 
    settings_errors();
    ?>
		<form method="post" action="">
		<?php 
    wp_nonce_field('rzct_nonce');
    ?>
		<table class="form-table">
		<?php 
    $opts = array('name' => esc_html__('Child Theme Name', 'rzct'), 'template' => search_theme_directories(), 'uri' => esc_html__('Theme URI (optional)', 'rzct'), 'description' => esc_html__('Description (optional)', 'rzct'), 'version' => esc_html__('Version (optional)', 'rzct'), 'author' => esc_html__('Author (optional)', 'rzct'), 'author_uri' => esc_html__('Author URI (optional)', 'rzct'));
    echo "<tr valign='top'><th scope='row'>" . esc_html__('Template', 'rzct') . "</th><td><select name='rzct_template'>";
    foreach ($opts['template'] as $k => $v) {
        echo "<option value='" . $k . "'>" . $k . "</option>";
    }
    echo "</select></td></tr>";
    echo "<tr valign='top'><th scope='row'>{$opts['name']}</th><td><input class='regular-text' type='text' name='rzct_name' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>{$opts['uri']}</th><td><input class='regular-text' type='text' name='rzct_uri' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>{$opts['description']}</th><td><input class='regular-text' type='text' name='rzct_description' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>{$opts['version']}</th><td><input class='regular-text' type='text' name='rzct_version' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>{$opts['author']}</th><td><input class='regular-text' type='text' name='rzct_author' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>{$opts['author_uri']}</th><td><input class='regular-text' type='text' name='rzct_author_uri' value=''></td></tr>\n\t\t\t<tr valign='top'><th scope='row'>Create a functions.php?</th><td><input class='regular-text' type='checkbox' name='rzct_function'></td</tr>\n\t\t\t<tr valign='top'><th scope='row'>Include changes to parent theme?</th><td><input class='regular-text' type='checkbox' name='rzct_parent'></td></tr>";
    ?>
		</table>
		<?php 
    submit_button(esc_html__('Create a child theme and activate it!', 'rzct'));
    ?>
		</form>
	</div>
<?php 
}
コード例 #5
0
 /**
  * Constructor for WP_Theme.
  *
  * @param string $theme_dir Directory of the theme within the theme_root.
  * @param string $theme_root Theme root.
  * @param WP_Error|null $child If this theme is a parent theme, the child may be passed for validation purposes.
  */
 public function __construct($theme_dir, $theme_root, $child = null)
 {
     // Initialize caching on first run.
     if (!isset(self::$persistently_cache)) {
         self::$persistently_cache = apply_filters('wp_cache_themes_persistently', false, 'WP_Theme');
         if (self::$persistently_cache) {
             wp_cache_add_global_groups('themes');
             if (is_int(self::$persistently_cache)) {
                 self::$cache_expiration = self::$persistently_cache;
             }
         } else {
             wp_cache_add_non_persistent_groups('themes');
         }
     }
     $this->theme_root = $theme_root;
     $this->stylesheet = $theme_dir;
     $theme_file = $this->stylesheet . '/style.css';
     $cache = $this->cache_get('theme');
     if (is_array($cache)) {
         foreach (array('errors', 'headers', 'template') as $key) {
             if (isset($cache[$key])) {
                 $this->{$key} = $cache[$key];
             }
         }
         if ($this->errors) {
             return;
         }
         if (isset($cache['theme_root_template'])) {
             $theme_root_template = $cache['theme_root_template'];
         }
     } elseif (!file_exists($this->theme_root . '/' . $theme_file)) {
         $this->headers['Name'] = $this->stylesheet;
         $this->errors = new WP_Error('theme_no_stylesheet', __('Stylesheet is missing.'));
         $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet));
         if (!file_exists($this->theme_root)) {
             // Don't cache this one.
             $this->errors->add('theme_root_missing', __('ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.'));
         }
         return;
     } elseif (!is_readable($this->theme_root . '/' . $theme_file)) {
         $this->headers['Name'] = $this->stylesheet;
         $this->errors = new WP_Error('theme_stylesheet_not_readable', __('Stylesheet is not readable.'));
         $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet));
         return;
     } else {
         $this->headers = get_file_data($this->theme_root . '/' . $theme_file, self::$file_headers, 'theme');
         // Default themes always trump their pretenders.
         // Properly identify default themes that are inside a directory within wp-content/themes.
         if ($default_theme_slug = array_search($this->headers['Name'], self::$default_themes)) {
             if (basename($this->stylesheet) != $default_theme_slug) {
                 $this->headers['Name'] .= '/' . $this->stylesheet;
             }
         }
     }
     // (If template is set from cache, we know it's good.)
     if (!$this->template && !($this->template = $this->headers['Template'])) {
         if (file_exists($this->theme_root . '/' . $this->stylesheet . '/index.php')) {
             $this->template = $this->stylesheet;
         } else {
             $this->errors = new WP_Error('theme_no_index', __('Template is missing.'));
             $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet));
             return;
         }
     }
     // If we got our data from cache, we can assume that 'template' is pointing to the right place.
     if (!is_array($cache) && $this->template != $this->stylesheet && !file_exists($this->theme_root . '/' . $this->template . '/index.php')) {
         // If we're in a directory of themes inside /themes, look for the parent nearby.
         // wp-content/themes/directory-of-themes/*
         $parent_dir = dirname($this->stylesheet);
         if ('.' != $parent_dir && file_exists($this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php')) {
             $this->template = $parent_dir . '/' . $this->template;
         } elseif (($directories = search_theme_directories()) && isset($directories[$this->template])) {
             // Look for the template in the search_theme_directories() results, in case it is in another theme root.
             // We don't look into directories of themes, just the theme root.
             $theme_root_template = $directories[$this->template]['theme_root'];
         } else {
             // Parent theme is missing.
             $this->errors = new WP_Error('theme_no_parent', sprintf(__('The parent theme is missing. Please install the "%s" parent theme.'), $this->template));
             $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template));
             return;
         }
     }
     // Set the parent, if we're a child theme.
     if ($this->template != $this->stylesheet) {
         // If we are a parent, then there is a problem. Only two generations allowed! Cancel things out.
         if (is_a($child, 'WP_Theme') && $child->template == $this->stylesheet) {
             $child->parent = null;
             $child->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), $child->template));
             $child->cache_add('theme', array('headers' => $child->headers, 'errors' => $child->errors, 'stylesheet' => $child->stylesheet, 'template' => $child->template));
             // The two themes actually reference each other with the Template header.
             if ($child->stylesheet == $this->template) {
                 $this->errors = new WP_Error('theme_parent_invalid', sprintf(__('The "%s" theme is not a valid parent theme.'), $this->template));
                 $this->cache_add('theme', array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template));
             }
             return;
         }
         // Set the parent. Pass the current instance so we can do the crazy checks above and assess errors.
         $this->parent = new WP_Theme($this->template, isset($theme_root_template) ? $theme_root_template : $this->theme_root, $this);
     }
     // We're good. If we didn't retrieve from cache, set it.
     if (!is_array($cache)) {
         $cache = array('headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template);
         // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above.
         if (isset($theme_root_template)) {
             $cache['theme_root_template'] = $theme_root_template;
         }
         $this->cache_add('theme', $cache);
     }
 }
コード例 #6
0
ファイル: theme.php プロジェクト: radman/noobyo-blog
/**
 * Retrieve theme roots.
 *
 * @since 2.9.0
 *
 * @return array|string An array of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
 */
function get_theme_roots()
{
    global $wp_theme_directories;
    if (count($wp_theme_directories) <= 1) {
        return '/themes';
    }
    $theme_roots = get_site_transient('theme_roots');
    if (false === $theme_roots) {
        search_theme_directories(true);
        // Regenerate the transient.
        $theme_roots = get_site_transient('theme_roots');
    }
    return $theme_roots;
}
コード例 #7
0
ファイル: theme-install.php プロジェクト: qaryas/qaryas_site
require_once dirname(__FILE__) . '/admin.php';
require ABSPATH . 'wp-admin/includes/theme-install.php';
wp_reset_vars(array('tab'));
if (!current_user_can('install_themes')) {
    wp_die(__('You do not have sufficient permissions to install themes on this site.'));
}
if (is_multisite() && !is_network_admin()) {
    wp_redirect(network_admin_url('theme-install.php'));
    exit;
}
$title = __('Add Themes');
$parent_file = 'themes.php';
if (!is_network_admin()) {
    $submenu_file = 'themes.php';
}
$installed_themes = search_theme_directories();
foreach ($installed_themes as $k => $v) {
    if (false !== strpos($k, '/')) {
        unset($installed_themes[$k]);
    }
}
wp_localize_script('theme', '_wpThemeSettings', array('themes' => false, 'settings' => array('isInstall' => true, 'canInstall' => current_user_can('install_themes'), 'installURI' => current_user_can('install_themes') ? self_admin_url('theme-install.php') : null, 'adminUrl' => parse_url(self_admin_url(), PHP_URL_PATH)), 'l10n' => array('addNew' => __('Add New Theme'), 'search' => __('Search Themes'), 'searchPlaceholder' => __('Search themes...'), 'upload' => __('Upload Theme'), 'back' => __('Back'), 'error' => __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.'), 'themesFound' => __('Number of Themes found: %d'), 'noThemesFound' => __('No themes found. Try a different search.'), 'collapseSidebar' => __('Collapse Sidebar'), 'expandSidebar' => __('Expand Sidebar')), 'installedThemes' => array_keys($installed_themes)));
wp_enqueue_script('theme');
if ($tab) {
    /**
     * Fires before each of the tabs are rendered on the Install Themes page.
     *
     * The dynamic portion of the hook name, `$tab`, refers to the current
     * theme install tab. Possible values are 'dashboard', 'search', 'upload',
     * 'featured', 'new', or 'updated'.
     *
コード例 #8
0
 public static function get_all()
 {
     if (isset($GLOBALS['ithemes-updater-packages-all'])) {
         return $GLOBALS['ithemes-updater-packages-all'];
     }
     $packages = array();
     // Compatibility fix for WP < 3.1 as the global var is empty by default
     if (empty($GLOBALS['wp_theme_directories'])) {
         get_themes();
     }
     $themes = search_theme_directories();
     if (is_array($themes)) {
         foreach ($themes as $slug => $data) {
             if (!file_exists("{$data['theme_root']}/{$data['theme_file']}")) {
                 continue;
             }
             $headers = get_file_data("{$data['theme_root']}/{$data['theme_file']}", array('package' => 'iThemes Package'), 'theme');
             if (empty($headers['package'])) {
                 continue;
             }
             $packages["{$data['theme_root']}/{$data['theme_file']}"] = $headers['package'];
         }
     }
     require_once ABSPATH . 'wp-admin/includes/plugin.php';
     $plugins = get_plugins();
     foreach ($plugins as $file => $data) {
         if (!file_exists(WP_PLUGIN_DIR . "/{$file}")) {
             continue;
         }
         $headers = get_file_data(WP_PLUGIN_DIR . "/{$file}", array('package' => 'iThemes Package'), 'plugin');
         if (empty($headers['package'])) {
             continue;
         }
         $packages[WP_PLUGIN_DIR . "/{$file}"] = $headers['package'];
     }
     foreach ($packages as $path => $package) {
         $packages[$path] = strtolower($package);
     }
     $GLOBALS['ithemes-updater-packages-all'] = $packages;
     return $packages;
 }
コード例 #9
0
ファイル: theme.php プロジェクト: smrpr/Fatlace
/**
 * Retrieve list of themes with theme data in theme directory.
 *
 * The theme is broken, if it doesn't have a parent theme and is missing either
 * style.css and, or index.php. If the theme has a parent theme then it is
 * broken, if it is missing style.css; index.php is optional. The broken theme
 * list is saved in the {@link $wp_broken_themes} global, which is displayed on
 * the theme list in the administration panels.
 *
 * @since 1.5.0
 * @global array $wp_broken_themes Stores the broken themes.
 * @global array $wp_themes Stores the working themes.
 *
 * @return array Theme list with theme data.
 */
function get_themes()
{
    global $wp_themes, $wp_broken_themes;
    if (isset($wp_themes)) {
        return $wp_themes;
    }
    /* Register the default root as a theme directory */
    register_theme_directory(get_theme_root());
    if (!($theme_files = search_theme_directories())) {
        return false;
    }
    asort($theme_files);
    $wp_themes = array();
    foreach ((array) $theme_files as $theme_file) {
        $theme_root = $theme_file['theme_root'];
        $theme_file = $theme_file['theme_file'];
        if (!is_readable("{$theme_root}/{$theme_file}")) {
            $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
            continue;
        }
        $theme_data = get_theme_data("{$theme_root}/{$theme_file}");
        $name = $theme_data['Name'];
        $title = $theme_data['Title'];
        $description = wptexturize($theme_data['Description']);
        $version = $theme_data['Version'];
        $author = $theme_data['Author'];
        $template = $theme_data['Template'];
        $stylesheet = dirname($theme_file);
        $screenshot = false;
        foreach (array('png', 'gif', 'jpg', 'jpeg') as $ext) {
            if (file_exists("{$theme_root}/{$stylesheet}/screenshot.{$ext}")) {
                $screenshot = "screenshot.{$ext}";
                break;
            }
        }
        if (empty($name)) {
            $name = dirname($theme_file);
            $title = $name;
        }
        $parent_template = $template;
        if (empty($template)) {
            if (file_exists("{$theme_root}/{$stylesheet}/index.php")) {
                $template = $stylesheet;
            } else {
                continue;
            }
        }
        $template = trim($template);
        if (!file_exists("{$theme_root}/{$template}/index.php")) {
            $parent_dir = dirname(dirname($theme_file));
            if (file_exists("{$theme_root}/{$parent_dir}/{$template}/index.php")) {
                $template = "{$parent_dir}/{$template}";
                $template_directory = "{$theme_root}/{$template}";
            } else {
                /**
                 * The parent theme doesn't exist in the current theme's folder or sub folder
                 * so lets use the theme root for the parent template.
                 */
                if (isset($theme_files[$template]) && file_exists($theme_files[$template]['theme_root'] . "/{$template}/index.php")) {
                    $template_directory = $theme_files[$template]['theme_root'] . "/{$template}";
                } else {
                    if (empty($parent_template)) {
                        $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'), 'error' => 'no_template');
                    } else {
                        $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => sprintf(__('The parent theme is missing. Please install the "%s" parent theme.'), $parent_template), 'error' => 'no_parent', 'parent' => $parent_template);
                    }
                    continue;
                }
            }
        } else {
            $template_directory = trim($theme_root . '/' . $template);
        }
        $stylesheet_files = array();
        $template_files = array();
        $stylesheet_dir = @dir("{$theme_root}/{$stylesheet}");
        if ($stylesheet_dir) {
            while (($file = $stylesheet_dir->read()) !== false) {
                if (!preg_match('|^\\.+$|', $file)) {
                    if (preg_match('|\\.css$|', $file)) {
                        $stylesheet_files[] = "{$theme_root}/{$stylesheet}/{$file}";
                    } elseif (preg_match('|\\.php$|', $file)) {
                        $template_files[] = "{$theme_root}/{$stylesheet}/{$file}";
                    }
                }
            }
            @$stylesheet_dir->close();
        }
        $template_dir = @dir("{$template_directory}");
        if ($template_dir) {
            while (($file = $template_dir->read()) !== false) {
                if (preg_match('|^\\.+$|', $file)) {
                    continue;
                }
                if (preg_match('|\\.php$|', $file)) {
                    $template_files[] = "{$template_directory}/{$file}";
                } elseif (is_dir("{$template_directory}/{$file}")) {
                    $template_subdir = @dir("{$template_directory}/{$file}");
                    if (!$template_subdir) {
                        continue;
                    }
                    while (($subfile = $template_subdir->read()) !== false) {
                        if (preg_match('|^\\.+$|', $subfile)) {
                            continue;
                        }
                        if (preg_match('|\\.php$|', $subfile)) {
                            $template_files[] = "{$template_directory}/{$file}/{$subfile}";
                        }
                    }
                    @$template_subdir->close();
                }
            }
            @$template_dir->close();
        }
        //Make unique and remove duplicates when stylesheet and template are the same i.e. most themes
        $template_files = array_unique($template_files);
        $stylesheet_files = array_unique($stylesheet_files);
        $template_dir = dirname($template_files[0]);
        $stylesheet_dir = dirname($stylesheet_files[0]);
        if (empty($template_dir)) {
            $template_dir = '/';
        }
        if (empty($stylesheet_dir)) {
            $stylesheet_dir = '/';
        }
        // Check for theme name collision.  This occurs if a theme is copied to
        // a new theme directory and the theme header is not updated.  Whichever
        // theme is first keeps the name.  Subsequent themes get a suffix applied.
        // The Default and Classic themes always trump their pretenders.
        if (isset($wp_themes[$name])) {
            if (('WordPress Default' == $name || 'WordPress Classic' == $name) && ('default' == $stylesheet || 'classic' == $stylesheet)) {
                // If another theme has claimed to be one of our default themes, move
                // them aside.
                $suffix = $wp_themes[$name]['Stylesheet'];
                $new_name = "{$name}/{$suffix}";
                $wp_themes[$new_name] = $wp_themes[$name];
                $wp_themes[$new_name]['Name'] = $new_name;
            } else {
                $name = "{$name}/{$stylesheet}";
            }
        }
        $theme_roots[$stylesheet] = str_replace(WP_CONTENT_DIR, '', $theme_root);
        $wp_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Author Name' => $theme_data['AuthorName'], 'Author URI' => $theme_data['AuthorURI'], 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir, 'Status' => $theme_data['Status'], 'Screenshot' => $screenshot, 'Tags' => $theme_data['Tags'], 'Theme Root' => $theme_root, 'Theme Root URI' => str_replace(WP_CONTENT_DIR, content_url(), $theme_root));
    }
    unset($theme_files);
    /* Store theme roots in the DB */
    if (get_site_transient('theme_roots') != $theme_roots) {
        set_site_transient('theme_roots', $theme_roots, 7200);
    }
    // cache for two hours
    unset($theme_roots);
    /* Resolve theme dependencies. */
    $theme_names = array_keys($wp_themes);
    foreach ((array) $theme_names as $theme_name) {
        $wp_themes[$theme_name]['Parent Theme'] = '';
        if ($wp_themes[$theme_name]['Stylesheet'] != $wp_themes[$theme_name]['Template']) {
            foreach ((array) $theme_names as $parent_theme_name) {
                if ($wp_themes[$parent_theme_name]['Stylesheet'] == $wp_themes[$parent_theme_name]['Template'] && $wp_themes[$parent_theme_name]['Template'] == $wp_themes[$theme_name]['Template']) {
                    $wp_themes[$theme_name]['Parent Theme'] = $wp_themes[$parent_theme_name]['Name'];
                    break;
                }
            }
        }
    }
    return $wp_themes;
}
コード例 #10
0
 /**
  * Create an instance of WPDKTheme class
  *
  * @brief Construct
  *
  * @param string              $file
  * @param bool|WPDKThemeSetup $setup Optional. A your custom theme setup class model
  *
  * @return WPDKTheme
  */
 public function __construct($file, $setup = false)
 {
     if (false == $setup) {
         $this->setup = $setup = new WPDKThemeSetup();
     }
     $this->setup = apply_filters('wpdk_theme_setup-' . $file, $setup);
     // Autoload
     $this->_wpxThemeClassLoadingPath = array();
     spl_autoload_extensions('.php');
     // for faster execution
     spl_autoload_register(array($this, 'autoloadEnvironment'));
     // Path unix
     $this->path = trailingslashit(dirname($file));
     $this->classesPath = $this->path . 'classes/';
     // URLs.
     $this->url = trailingslashit(get_template_directory_uri());
     $this->assetsURL = $this->url . 'assets/';
     $this->cssURL = $this->assetsURL . 'css/';
     $this->imagesURL = $this->assetsURL . 'images/';
     $this->javascriptURL = $this->assetsURL . 'js/';
     $theme_key = basename(dirname($file));
     $theme_directories = search_theme_directories();
     $theme_file = $theme_directories[$theme_key]['theme_file'];
     $theme_root = $theme_directories[$theme_key]['theme_root'];
     // WP_Theme is a final class, so I must create a part object
     $this->theme = new WP_Theme($theme_key, $theme_root);
     // Loading constants defnies
     $defines = trailingslashit(dirname($file)) . self::DEFINES;
     if (file_exists($defines)) {
         require_once $defines;
     }
     // Register autoload classes
     if (method_exists($this, 'registerClasses')) {
         $this->registerClasses();
     }
     // Avoid access to admin
     add_action('admin_init', array($this, 'admin_init'));
     // Cleanup
     add_action('init', array($this, '_init'));
     // Setup
     add_action('init', array($this, 'init_theme'));
     // Shortcodes
     add_action('init', array($this, 'init_shortcode'));
     // Ajax setup
     if (wpdk_is_ajax()) {
         add_action('init', array($this, 'ajax'));
     }
     // After setup
     add_action('after_setup_theme', array($this, '_after_setup_theme'));
     add_action('after_setup_theme', array($this, 'after_setup_theme'));
     // Fires when scripts and styles are enqueued.
     add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'));
     // Fires before styles in the $handles queue are printed.
     add_action('wp_print_styles', array($this, 'wp_print_styles'));
     // Print scripts or data in the head tag on the front end.
     add_action('wp_head', array($this, '_wp_head'), 0);
     add_action('wp_head', array($this, 'wp_head'));
     // Footer
     add_action('wp_footer', array($this, 'wp_footer'));
     // Add classes to body class
     add_filter('body_class', array($this, '_body_classes'));
     // Custom size
     add_filter('image_size_names_choose', array($this, 'image_size_names_choose'));
 }
コード例 #11
0
 /**
  * get_themes method
  *
  * Wrapper to WP `wp_get_themes` or `get_themes` (whichever is available).
  * Method resets global variables and hooks, required for indexing, whilst
  * performing theme search. After themes are found - it caches these using
  * local static variable and restores global functions.
  *
  * @param bool $force Set to true to re-list themes
  *
  * @return array Map of theme names and their paths
  */
 public function get_themes($force = false, $options = array())
 {
     static $theme_map = array();
     $key = json_encode($options);
     if ($force || !isset($theme_map[$key])) {
         global $wp_theme_directories, $wp_broken_themes;
         $restore_vals = array('wp_theme_directories' => array(AI1EC_THEMES_ROOT), 'wp_broken_themes' => array());
         // mark restore point
         foreach ($restore_vals as $key => $cval) {
             $restore_vals[$key] = ${$key};
             ${$key} = $cval;
         }
         // disable and clean cache
         add_filter('wp_cache_themes_persistently', '__return_false', 1);
         search_theme_directories(true);
         $theme_list = NULL;
         if (function_exists('wp_get_themes')) {
             $theme_list = wp_get_themes($options);
         } else {
             if (isset($options['errors']) && $options['errors']) {
                 $theme_list = get_broken_themes();
             } else {
                 $theme_list = get_themes();
             }
         }
         foreach ($theme_list as $theme) {
             $theme_map[$key][$theme->get('Name')] = $theme;
             $theme->get_theme_root_uri();
             // pre-cache
         }
         unset($theme_list);
         // remove cache disablers and restore values
         remove_filter('wp_cache_themes_persistently', '__return_false', 1);
         foreach ($restore_vals as $key => $cval) {
             ${$key} = $cval;
         }
         search_theme_directories(true);
     }
     return $theme_map[$key];
 }
コード例 #12
0
	/**
	 * Pressbooks filters allowed themes, this adds our themes to the list
	 * 
	 * @since 1.0.7
	 * @param array $themes
	 * @return array
	 */
	function filterChildThemes( $themes ) {
		$pbt_themes = array();

		if ( \Pressbooks\Book::isBook() ) {
			$registered_themes = search_theme_directories();

			foreach ( $registered_themes as $key => $val ) {
				if ( $val['theme_root'] == PBT_PLUGIN_DIR . 'themes-book' ) {
					$pbt_themes[$key] = 1;
				}
			}
			// add our theme
			$themes = array_merge( $themes, $pbt_themes );

			return $themes;
		} else {
			return $themes;
		}
	}
コード例 #13
0
ファイル: search.php プロジェクト: sedici/wpmu-istec
 /**
  * Replacecs global variables.
  *
  * @param array $variables_map
  *
  * @return array
  */
 protected function _replace_search_globals(array $variables_map)
 {
     foreach ($variables_map as $key => $current_value) {
         global ${$key};
         $variables_map[$key] = ${$key};
         ${$key} = $current_value;
     }
     search_theme_directories(true);
     return $variables_map;
 }
コード例 #14
0
 function bulk_upgrade($themes)
 {
     $this->init();
     $this->bulk = true;
     $this->upgrade_strings();
     $current = get_site_transient('update_themes');
     add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
     add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
     add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
     $this->skin->header();
     // Connect to the Filesystem first.
     $res = $this->fs_connect(array(WP_CONTENT_DIR));
     if (!$res) {
         $this->skin->footer();
         return false;
     }
     $this->skin->bulk_header();
     // Only start maintenance mode if running in Multisite OR the theme is in use
     $maintenance = is_multisite();
     // @TODO: This should only kick in for individual sites if at all possible.
     foreach ($themes as $theme) {
         $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
     }
     if ($maintenance) {
         $this->maintenance_mode(true);
     }
     $results = array();
     $this->update_count = count($themes);
     $this->update_current = 0;
     foreach ($themes as $theme) {
         $this->update_current++;
         if (!isset($current->response[$theme])) {
             $this->skin->set_result(false);
             $this->skin->before();
             $this->skin->error('up_to_date');
             $this->skin->after();
             $results[$theme] = false;
             continue;
         }
         $this->skin->theme_info = $this->theme_info($theme);
         // Get the URL to the zip file
         $r = $current->response[$theme];
         $options = array('package' => $r['package'], 'destination' => WP_CONTENT_DIR . '/themes', 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('theme' => $theme));
         $result = $this->run($options);
         $results[$theme] = $this->result;
         // Prevent credentials auth screen from displaying multiple times
         if (false === $result) {
             break;
         }
     }
     //end foreach $plugins
     $this->maintenance_mode(false);
     $this->skin->bulk_footer();
     $this->skin->footer();
     // Cleanup our hooks, in case something else does a upgrade on this connection.
     remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
     remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
     remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
     // Force refresh of theme update information
     delete_site_transient('update_themes');
     search_theme_directories(true);
     foreach (wp_get_themes() as $theme) {
         $theme->cache_delete();
     }
     return $results;
 }
コード例 #15
0
 /**
  * Used by add_filter( 'allowed_themes' ) Will hide any theme not in ./themes-root/* with exceptions
  * for 'pressbooks-root', the PB_ROOT_THEME constant, and $GLOBALS['PB_SECRET_SAUCE']['ROOT_THEMES'][]
  *
  * @param array $themes
  *
  * @return array
  */
 function allowedRootThemes($themes)
 {
     $exceptions = array('pressbooks-root');
     if (defined('PB_ROOT_THEME')) {
         $exceptions[] = PB_ROOT_THEME;
     }
     if (isset($GLOBALS['PB_SECRET_SAUCE']['ROOT_THEMES'])) {
         if (is_array($GLOBALS['PB_SECRET_SAUCE']['ROOT_THEMES'])) {
             $exceptions = array_merge($exceptions, $GLOBALS['PB_SECRET_SAUCE']['ROOT_THEMES']);
         } else {
             $exceptions[] = $GLOBALS['PB_SECRET_SAUCE']['ROOT_THEMES'];
         }
     }
     $compare = search_theme_directories();
     foreach ($compare as $key => $val) {
         if (!in_array($key, $exceptions) && untrailingslashit($val['theme_root']) != PB_PLUGIN_DIR . 'themes-root') {
             unset($themes[$key]);
         }
     }
     return $themes;
 }
コード例 #16
0
 function _unhook_root()
 {
     global $wp_theme_directories;
     if (!$this->hooked_root) {
         return;
     }
     if (isset($this->hooked_root['wp_theme_directories'])) {
         $wp_theme_directories = $this->hooked_root['wp_theme_directories'];
     } else {
         unset($wp_theme_directories);
     }
     remove_filter('wp2android_theme_settings_name', array(&$this, 'wp2android_theme_settings_name'), 99);
     remove_filter('theme_root', array(&$this, 'theme_root'), 99);
     $this->hooked_root = false;
     if (function_exists('search_theme_directories')) {
         search_theme_directories(true);
     }
 }