| @@ -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 | |
| @@ -42,8 +44,10 @@ | ||
| 42 | 44 | */ |
| 43 | 45 | public static function remove( $property = 'uploaded', $source_type = 'media_library' ){ |
| 44 | 46 | $settings_key = Schema::getConstant('COUNTER_KEY'); |
| 45 | 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 : []; | |
| 46 | 50 | $data[$property] = isset($data[$property]) ? (int)$data[$property] - 1 : -1; |
| 47 | 51 | |
| 48 | 52 | return Utils::update_option( $source_type, $data, $settings_key ); |
| 49 | 53 | } |
| @@ -65,8 +69,10 @@ | ||
| 65 | 69 | public static function update( $property, $value, $source_type = 'media_library' ) { |
| 66 | 70 | $key = Schema::getConstant('COUNTER_KEY'); |
| 67 | 71 | // Update the count by source type |
| 68 | 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 : []; | |
| 69 | 75 | $data[$property] = $value; |
| 70 | 76 | return Utils::update_option( $source_type, $data, $key ); |
| 71 | 77 | } |
| 72 | 78 | |