@@ -15,29 +15,29 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | interface JsonWpOptionSerializableInterface |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to |
|
| 20 | - * determine what option name to use. |
|
| 21 | - * @since $VID:$ |
|
| 22 | - * @return string |
|
| 23 | - */ |
|
| 24 | - public function getWpOptionName(); |
|
| 18 | + /** |
|
| 19 | + * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to |
|
| 20 | + * determine what option name to use. |
|
| 21 | + * @since $VID:$ |
|
| 22 | + * @return string |
|
| 23 | + */ |
|
| 24 | + public function getWpOptionName(); |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Creates a simple PHP array or stdClass from this object's properties, which can be easily serialized using |
|
| 28 | - * wp_json_serialize(). |
|
| 29 | - * @since $VID:$ |
|
| 30 | - * @return mixed |
|
| 31 | - */ |
|
| 32 | - public function toJsonSerializableData(); |
|
| 26 | + /** |
|
| 27 | + * Creates a simple PHP array or stdClass from this object's properties, which can be easily serialized using |
|
| 28 | + * wp_json_serialize(). |
|
| 29 | + * @since $VID:$ |
|
| 30 | + * @return mixed |
|
| 31 | + */ |
|
| 32 | + public function toJsonSerializableData(); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Initializes this object from data |
|
| 36 | - * @since $VID:$ |
|
| 37 | - * @param mixed $data |
|
| 38 | - * @return boolean success |
|
| 39 | - */ |
|
| 40 | - public function fromJsonSerializedData($data); |
|
| 34 | + /** |
|
| 35 | + * Initializes this object from data |
|
| 36 | + * @since $VID:$ |
|
| 37 | + * @param mixed $data |
|
| 38 | + * @return boolean success |
|
| 39 | + */ |
|
| 40 | + public function fromJsonSerializedData($data); |
|
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | // End of file JsonWpOptionSerializableInterface.php |
@@ -16,39 +16,39 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class JsonWpOptionManager |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
| 21 | - * the object alone and returns false. |
|
| 22 | - * @since $VID:$ |
|
| 23 | - * @param JsonWpOptionSerializableInterface $obj |
|
| 24 | - * @return bool |
|
| 25 | - */ |
|
| 26 | - public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
| 27 | - { |
|
| 28 | - $option = get_option($obj->getWpOptionName()); |
|
| 29 | - if ($option) { |
|
| 30 | - $json = json_decode($option); |
|
| 31 | - if (is_array($json) || $json instanceof stdClass) { |
|
| 32 | - return $obj->fromJsonSerializedData($json); |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - return false; |
|
| 36 | - } |
|
| 19 | + /** |
|
| 20 | + * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves |
|
| 21 | + * the object alone and returns false. |
|
| 22 | + * @since $VID:$ |
|
| 23 | + * @param JsonWpOptionSerializableInterface $obj |
|
| 24 | + * @return bool |
|
| 25 | + */ |
|
| 26 | + public function populateFromDb(JsonWpOptionSerializableInterface $obj) |
|
| 27 | + { |
|
| 28 | + $option = get_option($obj->getWpOptionName()); |
|
| 29 | + if ($option) { |
|
| 30 | + $json = json_decode($option); |
|
| 31 | + if (is_array($json) || $json instanceof stdClass) { |
|
| 32 | + return $obj->fromJsonSerializedData($json); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Saves the object's data to the wp_options table for later use. |
|
| 40 | - * @since $VID:$ |
|
| 41 | - * @param JsonWpOptionSerializableInterface $obj |
|
| 42 | - * @return bool |
|
| 43 | - */ |
|
| 44 | - public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
| 45 | - { |
|
| 46 | - return update_option( |
|
| 47 | - $obj->getWpOptionName(), |
|
| 48 | - wp_json_encode($obj->toJsonSerializableData()), |
|
| 49 | - false |
|
| 50 | - ); |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * Saves the object's data to the wp_options table for later use. |
|
| 40 | + * @since $VID:$ |
|
| 41 | + * @param JsonWpOptionSerializableInterface $obj |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function saveToDb(JsonWpOptionSerializableInterface $obj) |
|
| 45 | + { |
|
| 46 | + return update_option( |
|
| 47 | + $obj->getWpOptionName(), |
|
| 48 | + wp_json_encode($obj->toJsonSerializableData()), |
|
| 49 | + false |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | // End of file JsonWpOptionManager.php |