Package.php 1.7 KB

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