当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Theme::get_allowed方法代码示例

本文整理汇总了PHP中WP_Theme::get_allowed方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Theme::get_allowed方法的具体用法?PHP WP_Theme::get_allowed怎么用?PHP WP_Theme::get_allowed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Theme的用法示例。


在下文中一共展示了WP_Theme::get_allowed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
}
开发者ID:pausaura,项目名称:agora_nodes,代码行数:75,代码来源:theme.php

示例2: 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);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:13,代码来源:getAllowedFilters.php


注:本文中的WP_Theme::get_allowed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。