An updated theme (based on Atticus Finch) for ClassicPress
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.1 KiB

3 years ago
  1. <?php
  2. if ( !class_exists('Puc_v4p1_Theme_Update', false) ):
  3. class Puc_v4p1_Theme_Update extends Puc_v4p1_Update {
  4. public $details_url = '';
  5. protected static $extraFields = array('details_url');
  6. /**
  7. * Transform the metadata into the format used by WordPress core.
  8. * Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
  9. *
  10. * @return array
  11. */
  12. public function toWpFormat() {
  13. $update = array(
  14. 'theme' => $this->slug,
  15. 'new_version' => $this->version,
  16. 'url' => $this->details_url,
  17. );
  18. if ( !empty($this->download_url) ) {
  19. $update['package'] = $this->download_url;
  20. }
  21. return $update;
  22. }
  23. /**
  24. * Create a new instance of Theme_Update from its JSON-encoded representation.
  25. *
  26. * @param string $json Valid JSON string representing a theme information object.
  27. * @return self New instance of ThemeUpdate, or NULL on error.
  28. */
  29. public static function fromJson($json) {
  30. $instance = new self();
  31. if ( !parent::createFromJson($json, $instance) ) {
  32. return null;
  33. }
  34. return $instance;
  35. }
  36. /**
  37. * Create a new instance by copying the necessary fields from another object.
  38. *
  39. * @param StdClass|Puc_v4p1_Theme_Update $object The source object.
  40. * @return Puc_v4p1_Theme_Update The new copy.
  41. */
  42. public static function fromObject($object) {
  43. $update = new self();
  44. $update->copyFields($object, $update);
  45. return $update;
  46. }
  47. /**
  48. * Basic validation.
  49. *
  50. * @param StdClass $apiResponse
  51. * @return bool|WP_Error
  52. */
  53. protected function validateMetadata($apiResponse) {
  54. $required = array('version', 'details_url');
  55. foreach($required as $key) {
  56. if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
  57. return new WP_Error(
  58. 'tuc-invalid-metadata',
  59. sprintf('The theme metadata is missing the required "%s" key.', $key)
  60. );
  61. }
  62. }
  63. return true;
  64. }
  65. protected function getFieldNames() {
  66. return array_merge(parent::getFieldNames(), self::$extraFields);
  67. }
  68. protected function getPrefixedFilter($tag) {
  69. return parent::getPrefixedFilter($tag) . '_theme';
  70. }
  71. }
  72. endif;