From c873f4c53d66ba8a9b19f75db7686d8486b8aebb Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 14 Jan 2014 19:28:32 +0000 Subject: [PATCH] Add a filter to allow the consumer to receive customised information from the server I have a need to receive extra information back from the server. In particular, I want to receive information that says "updates entitlement soon expires" or "updates entitlement already expired". Currently, the functions in the class PluginUpdate_1_3 strip out anything not in the private $fields. This change adds a filter to allow the consumer to retain any extra fields they wish. --- plugin-update-checker.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin-update-checker.php b/plugin-update-checker.php index a7366cc..f8e622c 100644 --- a/plugin-update-checker.php +++ b/plugin-update-checker.php @@ -845,7 +845,9 @@ class PluginUpdate_1_3 { */ public static function fromObject($object) { $update = new self(); - foreach(self::$fields as $field){ + $fields = self::$fields; + if (!empty($object->slug)) $fields = apply_filters('puc_retain_fields-'.$object->slug, $fields); + foreach($fields as $field){ $update->$field = $object->$field; } return $update; @@ -861,7 +863,9 @@ class PluginUpdate_1_3 { */ public function toStdClass() { $object = new StdClass(); - foreach(self::$fields as $field){ + $fields = self::$fields; + if (!empty($this->slug)) $fields = apply_filters('puc_retain_fields-'.$this->slug, $fields); + foreach($fields as $field){ $object->$field = $this->$field; } return $object;