Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like WP_Theme often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WP_Theme, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | final class WP_Theme implements ArrayAccess { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Whether the theme has been marked as updateable. |
||
| 13 | * |
||
| 14 | * @since 4.4.0 |
||
| 15 | * @access public |
||
| 16 | * @var bool |
||
| 17 | * |
||
| 18 | * @see WP_MS_Themes_List_Table |
||
| 19 | */ |
||
| 20 | public $update = false; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Headers for style.css files. |
||
| 24 | * |
||
| 25 | * @static |
||
| 26 | * @access private |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | private static $file_headers = array( |
||
| 30 | 'Name' => 'Theme Name', |
||
| 31 | 'ThemeURI' => 'Theme URI', |
||
| 32 | 'Description' => 'Description', |
||
| 33 | 'Author' => 'Author', |
||
| 34 | 'AuthorURI' => 'Author URI', |
||
| 35 | 'Version' => 'Version', |
||
| 36 | 'Template' => 'Template', |
||
| 37 | 'Status' => 'Status', |
||
| 38 | 'Tags' => 'Tags', |
||
| 39 | 'TextDomain' => 'Text Domain', |
||
| 40 | 'DomainPath' => 'Domain Path', |
||
| 41 | ); |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Default themes. |
||
| 45 | * |
||
| 46 | * @static |
||
| 47 | * @access private |
||
| 48 | * @var array |
||
| 49 | */ |
||
| 50 | private static $default_themes = array( |
||
| 51 | 'classic' => 'WordPress Classic', |
||
| 52 | 'default' => 'WordPress Default', |
||
| 53 | 'twentyten' => 'Twenty Ten', |
||
| 54 | 'twentyeleven' => 'Twenty Eleven', |
||
| 55 | 'twentytwelve' => 'Twenty Twelve', |
||
| 56 | 'twentythirteen' => 'Twenty Thirteen', |
||
| 57 | 'twentyfourteen' => 'Twenty Fourteen', |
||
| 58 | 'twentyfifteen' => 'Twenty Fifteen', |
||
| 59 | 'twentysixteen' => 'Twenty Sixteen', |
||
| 60 | ); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Renamed theme tags. |
||
| 64 | * |
||
| 65 | * @static |
||
| 66 | * @access private |
||
| 67 | * @var array |
||
| 68 | */ |
||
| 69 | private static $tag_map = array( |
||
| 70 | 'fixed-width' => 'fixed-layout', |
||
| 71 | 'flexible-width' => 'fluid-layout', |
||
| 72 | ); |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Absolute path to the theme root, usually wp-content/themes |
||
| 76 | * |
||
| 77 | * @access private |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | private $theme_root; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Header data from the theme's style.css file. |
||
| 84 | * |
||
| 85 | * @access private |
||
| 86 | * @var array |
||
| 87 | */ |
||
| 88 | private $headers = array(); |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Header data from the theme's style.css file after being sanitized. |
||
| 92 | * |
||
| 93 | * @access private |
||
| 94 | * @var array |
||
| 95 | */ |
||
| 96 | private $headers_sanitized; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Header name from the theme's style.css after being translated. |
||
| 100 | * |
||
| 101 | * Cached due to sorting functions running over the translated name. |
||
| 102 | * |
||
| 103 | * @access private |
||
| 104 | * @var string |
||
| 105 | */ |
||
| 106 | private $name_translated; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Errors encountered when initializing the theme. |
||
| 110 | * |
||
| 111 | * @access private |
||
| 112 | * @var WP_Error |
||
| 113 | */ |
||
| 114 | private $errors; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * The directory name of the theme's files, inside the theme root. |
||
| 118 | * |
||
| 119 | * In the case of a child theme, this is directory name of the child theme. |
||
| 120 | * Otherwise, 'stylesheet' is the same as 'template'. |
||
| 121 | * |
||
| 122 | * @access private |
||
| 123 | * @var string |
||
| 124 | */ |
||
| 125 | private $stylesheet; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The directory name of the theme's files, inside the theme root. |
||
| 129 | * |
||
| 130 | * In the case of a child theme, this is the directory name of the parent theme. |
||
| 131 | * Otherwise, 'template' is the same as 'stylesheet'. |
||
| 132 | * |
||
| 133 | * @access private |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | private $template; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * A reference to the parent theme, in the case of a child theme. |
||
| 140 | * |
||
| 141 | * @access private |
||
| 142 | * @var WP_Theme |
||
| 143 | */ |
||
| 144 | private $parent; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * URL to the theme root, usually an absolute URL to wp-content/themes |
||
| 148 | * |
||
| 149 | * @access private |
||
| 150 | * var string |
||
| 151 | */ |
||
| 152 | private $theme_root_uri; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Flag for whether the theme's textdomain is loaded. |
||
| 156 | * |
||
| 157 | * @access private |
||
| 158 | * @var bool |
||
| 159 | */ |
||
| 160 | private $textdomain_loaded; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Stores an md5 hash of the theme root, to function as the cache key. |
||
| 164 | * |
||
| 165 | * @access private |
||
| 166 | * @var string |
||
| 167 | */ |
||
| 168 | private $cache_hash; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Flag for whether the themes cache bucket should be persistently cached. |
||
| 172 | * |
||
| 173 | * Default is false. Can be set with the wp_cache_themes_persistently filter. |
||
| 174 | * |
||
| 175 | * @static |
||
| 176 | * @access private |
||
| 177 | * @var bool |
||
| 178 | */ |
||
| 179 | private static $persistently_cache; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Expiration time for the themes cache bucket. |
||
| 183 | * |
||
| 184 | * By default the bucket is not cached, so this value is useless. |
||
| 185 | * |
||
| 186 | * @static |
||
| 187 | * @access private |
||
| 188 | * @var bool |
||
| 189 | */ |
||
| 190 | private static $cache_expiration = 1800; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Constructor for WP_Theme. |
||
| 194 | * |
||
| 195 | * @global array $wp_theme_directories |
||
| 196 | * |
||
| 197 | * @param string $theme_dir Directory of the theme within the theme_root. |
||
| 198 | * @param string $theme_root Theme root. |
||
| 199 | * @param WP_Error|void $_child If this theme is a parent theme, the child may be passed for validation purposes. |
||
| 200 | */ |
||
| 201 | public function __construct( $theme_dir, $theme_root, $_child = null ) { |
||
| 331 | |||
| 332 | /** |
||
| 333 | * When converting the object to a string, the theme name is returned. |
||
| 334 | * |
||
| 335 | * @return string Theme name, ready for display (translated) |
||
| 336 | */ |
||
| 337 | public function __toString() { |
||
| 340 | |||
| 341 | /** |
||
| 342 | * __isset() magic method for properties formerly returned by current_theme_info() |
||
| 343 | * |
||
| 344 | * @staticvar array $properties |
||
| 345 | * |
||
| 346 | * @param string $offset Property to check if set. |
||
| 347 | * @return bool Whether the given property is set. |
||
| 348 | */ |
||
| 349 | public function __isset( $offset ) { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * __get() magic method for properties formerly returned by current_theme_info() |
||
| 360 | * |
||
| 361 | * @param string $offset Property to get. |
||
| 362 | * @return mixed Property value. |
||
| 363 | */ |
||
| 364 | public function __get( $offset ) { |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
||
| 402 | * |
||
| 403 | * @param mixed $offset |
||
| 404 | * @param mixed $value |
||
| 405 | */ |
||
| 406 | public function offsetSet( $offset, $value ) {} |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
||
| 410 | * |
||
| 411 | * @param mixed $offset |
||
| 412 | */ |
||
| 413 | public function offsetUnset( $offset ) {} |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Method to implement ArrayAccess for keys formerly returned by get_themes() |
||
| 417 | * |
||
| 418 | * @staticvar array $keys |
||
| 419 | * |
||
| 420 | * @param mixed $offset |
||
| 421 | * @return bool |
||
| 422 | */ |
||
| 423 | public function offsetExists( $offset ) { |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Method to implement ArrayAccess for keys formerly returned by get_themes(). |
||
| 435 | * |
||
| 436 | * Author, Author Name, Author URI, and Description did not previously return |
||
| 437 | * translated data. We are doing so now as it is safe to do. However, as |
||
| 438 | * Name and Title could have been used as the key for get_themes(), both remain |
||
| 439 | * untranslated for back compatibility. This means that ['Name'] is not ideal, |
||
| 440 | * and care should be taken to use $theme->display('Name') to get a properly |
||
| 441 | * translated header. |
||
| 442 | * |
||
| 443 | * @param mixed $offset |
||
| 444 | * @return mixed |
||
| 445 | */ |
||
| 446 | public function offsetGet( $offset ) { |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Returns errors property. |
||
| 493 | * |
||
| 494 | * @since 3.4.0 |
||
| 495 | * @access public |
||
| 496 | * |
||
| 497 | * @return WP_Error|false WP_Error if there are errors, or false. |
||
| 498 | */ |
||
| 499 | public function errors() { |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Whether the theme exists. |
||
| 505 | * |
||
| 506 | * A theme with errors exists. A theme with the error of 'theme_not_found', |
||
| 507 | * meaning that the theme's directory was not found, does not exist. |
||
| 508 | * |
||
| 509 | * @since 3.4.0 |
||
| 510 | * @access public |
||
| 511 | * |
||
| 512 | * @return bool Whether the theme exists. |
||
| 513 | */ |
||
| 514 | public function exists() { |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Returns reference to the parent theme. |
||
| 520 | * |
||
| 521 | * @since 3.4.0 |
||
| 522 | * @access public |
||
| 523 | * |
||
| 524 | * @return WP_Theme|false Parent theme, or false if the current theme is not a child theme. |
||
| 525 | */ |
||
| 526 | public function parent() { |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Adds theme data to cache. |
||
| 532 | * |
||
| 533 | * Cache entries keyed by the theme and the type of data. |
||
| 534 | * |
||
| 535 | * @since 3.4.0 |
||
| 536 | * @access private |
||
| 537 | * |
||
| 538 | * @param string $key Type of data to store (theme, screenshot, headers, page_templates) |
||
| 539 | * @param string $data Data to store |
||
| 540 | * @return bool Return value from wp_cache_add() |
||
| 541 | */ |
||
| 542 | private function cache_add( $key, $data ) { |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Gets theme data from cache. |
||
| 548 | * |
||
| 549 | * Cache entries are keyed by the theme and the type of data. |
||
| 550 | * |
||
| 551 | * @since 3.4.0 |
||
| 552 | * @access private |
||
| 553 | * |
||
| 554 | * @param string $key Type of data to retrieve (theme, screenshot, headers, page_templates) |
||
| 555 | * @return mixed Retrieved data |
||
| 556 | */ |
||
| 557 | private function cache_get( $key ) { |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Clears the cache for the theme. |
||
| 563 | * |
||
| 564 | * @since 3.4.0 |
||
| 565 | * @access public |
||
| 566 | */ |
||
| 567 | public function cache_delete() { |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Get a raw, unformatted theme header. |
||
| 577 | * |
||
| 578 | * The header is sanitized, but is not translated, and is not marked up for display. |
||
| 579 | * To get a theme header for display, use the display() method. |
||
| 580 | * |
||
| 581 | * Use the get_template() method, not the 'Template' header, for finding the template. |
||
| 582 | * The 'Template' header is only good for what was written in the style.css, while |
||
| 583 | * get_template() takes into account where WordPress actually located the theme and |
||
| 584 | * whether it is actually valid. |
||
| 585 | * |
||
| 586 | * @since 3.4.0 |
||
| 587 | * @access public |
||
| 588 | * |
||
| 589 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
||
| 590 | * @return string|false String on success, false on failure. |
||
| 591 | */ |
||
| 592 | public function get( $header ) { |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Gets a theme header, formatted and translated for display. |
||
| 619 | * |
||
| 620 | * @since 3.4.0 |
||
| 621 | * @access public |
||
| 622 | * |
||
| 623 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
||
| 624 | * @param bool $markup Optional. Whether to mark up the header. Defaults to true. |
||
| 625 | * @param bool $translate Optional. Whether to translate the header. Defaults to true. |
||
| 626 | * @return string|false Processed header, false on failure. |
||
| 627 | */ |
||
| 628 | public function display( $header, $markup = true, $translate = true ) { |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Sanitize a theme header. |
||
| 648 | * |
||
| 649 | * @since 3.4.0 |
||
| 650 | * @access private |
||
| 651 | * |
||
| 652 | * @staticvar array $header_tags |
||
| 653 | * @staticvar array $header_tags_with_a |
||
| 654 | * |
||
| 655 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
||
| 656 | * @param string $value Value to sanitize. |
||
| 657 | * @return mixed |
||
| 658 | */ |
||
| 659 | private function sanitize_header( $header, $value ) { |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Mark up a theme header. |
||
| 707 | * |
||
| 708 | * @since 3.4.0 |
||
| 709 | * @access private |
||
| 710 | * |
||
| 711 | * @staticvar string $comma |
||
| 712 | * |
||
| 713 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
||
| 714 | * @param string $value Value to mark up. |
||
| 715 | * @param string $translate Whether the header has been translated. |
||
| 716 | * @return string Value, marked up. |
||
| 717 | */ |
||
| 718 | private function markup_header( $header, $value, $translate ) { |
||
| 750 | |||
| 751 | /** |
||
| 752 | * Translate a theme header. |
||
| 753 | * |
||
| 754 | * @since 3.4.0 |
||
| 755 | * @access private |
||
| 756 | * |
||
| 757 | * @staticvar array $tags_list |
||
| 758 | * |
||
| 759 | * @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
||
| 760 | * @param string $value Value to translate. |
||
| 761 | * @return string Translated value. |
||
| 762 | */ |
||
| 763 | private function translate_header( $header, $value ) { |
||
| 798 | |||
| 799 | /** |
||
| 800 | * The directory name of the theme's "stylesheet" files, inside the theme root. |
||
| 801 | * |
||
| 802 | * In the case of a child theme, this is directory name of the child theme. |
||
| 803 | * Otherwise, get_stylesheet() is the same as get_template(). |
||
| 804 | * |
||
| 805 | * @since 3.4.0 |
||
| 806 | * @access public |
||
| 807 | * |
||
| 808 | * @return string Stylesheet |
||
| 809 | */ |
||
| 810 | public function get_stylesheet() { |
||
| 813 | |||
| 814 | /** |
||
| 815 | * The directory name of the theme's "template" files, inside the theme root. |
||
| 816 | * |
||
| 817 | * In the case of a child theme, this is the directory name of the parent theme. |
||
| 818 | * Otherwise, the get_template() is the same as get_stylesheet(). |
||
| 819 | * |
||
| 820 | * @since 3.4.0 |
||
| 821 | * @access public |
||
| 822 | * |
||
| 823 | * @return string Template |
||
| 824 | */ |
||
| 825 | public function get_template() { |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Returns the absolute path to the directory of a theme's "stylesheet" files. |
||
| 831 | * |
||
| 832 | * In the case of a child theme, this is the absolute path to the directory |
||
| 833 | * of the child theme's files. |
||
| 834 | * |
||
| 835 | * @since 3.4.0 |
||
| 836 | * @access public |
||
| 837 | * |
||
| 838 | * @return string Absolute path of the stylesheet directory. |
||
| 839 | */ |
||
| 840 | public function get_stylesheet_directory() { |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Returns the absolute path to the directory of a theme's "template" files. |
||
| 849 | * |
||
| 850 | * In the case of a child theme, this is the absolute path to the directory |
||
| 851 | * of the parent theme's files. |
||
| 852 | * |
||
| 853 | * @since 3.4.0 |
||
| 854 | * @access public |
||
| 855 | * |
||
| 856 | * @return string Absolute path of the template directory. |
||
| 857 | */ |
||
| 858 | public function get_template_directory() { |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Returns the URL to the directory of a theme's "stylesheet" files. |
||
| 869 | * |
||
| 870 | * In the case of a child theme, this is the URL to the directory of the |
||
| 871 | * child theme's files. |
||
| 872 | * |
||
| 873 | * @since 3.4.0 |
||
| 874 | * @access public |
||
| 875 | * |
||
| 876 | * @return string URL to the stylesheet directory. |
||
| 877 | */ |
||
| 878 | public function get_stylesheet_directory_uri() { |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Returns the URL to the directory of a theme's "template" files. |
||
| 884 | * |
||
| 885 | * In the case of a child theme, this is the URL to the directory of the |
||
| 886 | * parent theme's files. |
||
| 887 | * |
||
| 888 | * @since 3.4.0 |
||
| 889 | * @access public |
||
| 890 | * |
||
| 891 | * @return string URL to the template directory. |
||
| 892 | */ |
||
| 893 | public function get_template_directory_uri() { |
||
| 901 | |||
| 902 | /** |
||
| 903 | * The absolute path to the directory of the theme root. |
||
| 904 | * |
||
| 905 | * This is typically the absolute path to wp-content/themes. |
||
| 906 | * |
||
| 907 | * @since 3.4.0 |
||
| 908 | * @access public |
||
| 909 | * |
||
| 910 | * @return string Theme root. |
||
| 911 | */ |
||
| 912 | public function get_theme_root() { |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Returns the URL to the directory of the theme root. |
||
| 918 | * |
||
| 919 | * This is typically the absolute URL to wp-content/themes. This forms the basis |
||
| 920 | * for all other URLs returned by WP_Theme, so we pass it to the public function |
||
| 921 | * get_theme_root_uri() and allow it to run the theme_root_uri filter. |
||
| 922 | * |
||
| 923 | * @since 3.4.0 |
||
| 924 | * @access public |
||
| 925 | * |
||
| 926 | * @return string Theme root URI. |
||
| 927 | */ |
||
| 928 | public function get_theme_root_uri() { |
||
| 933 | |||
| 934 | /** |
||
| 935 | * Returns the main screenshot file for the theme. |
||
| 936 | * |
||
| 937 | * The main screenshot is called screenshot.png. gif and jpg extensions are also allowed. |
||
| 938 | * |
||
| 939 | * Screenshots for a theme must be in the stylesheet directory. (In the case of child |
||
| 940 | * themes, parent theme screenshots are not inherited.) |
||
| 941 | * |
||
| 942 | * @since 3.4.0 |
||
| 943 | * @access public |
||
| 944 | * |
||
| 945 | * @param string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI. |
||
| 946 | * @return string|false Screenshot file. False if the theme does not have a screenshot. |
||
| 947 | */ |
||
| 948 | public function get_screenshot( $uri = 'uri' ) { |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Return files in the theme's directory. |
||
| 973 | * |
||
| 974 | * @since 3.4.0 |
||
| 975 | * @access public |
||
| 976 | * |
||
| 977 | * @param mixed $type Optional. Array of extensions to return. Defaults to all files (null). |
||
| 978 | * @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). -1 depth is infinite. |
||
| 979 | * @param bool $search_parent Optional. Whether to return parent files. Defaults to false. |
||
| 980 | * @return array Array of files, keyed by the path to the file relative to the theme's directory, with the values |
||
| 981 | * being absolute paths. |
||
| 982 | */ |
||
| 983 | public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Returns the theme's page templates. |
||
| 994 | * |
||
| 995 | * @since 3.4.0 |
||
| 996 | * @access public |
||
| 997 | * |
||
| 998 | * @param WP_Post|null $post Optional. The post being edited, provided for context. |
||
| 999 | * @return array Array of page templates, keyed by filename, with the value of the translated header name. |
||
| 1000 | */ |
||
| 1001 | public function get_page_templates( $post = null ) { |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Scans a directory for files of a certain extension. |
||
| 1047 | * |
||
| 1048 | * @since 3.4.0 |
||
| 1049 | * |
||
| 1050 | * @static |
||
| 1051 | * @access private |
||
| 1052 | * |
||
| 1053 | * @param string $path Absolute path to search. |
||
| 1054 | * @param array|string|null $extensions Optional. Array of extensions to find, string of a single extension, |
||
| 1055 | * or null for all extensions. Default null. |
||
| 1056 | * @param int $depth Optional. How many levels deep to search for files. Accepts 0, 1+, or |
||
| 1057 | * -1 (infinite depth). Default 0. |
||
| 1058 | * @param string $relative_path Optional. The basename of the absolute path. Used to control the |
||
| 1059 | * returned path for the found files, particularly when this function |
||
| 1060 | * recurses to lower depths. Default empty. |
||
| 1061 | * @return array|false Array of files, keyed by the path to the file relative to the `$path` directory prepended |
||
| 1062 | * with `$relative_path`, with the values being absolute paths. False otherwise. |
||
| 1063 | */ |
||
| 1064 | private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
||
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Loads the theme's textdomain. |
||
| 1098 | * |
||
| 1099 | * Translation files are not inherited from the parent theme. Todo: if this fails for the |
||
| 1100 | * child theme, it should probably try to load the parent theme's translations. |
||
| 1101 | * |
||
| 1102 | * @since 3.4.0 |
||
| 1103 | * @access public |
||
| 1104 | * |
||
| 1105 | * @return bool True if the textdomain was successfully loaded or has already been loaded. |
||
| 1106 | * False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
||
| 1107 | */ |
||
| 1108 | public function load_textdomain() { |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Whether the theme is allowed (multisite only). |
||
| 1135 | * |
||
| 1136 | * @since 3.4.0 |
||
| 1137 | * @access public |
||
| 1138 | * |
||
| 1139 | * @param string $check Optional. Whether to check only the 'network'-wide settings, the 'site' |
||
| 1140 | * settings, or 'both'. Defaults to 'both'. |
||
| 1141 | * @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site. |
||
| 1142 | * @return bool Whether the theme is allowed for the network. Returns true in single-site. |
||
| 1143 | */ |
||
| 1144 | public function is_allowed( $check = 'both', $blog_id = null ) { |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Determines the latest WordPress default theme that is installed. |
||
| 1165 | * |
||
| 1166 | * This hits the filesystem. |
||
| 1167 | * |
||
| 1168 | * @return WP_Theme|false Object, or false if no theme is installed, which would be bad. |
||
| 1169 | */ |
||
| 1170 | public static function get_core_default_theme() { |
||
| 1171 | foreach ( array_reverse( self::$default_themes ) as $slug => $name ) { |
||
| 1172 | $theme = wp_get_theme( $slug ); |
||
| 1173 | if ( $theme->exists() ) { |
||
| 1174 | return $theme; |
||
| 1175 | } |
||
| 1176 | } |
||
| 1177 | return false; |
||
| 1178 | } |
||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Returns array of stylesheet names of themes allowed on the site or network. |
||
| 1182 | * |
||
| 1183 | * @since 3.4.0 |
||
| 1184 | * |
||
| 1185 | * @static |
||
| 1186 | * @access public |
||
| 1187 | * |
||
| 1188 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
||
| 1189 | * @return array Array of stylesheet names. |
||
| 1190 | */ |
||
| 1191 | public static function get_allowed( $blog_id = null ) { |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Returns array of stylesheet names of themes allowed on the network. |
||
| 1209 | * |
||
| 1210 | * @since 3.4.0 |
||
| 1211 | * |
||
| 1212 | * @static |
||
| 1213 | * @access public |
||
| 1214 | * |
||
| 1215 | * @staticvar array $allowed_themes |
||
| 1216 | * |
||
| 1217 | * @return array Array of stylesheet names. |
||
| 1218 | */ |
||
| 1219 | public static function get_allowed_on_network() { |
||
| 1236 | |||
| 1237 | /** |
||
| 1238 | * Returns array of stylesheet names of themes allowed on the site. |
||
| 1239 | * |
||
| 1240 | * @since 3.4.0 |
||
| 1241 | * |
||
| 1242 | * @static |
||
| 1243 | * @access public |
||
| 1244 | * |
||
| 1245 | * @staticvar array $allowed_themes |
||
| 1246 | * |
||
| 1247 | * @param int $blog_id Optional. ID of the site. Defaults to the current site. |
||
| 1248 | * @return array Array of stylesheet names. |
||
| 1249 | */ |
||
| 1250 | public static function get_allowed_on_site( $blog_id = null ) { |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Sorts themes by name. |
||
| 1320 | * |
||
| 1321 | * @since 3.4.0 |
||
| 1322 | * |
||
| 1323 | * @static |
||
| 1324 | * @access public |
||
| 1325 | * |
||
| 1326 | * @param array $themes Array of themes to sort, passed by reference. |
||
| 1327 | */ |
||
| 1328 | public static function sort_by_name( &$themes ) { |
||
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Callback function for usort() to naturally sort themes by name. |
||
| 1338 | * |
||
| 1339 | * Accesses the Name header directly from the class for maximum speed. |
||
| 1340 | * Would choke on HTML but we don't care enough to slow it down with strip_tags(). |
||
| 1341 | * |
||
| 1342 | * @since 3.4.0 |
||
| 1343 | * |
||
| 1344 | * @static |
||
| 1345 | * @access private |
||
| 1346 | * |
||
| 1347 | * @param string $a First name. |
||
| 1348 | * @param string $b Second name. |
||
| 1349 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
||
| 1350 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
||
| 1351 | */ |
||
| 1352 | private static function _name_sort( $a, $b ) { |
||
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Name sort (with translation). |
||
| 1358 | * |
||
| 1359 | * @since 3.4.0 |
||
| 1360 | * |
||
| 1361 | * @static |
||
| 1362 | * @access private |
||
| 1363 | * |
||
| 1364 | * @param string $a First name. |
||
| 1365 | * @param string $b Second name. |
||
| 1366 | * @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
||
| 1367 | * Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
||
| 1368 | */ |
||
| 1369 | private static function _name_sort_i18n( $a, $b ) { |
||
| 1373 | } |
||
| 1374 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.