wp_get_themes()
wp_get_themes( array $args = array() ) 根据参数返回WP_主题对象的数组…
wp_get_themes( array $args = array() )
根据参数返回WP_主题对象的数组。
Returns an array of WP_Theme objects based on the arguments.
目录锚点:#说明#参数#源码#笔记
说明(Description)
尽管在get_themes()上有了进步,但是这个函数相当昂贵,并且随着其他主题的增加而线性增长。如果可能,请坚持wp_get_theme()。
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$args | (array) | 搜索的理由errors’(mixed)True返回有错误的主题,false返回没有错误的主题,null返回所有主题。默认为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. |
源码(Source)
/** * 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 * * @global array $wp_theme_directories * @staticvar array $_themes * * @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 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 ) { 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; }
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
3.4.0 | wp-includes/theme.php | 16 | 12 |
笔记(Notes)
例子:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!