| @@ -29,8 +29,10 @@ | ||
| 29 | 29 | */ |
| 30 | 30 | public static function add( $property = 'uploaded', $source_type = 'media_library' ){ |
| 31 | 31 | $settings_key = Schema::getConstant('COUNTER_KEY'); |
| 32 | 32 | $data = Utils::get_option( $source_type, [], $settings_key ); |
| 33 | + // Self-heal a legacy/corrupted non-array row instead of crashing on it. | |
| 34 | + $data = is_array($data) ? $data : []; | |
| 33 | 35 | $data[$property] = isset($data[$property]) ? (int)$data[$property] + 1 : 1; |
| 34 | 36 | return Utils::update_option( $source_type, $data, $settings_key ); |
| 35 | 37 | } |
| 36 | 38 | |
| @@ -41,14 +43,14 @@ | ||
| 41 | 43 | * |
| 42 | 44 | */ |
| 43 | 45 | public static function remove( $property = 'uploaded', $source_type = 'media_library' ){ |
| 44 | 46 | $settings_key = Schema::getConstant('COUNTER_KEY'); |
| 45 | - $data = Utils::maybe_unserialize( Utils::get_option_meta( $settings_key, true, true ) ) ?: []; | |
| 47 | + $data = Utils::get_option( $source_type, [], $settings_key ); | |
| 48 | + // Self-heal a legacy/corrupted non-array row instead of crashing on it. | |
| 49 | + $data = is_array($data) ? $data : []; | |
| 50 | + $data[$property] = isset($data[$property]) ? (int)$data[$property] - 1 : -1; | |
| 46 | 51 | |
| 47 | - $source_type_data = isset($data[$source_type]) ? $data[$source_type] : []; | |
| 48 | - $source_type_data[$property] = isset($source_type_data[$property]) ? (int)$source_type_data[$property] - 1 : -1; | |
| 49 | - | |
| 50 | - return Utils::update_option( $source_type, $source_type_data, $settings_key ); | |
| 52 | + return Utils::update_option( $source_type, $data, $settings_key ); | |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | 55 | /** |
| 54 | 56 | * Get Count |
| @@ -67,8 +69,10 @@ | ||
| 67 | 69 | public static function update( $property, $value, $source_type = 'media_library' ) { |
| 68 | 70 | $key = Schema::getConstant('COUNTER_KEY'); |
| 69 | 71 | // Update the count by source type |
| 70 | 72 | $data = Utils::get_option( $source_type, [], $key ); |
| 73 | + // Self-heal a legacy/corrupted non-array row instead of crashing on it. | |
| 74 | + $data = is_array($data) ? $data : []; | |
| 71 | 75 | $data[$property] = $value; |
| 72 | 76 | return Utils::update_option( $source_type, $data, $key ); |
| 73 | 77 | } |
| 74 | 78 | |