本文整理汇总了PHP中WP_Theme类的典型用法代码示例。如果您正苦于以下问题:PHP WP_Theme类的具体用法?PHP WP_Theme怎么用?PHP WP_Theme使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_Theme类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: twentythirteen_switch_theme
/**
* Prevent switching to Twenty Thirteen on old versions of WordPress. Switches
* to the previously activated theme or the default theme.
*
* @since Twenty Thirteen 1.0
*
* @param string $theme_name The theme name.
* @param WP_Theme $theme The theme object.
* @return void
*/
function twentythirteen_switch_theme($theme_name, $theme)
{
if ('twentythirteen' != $theme->get_template()) {
switch_theme($theme->get_template(), $theme->get_stylesheet());
} elseif ('twentythirteen' != WP_DEFAULT_THEME) {
switch_theme(WP_DEFAULT_THEME);
}
unset($_GET['activated']);
add_action('admin_notices', 'twentythirteen_upgrade_notice');
}
示例2: prepare_items
function prepare_items()
{
$themes = wp_get_themes(array('allowed' => true));
if (!empty($_REQUEST['s'])) {
$this->search_terms = array_unique(array_filter(array_map('trim', explode(',', strtolower(wp_unslash($_REQUEST['s']))))));
}
if (!empty($_REQUEST['features'])) {
$this->features = $_REQUEST['features'];
}
if ($this->search_terms || $this->features) {
foreach ($themes as $key => $theme) {
if (!$this->search_theme($theme)) {
unset($themes[$key]);
}
}
}
unset($themes[get_option('stylesheet')]);
WP_Theme::sort_by_name($themes);
$per_page = 36;
$page = $this->get_pagenum();
$start = ($page - 1) * $per_page;
$this->items = array_slice($themes, $start, $per_page, true);
$this->set_pagination_args(array('total_items' => count($themes), 'per_page' => $per_page, 'infinite_scroll' => true));
}
示例3: wpmu_get_blog_allowedthemes
/**
* @deprecated 3.4.0
* @see WP_Theme::get_allowed_on_site()
*/
function wpmu_get_blog_allowedthemes($blog_id = 0)
{
_deprecated_function(__FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_site()');
return array_map('intval', WP_Theme::get_allowed_on_site($blog_id));
}
示例4: search_theme
/**
* @param WP_Theme $theme
* @return bool
*/
public function search_theme($theme)
{
// Search the features
foreach ($this->features as $word) {
if (!in_array($word, $theme->get('Tags'))) {
return false;
}
}
// Match all phrases
foreach ($this->search_terms as $word) {
if (in_array($word, $theme->get('Tags'))) {
continue;
}
foreach (array('Name', 'Description', 'Author', 'AuthorURI') as $header) {
// Don't mark up; Do translate.
if (false !== stripos(strip_tags($theme->display($header, false, true)), $word)) {
continue 2;
}
}
if (false !== stripos($theme->get_stylesheet(), $word)) {
continue;
}
if (false !== stripos($theme->get_template(), $word)) {
continue;
}
return false;
}
return true;
}
示例5: get_theme_version
/**
* Returns the version of the the current theme.
*
* @return string
* The version of the current theme.
*
* @ingroup helperfunc
*/
function get_theme_version()
{
if (class_exists('WP_Theme')) {
$theme = new WP_Theme(get_theme_name(), get_theme_root());
return $theme->get('Version');
} else {
$theme_data = get_theme_data(get_template_directory() . '/style.css');
return $theme_data['Version'];
}
}
示例6: resolveLanguagesPath
public static function resolveLanguagesPath(\WP_Theme $theme)
{
// as taken from wp-includes/class-wp-theme.php:1114
$path = $theme->get_stylesheet_directory();
if ($domainpath = $theme->get('DomainPath')) {
$path .= $domainpath;
} else {
$path .= '/languages';
}
return $path;
}
示例7: get_theme_info_html
protected function get_theme_info_html(WP_Theme $theme)
{
$name = $theme->display('Name');
$version = $theme->display('Version');
$description = $theme->display('Description');
$desc_title = esc_attr($theme->get('Description'));
$author = $theme->display('Author');
$screenshot = $theme->get_screenshot();
$thumbnail_style = $screenshot !== false ? sprintf('style="background-image:url(%s);"', $screenshot) : '';
$theme_url = network_admin_url(add_query_arg('theme', $theme->get_stylesheet(), 'themes.php'));
$version_label = __('Version:', 'wtaiu');
$author_label = __('By', 'wtaiu');
$output = <<<OUTPUT
<div class="theme-info" title="{$desc_title}">
<a href="{$theme_url}" class="theme-screenshot" {$thumbnail_style}></a>
<div class="theme-info-wrap">
<h3 class="theme-info-header" title="{$name}">
<a href="{$theme_url}" class="theme-name">{$name}</a>
</h3>
<p class="theme-version">{$version_label} {$version}</p>
<p class="theme-author">{$author_label} {$author}</p>
</div>
</div>
OUTPUT;
return $output;
}
示例8: outputThemeInfo
protected function outputThemeInfo($theme)
{
$theme_path = wordpress_path('wp-content/themes/') . $theme;
// check
if (!file_exists($theme_path)) {
throw new \InvalidArgumentException("Theme '{$theme}' is not found.");
}
$theme_object = new \WP_Theme($theme, dirname($theme_path));
// // MEMO: template_dir と同じ
// $this->line("<info>[path]</info> '{$theme_path}'");
$properties_wordpress = ['name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet', 'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri'];
foreach ($properties_wordpress as $property) {
$value = $theme_object->{$property};
if (is_array($value)) {
$value = '[' . implode(', ', $value) . ']';
}
$this->line("<info>[{$property}]</info> {$value}");
}
$properties_extra = ['php_namespace' => 'PHP Namespace'];
foreach ($properties_extra as $property => $field) {
$value = $theme_object->get($field);
if (is_array($value)) {
$value = '[' . implode(', ', $value) . ']';
}
$this->line("<info>[{$property}]</info> {$value}");
}
}
示例9: get_switched_theme
/**
* Get the switched theme object.
*
* @return WP_Theme|bool
* @since 0.1
*/
public function get_switched_theme()
{
if (!is_null($this->switched_theme)) {
return $this->switched_theme;
}
$cts = Conditional_Themes_Manager::get_all();
if (is_array($cts) && !empty($cts)) {
foreach ($cts as $ct) {
if (!is_null($this->original_theme)) {
if ($ct->theme === $this->original_theme->get_stylesheet()) {
continue;
}
}
if (!empty($ct->condition) && is_callable($ct->condition)) {
$ct->condition = call_user_func($ct->condition);
$ct->condition = (bool) $ct->condition;
}
if (is_bool($ct->condition) && $ct->condition) {
$theme = wp_get_theme($ct->theme);
if ($theme->exists() && $theme->is_allowed()) {
$this->switched_theme = $theme;
break;
}
}
}
}
if (empty($this->switched_theme)) {
$this->switched_theme = FALSE;
}
return $this->switched_theme;
}
示例10: prepare_items
function prepare_items()
{
global $status, $totals, $page, $orderby, $order, $s;
wp_reset_vars(array('orderby', 'order', 's'));
$themes = array('all' => apply_filters('all_themes', wp_get_themes()), 'search' => array(), 'enabled' => array(), 'disabled' => array(), 'upgrade' => array(), 'broken' => $this->is_site_themes ? array() : wp_get_themes(array('errors' => true)));
if ($this->is_site_themes) {
$themes_per_page = $this->get_items_per_page('site_themes_network_per_page');
$allowed_where = 'site';
} else {
$themes_per_page = $this->get_items_per_page('themes_network_per_page');
$allowed_where = 'network';
}
$maybe_update = current_user_can('update_themes') && !$this->is_site_themes && ($current = get_site_transient('update_themes'));
foreach ((array) $themes['all'] as $key => $theme) {
if ($this->is_site_themes && $theme->is_allowed('network')) {
unset($themes['all'][$key]);
continue;
}
if ($maybe_update && isset($current->response[$key])) {
$themes['all'][$key]->update = true;
$themes['upgrade'][$key] = $themes['all'][$key];
}
$filter = $theme->is_allowed($allowed_where, $this->site_id) ? 'enabled' : 'disabled';
$themes[$filter][$key] = $themes['all'][$key];
}
if ($s) {
$status = 'search';
$themes['search'] = array_filter(array_merge($themes['all'], $themes['broken']), array(&$this, '_search_callback'));
}
$totals = array();
foreach ($themes as $type => $list) {
$totals[$type] = count($list);
}
if (empty($themes[$status]) && !in_array($status, array('all', 'search'))) {
$status = 'all';
}
$this->items = $themes[$status];
WP_Theme::sort_by_name($this->items);
$this->has_items = !empty($themes['all']);
$total_this_page = $totals[$status];
if ($orderby) {
$orderby = ucfirst($orderby);
$order = strtoupper($order);
if ($orderby == 'Name') {
if ('ASC' == $order) {
$this->items = array_reverse($this->items);
}
} else {
uasort($this->items, array(&$this, '_order_callback'));
}
}
$start = ($page - 1) * $themes_per_page;
if ($total_this_page > $themes_per_page) {
$this->items = array_slice($this->items, $start, $themes_per_page, true);
}
$this->set_pagination_args(array('total_items' => $total_this_page, 'per_page' => $themes_per_page));
}
示例11: wp_get_themes
/**
* Returns an array of WP_Theme objects based on the arguments.
*
* Despite advances over get_themes(), this function is quite expensive, and grows
* linearly with additional themes. Stick to wp_get_theme() if possible.
*
* @since 3.4.0
*
* @param array $args The search arguments. Optional.
* - errors mixed True to return themes with errors, false to return themes without errors, null
* to return all themes. Defaults to false.
* - allowed mixed (Multisite) True to return only allowed themes for a site. False to return only
* disallowed themes for a site. 'site' to return only site-allowed themes. 'network'
* to return only network-allowed themes. Null to return all themes. Defaults to null.
* - blog_id int (Multisite) The blog ID used to calculate which themes are allowed. Defaults to 0,
* synonymous for the current blog.
* @return Array of WP_Theme objects.
*/
function wp_get_themes($args = array())
{
global $wp_theme_directories;
$defaults = array('errors' => false, 'allowed' => null, 'blog_id' => 0);
$args = wp_parse_args($args, $defaults);
$theme_directories = search_theme_directories();
if (count($wp_theme_directories) > 1) {
// Make sure the current theme wins out, in case search_theme_directories() picks the wrong
// one in the case of a conflict. (Normally, last registered theme root wins.)
$current_theme = get_stylesheet();
if (isset($theme_directories[$current_theme])) {
$root_of_current_theme = get_raw_theme_root($current_theme);
if (!in_array($root_of_current_theme, $wp_theme_directories)) {
$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme;
}
$theme_directories[$current_theme]['theme_root'] = $root_of_current_theme;
}
}
if (empty($theme_directories)) {
return array();
}
if (is_multisite() && null !== $args['allowed']) {
$allowed = $args['allowed'];
if ('network' === $allowed) {
$theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed_on_network());
} elseif ('site' === $allowed) {
$theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed_on_site($args['blog_id']));
} elseif ($allowed) {
$theme_directories = array_intersect_key($theme_directories, WP_Theme::get_allowed($args['blog_id']));
} else {
$theme_directories = array_diff_key($theme_directories, WP_Theme::get_allowed($args['blog_id']));
}
}
$themes = array();
static $_themes = array();
foreach ($theme_directories as $theme => $theme_root) {
// XTEC ************ AFEGIT - Hide reactor at the theme selector
// 2014.08.29 @sarjona
if ($theme == 'reactor') {
break;
}
//************ FI
if (isset($_themes[$theme_root['theme_root'] . '/' . $theme])) {
$themes[$theme] = $_themes[$theme_root['theme_root'] . '/' . $theme];
} else {
$themes[$theme] = $_themes[$theme_root['theme_root'] . '/' . $theme] = new WP_Theme($theme, $theme_root['theme_root']);
}
}
if (null !== $args['errors']) {
foreach ($themes as $theme => $wp_theme) {
if ($wp_theme->errors() != $args['errors']) {
unset($themes[$theme]);
}
}
}
return $themes;
}
示例12: test_wp_theme_get_allowed_with_site_allowed_themes_filter
/**
* Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
*/
public function test_wp_theme_get_allowed_with_site_allowed_themes_filter()
{
$blog_id = 1;
$this->default_allowed = WP_Theme::get_allowed($blog_id);
add_filter('site_allowed_themes', array($this, 'filter_site_allowed_themes'), 10, 2);
$allowed = WP_Theme::get_allowed($blog_id);
remove_filter('site_allowed_themes', array($this, 'filter_site_allowed_themes'), 10);
$expected = $this->default_allowed + array('site-allowed-theme' => true);
$this->assertEquals($expected, $allowed);
}
示例13: tc_get_theme_data
function tc_get_theme_data($theme_file)
{
if (!class_exists('WP_Theme')) {
return get_theme_data($theme_file);
}
$theme = new WP_Theme(basename(dirname($theme_file)), dirname(dirname($theme_file)));
$theme_data = array('Name' => $theme->get('Name'), 'URI' => $theme->display('ThemeURI', true, false), 'Description' => $theme->display('Description', true, false), 'Author' => $theme->display('Author', true, false), 'AuthorURI' => $theme->display('AuthorURI', true, false), 'Version' => $theme->get('Version'), 'Template' => $theme->get('Template'), 'Status' => $theme->get('Status'), 'Tags' => $theme->get('Tags'), 'Title' => $theme->get('Name'), 'AuthorName' => $theme->display('Author', false, false), 'License' => $theme->display('License', false, false), 'License URI' => $theme->display('License URI', false, false), 'Template Version' => $theme->display('Template Version', false, false));
return $theme_data;
}
示例14: populate_network
/**
* Populate network settings.
*
* @since 3.0.0
*
* @global wpdb $wpdb
* @global object $current_site
* @global int $wp_db_version
* @global WP_Rewrite $wp_rewrite
*
* @param int $network_id ID of network to populate.
* @return bool|WP_Error True on success, or WP_Error on warning (with the install otherwise successful,
* so the error code must be checked) or failure.
*/
function populate_network($network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false)
{
global $wpdb, $current_site, $wp_db_version, $wp_rewrite;
$errors = new WP_Error();
if ('' == $domain) {
$errors->add('empty_domain', __('You must provide a domain name.'));
}
if ('' == $site_name) {
$errors->add('empty_sitename', __('You must provide a name for your network of sites.'));
}
// Check for network collision.
if ($network_id == $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->site} WHERE id = %d", $network_id))) {
$errors->add('siteid_exists', __('The network already exists.'));
}
if (!is_email($email)) {
$errors->add('invalid_email', __('You must provide a valid email address.'));
}
if ($errors->get_error_code()) {
return $errors;
}
// If a user with the provided email does not exist, default to the current user as the new network admin.
$site_user = get_user_by('email', $email);
if (false === $site_user) {
$site_user = wp_get_current_user();
}
// Set up site tables.
$template = get_option('template');
$stylesheet = get_option('stylesheet');
$allowed_themes = array($stylesheet => true);
if ($template != $stylesheet) {
$allowed_themes[$template] = true;
}
if (WP_DEFAULT_THEME != $stylesheet && WP_DEFAULT_THEME != $template) {
$allowed_themes[WP_DEFAULT_THEME] = true;
}
// If WP_DEFAULT_THEME doesn't exist, also whitelist the latest core default theme.
if (!wp_get_theme(WP_DEFAULT_THEME)->exists()) {
if ($core_default = WP_Theme::get_core_default_theme()) {
$allowed_themes[$core_default->get_stylesheet()] = true;
}
}
if (1 == $network_id) {
$wpdb->insert($wpdb->site, array('domain' => $domain, 'path' => $path));
$network_id = $wpdb->insert_id;
} else {
$wpdb->insert($wpdb->site, array('domain' => $domain, 'path' => $path, 'id' => $network_id));
}
wp_cache_delete('networks_have_paths', 'site-options');
if (!is_multisite()) {
$site_admins = array($site_user->user_login);
$users = get_users(array('fields' => array('ID', 'user_login')));
if ($users) {
foreach ($users as $user) {
if (is_super_admin($user->ID) && !in_array($user->user_login, $site_admins)) {
$site_admins[] = $user->user_login;
}
}
}
} else {
$site_admins = get_site_option('site_admins');
}
/* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */
$welcome_email = __('Howdy USERNAME,
Your new SITE_NAME site has been successfully set up at:
BLOG_URL
You can log in to the administrator account with the following information:
Username: USERNAME
Password: PASSWORD
Log in here: BLOG_URLwp-login.php
We hope you enjoy your new site. Thanks!
--The Team @ SITE_NAME');
$misc_exts = array('jpg', 'jpeg', 'png', 'gif', 'mov', 'avi', 'mpg', '3gp', '3g2', 'midi', 'mid', 'pdf', 'doc', 'ppt', 'odt', 'pptx', 'docx', 'pps', 'ppsx', 'xls', 'xlsx', 'key');
$audio_exts = wp_get_audio_extensions();
$video_exts = wp_get_video_extensions();
$upload_filetypes = array_unique(array_merge($misc_exts, $audio_exts, $video_exts));
$sitemeta = array('site_name' => $site_name, 'admin_email' => $email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => implode(' ', $upload_filetypes), 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files'), 'wpmu_upgrade_site' => $wp_db_version, 'welcome_email' => $welcome_email, 'first_post' => __('Welcome to %s. This is your first post. Edit or delete it, then start blogging!'), 'siteurl' => get_option('siteurl') . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => is_multisite() ? get_site_option('upload_space_check_disabled') : '1', 'subdomain_install' => intval($subdomain_install), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'ms_files_rewriting' => is_multisite() ? get_site_option('ms_files_rewriting') : '0', 'initial_db_version' => get_option('initial_db_version'), 'active_sitewide_plugins' => array(), 'WPLANG' => get_locale());
if (!$subdomain_install) {
$sitemeta['illegal_names'][] = 'blog';
}
/**
* Filter meta for a network on creation.
//.........这里部分代码省略.........
示例15: wp_prepare_themes_for_js
/**
* Prepare themes for JavaScript.
*
* @since 3.8.0
*
* @param array $themes Optional. Array of WP_Theme objects to prepare.
* Defaults to all allowed themes.
*
* @return array An associative array of theme data, sorted by name.
*/
function wp_prepare_themes_for_js($themes = null)
{
$current_theme = get_stylesheet();
/**
* Filter theme data before it is prepared for JavaScript.
*
* Passing a non-empty array will result in wp_prepare_themes_for_js() returning
* early with that value instead.
*
* @since 4.2.0
*
* @param array $prepared_themes An associative array of theme data. Default empty array.
* @param null|array $themes An array of WP_Theme objects to prepare, if any.
* @param string $current_theme The current theme slug.
*/
$prepared_themes = (array) apply_filters('pre_prepare_themes_for_js', array(), $themes, $current_theme);
if (!empty($prepared_themes)) {
return $prepared_themes;
}
// Make sure the current theme is listed first.
$prepared_themes[$current_theme] = array();
if (null === $themes) {
$themes = wp_get_themes(array('allowed' => true));
if (!isset($themes[$current_theme])) {
$themes[$current_theme] = wp_get_theme();
}
}
$updates = array();
if (current_user_can('update_themes')) {
$updates_transient = get_site_transient('update_themes');
if (isset($updates_transient->response)) {
$updates = $updates_transient->response;
}
}
WP_Theme::sort_by_name($themes);
$parents = array();
/** @type WP_Theme $theme */
foreach ($themes as $theme) {
$slug = $theme->get_stylesheet();
$encoded_slug = urlencode($slug);
$parent = false;
if ($theme->parent()) {
$parent = $theme->parent()->display('Name');
$parents[$slug] = $theme->parent()->get_stylesheet();
}
$prepared_themes[$slug] = array('id' => $slug, 'name' => $theme->display('Name'), 'screenshot' => array($theme->get_screenshot()), 'description' => $theme->display('Description'), 'author' => $theme->display('Author', false, true), 'authorAndUri' => $theme->display('Author'), 'version' => $theme->display('Version'), 'tags' => $theme->display('Tags'), 'parent' => $parent, 'active' => $slug === $current_theme, 'hasUpdate' => isset($updates[$slug]), 'update' => get_theme_update_available($theme), 'actions' => array('activate' => current_user_can('switch_themes') ? wp_nonce_url(admin_url('themes.php?action=activate&stylesheet=' . $encoded_slug), 'switch-theme_' . $slug) : null, 'customize' => current_user_can('edit_theme_options') && current_user_can('customize') ? wp_customize_url($slug) : null, 'preview' => add_query_arg(array('preview' => 1, 'template' => urlencode($theme->get_template()), 'stylesheet' => urlencode($slug), 'preview_iframe' => true, 'TB_iframe' => true), home_url('/')), 'delete' => current_user_can('delete_themes') ? wp_nonce_url(admin_url('themes.php?action=delete&stylesheet=' . $encoded_slug), 'delete-theme_' . $slug) : null));
}
// Remove 'delete' action if theme has an active child
if (!empty($parents) && array_key_exists($current_theme, $parents)) {
unset($prepared_themes[$parents[$current_theme]]['actions']['delete']);
}
/**
* Filter the themes prepared for JavaScript, for themes.php.
*
* Could be useful for changing the order, which is by name by default.
*
* @since 3.8.0
*
* @param array $prepared_themes Array of themes.
*/
$prepared_themes = apply_filters('wp_prepare_themes_for_js', $prepared_themes);
$prepared_themes = array_values($prepared_themes);
return array_filter($prepared_themes);
}