国内外主机
测评及优惠码

WordPress程序中函数wp_get_themes()应用

  WordPress程序函数wp_get_themes()描述:

  根据参数返回WP_Theme对象的数组。

WordPress程序中函数wp_get_themes()应用

  用法:

  <?php

  $all_themes = wp_get_themes();

  print_r($all_themes);

  ?>

  参数:

  $args

  (array)(可选)用来查询的参数

  ‘errors’

  (mixed)为true时返回有错误主题,为false时返回没有错误的主题,为null则返回所有主题。默认为false。

  ‘allowed’

  (mixed)(多站点)(真),仅返回站点允许的主题。如果返回False,则仅返回网站不允许的主题。“网站”仅返回网站允许的主题。“网络”仅返回允许网络的主题。如果为Null,则返回所有主题。默认为空。

  ‘blog_id’

  (int)多站点)用于计算允许哪些主题的博客ID。默认为0

  默认值: array()

  WordPress程序源文件:

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 ( is_array( $wp_theme_directories ) && 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; } 

赞一个
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《WordPress程序中函数wp_get_themes()应用》
文章链接:https://www.ibytx.com/1806.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册