Package.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace YahnisElsts\PluginUpdateChecker\v5p1\Theme;
  3. use YahnisElsts\PluginUpdateChecker\v5p1\InstalledPackage;
  4. if ( !class_exists(Package::class, false) ):
  5. class Package extends InstalledPackage {
  6. /**
  7. * @var string Theme directory name.
  8. */
  9. protected $stylesheet;
  10. /**
  11. * @var \WP_Theme Theme object.
  12. */
  13. protected $theme;
  14. public function __construct($stylesheet, $updateChecker) {
  15. $this->stylesheet = $stylesheet;
  16. $this->theme = wp_get_theme($this->stylesheet);
  17. parent::__construct($updateChecker);
  18. }
  19. public function getInstalledVersion() {
  20. return $this->theme->get('Version');
  21. }
  22. public function getAbsoluteDirectoryPath() {
  23. if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
  24. return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
  25. }
  26. return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
  27. }
  28. /**
  29. * Get the value of a specific plugin or theme header.
  30. *
  31. * @param string $headerName
  32. * @param string $defaultValue
  33. * @return string Either the value of the header, or $defaultValue if the header doesn't exist or is empty.
  34. */
  35. public function getHeaderValue($headerName, $defaultValue = '') {
  36. $value = $this->theme->get($headerName);
  37. if ( ($headerName === false) || ($headerName === '') ) {
  38. return $defaultValue;
  39. }
  40. return $value;
  41. }
  42. protected function getHeaderNames() {
  43. return array(
  44. 'Name' => 'Theme Name',
  45. 'ThemeURI' => 'Theme URI',
  46. 'Description' => 'Description',
  47. 'Author' => 'Author',
  48. 'AuthorURI' => 'Author URI',
  49. 'Version' => 'Version',
  50. 'Template' => 'Template',
  51. 'Status' => 'Status',
  52. 'Tags' => 'Tags',
  53. 'TextDomain' => 'Text Domain',
  54. 'DomainPath' => 'Domain Path',
  55. );
  56. }
  57. }
  58. endif;