get_theme_feature_list

Retrieve list of WordPress theme features (aka theme tags).

Description

(array) get_theme_feature_list( (bool) $api = true ); 

Returns (array)

Array of features keyed by category with translations keyed by slug.

Parameters (1)

0. $api — Optional. (bool) => true
Whether try to fetch tags from the WordPress.org API. Defaults to true.

Usage

  1. if ( !function_exists( 'get_theme_feature_list' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/theme.php'; 
  3.  
  4. // Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true. 
  5. $api = true; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_theme_feature_list($api); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/theme.php  
  1. function get_theme_feature_list( $api = true ) { 
  2. // Hard-coded list is used if api not accessible. 
  3. $features = array( 
  4.  
  5. __( 'Layout' ) => array( 
  6. 'grid-layout' => __( 'Grid Layout' ),  
  7. 'one-column' => __( 'One Column' ),  
  8. 'two-columns' => __( 'Two Columns' ),  
  9. 'three-columns' => __( 'Three Columns' ),  
  10. 'four-columns' => __( 'Four Columns' ),  
  11. 'left-sidebar' => __( 'Left Sidebar' ),  
  12. 'right-sidebar' => __( 'Right Sidebar' ),  
  13. ),  
  14.  
  15. __( 'Features' ) => array( 
  16. 'accessibility-ready' => __( 'Accessibility Ready' ),  
  17. 'buddypress' => __( 'BuddyPress' ),  
  18. 'custom-background' => __( 'Custom Background' ),  
  19. 'custom-colors' => __( 'Custom Colors' ),  
  20. 'custom-header' => __( 'Custom Header' ),  
  21. 'custom-logo' => __( 'Custom Logo' ),  
  22. 'custom-menu' => __( 'Custom Menu' ),  
  23. 'editor-style' => __( 'Editor Style' ),  
  24. 'featured-image-header' => __( 'Featured Image Header' ),  
  25. 'featured-images' => __( 'Featured Images' ),  
  26. 'flexible-header' => __( 'Flexible Header' ),  
  27. 'footer-widgets' => __( 'Footer Widgets' ),  
  28. 'front-page-post-form' => __( 'Front Page Posting' ),  
  29. 'full-width-template' => __( 'Full Width Template' ),  
  30. 'microformats' => __( 'Microformats' ),  
  31. 'post-formats' => __( 'Post Formats' ),  
  32. 'rtl-language-support' => __( 'RTL Language Support' ),  
  33. 'sticky-post' => __( 'Sticky Post' ),  
  34. 'theme-options' => __( 'Theme Options' ),  
  35. 'threaded-comments' => __( 'Threaded Comments' ),  
  36. 'translation-ready' => __( 'Translation Ready' ),  
  37. ),  
  38.  
  39. __( 'Subject' ) => array( 
  40. 'blog' => __( 'Blog' ),  
  41. 'e-commerce' => __( 'E-Commerce' ),  
  42. 'education' => __( 'Education' ),  
  43. 'entertainment' => __( 'Entertainment' ),  
  44. 'food-and-drink' => __( 'Food & Drink' ),  
  45. 'holiday' => __( 'Holiday' ),  
  46. 'news' => __( 'News' ),  
  47. 'photography' => __( 'Photography' ),  
  48. 'portfolio' => __( 'Portfolio' ),  
  49. ); 
  50.  
  51. if ( ! $api || ! current_user_can( 'install_themes' ) ) 
  52. return $features; 
  53.  
  54. if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) 
  55. set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); 
  56.  
  57. if ( !$feature_list ) { 
  58. $feature_list = themes_api( 'feature_list', array() ); 
  59. if ( is_wp_error( $feature_list ) ) 
  60. return $features; 
  61.  
  62. if ( !$feature_list ) 
  63. return $features; 
  64.  
  65. set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); 
  66.  
  67. $category_translations = array( 
  68. 'Layout' => __( 'Layout' ),  
  69. 'Features' => __( 'Features' ),  
  70. 'Subject' => __( 'Subject' ),  
  71. ); 
  72.  
  73. // Loop over the wporg canonical list and apply translations 
  74. $wporg_features = array(); 
  75. foreach ( (array) $feature_list as $feature_category => $feature_items ) { 
  76. if ( isset($category_translations[$feature_category]) ) 
  77. $feature_category = $category_translations[$feature_category]; 
  78. $wporg_features[$feature_category] = array(); 
  79.  
  80. foreach ( $feature_items as $feature ) { 
  81. if ( isset($features[$feature_category][$feature]) ) 
  82. $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature]; 
  83. else 
  84. $wporg_features[$feature_category][$feature] = $feature; 
  85.  
  86. return $wporg_features;