@@ -181,15 +181,15 @@ public function get_by_id( $id ) {
181181 */
182182 public function get_by ( $ key , $ value ) {
183183
184- // Don't mutate the underlying resources, so multiple calls to get()
185- // with different order_by and order properties are supported.
186- $ resources = $ this ->resources ;
187-
188184 // Don't attempt sorting if no resources exist.
189185 if ( ! $ this ->exist () ) {
190- return $ resources ;
186+ return false ;
191187 }
192188
189+ // Don't mutate the underlying resources, so multiple calls to get()
190+ // with different order_by and order properties are supported.
191+ $ resources = $ this ->resources ;
192+
193193 foreach ( $ resources as $ id => $ resource ) {
194194 // Remove this resource if it doesn't have the array key.
195195 if ( ! array_key_exists ( $ key , $ resource ) ) {
@@ -332,6 +332,21 @@ public function exist() {
332332 return false ;
333333 }
334334
335+ // If the resources are not an array, no resources exist.
336+ if ( ! is_array ( $ this ->resources ) ) {
337+ return false ;
338+ }
339+
340+ // Ignore cached resources stored in the options table if they are a flat array
341+ // that originates from between 1.6.0 and 1.9.5.2 of the Plugin
342+ // i.e. [id => name], rather than [id => [id => '...', name => '...', ...]].
343+ // The Plugin's upgrade routine must handle converting the flat array to the new array format, but the
344+ // resource classes are typically loaded before this happens, so this check is necessary to avoid
345+ // fatal errors when a user upgrades from 1.6.0...1.9.5.2 to 1.9.6 or higher.
346+ if ( ! is_array ( reset ( $ this ->resources ) ) ) {
347+ return false ;
348+ }
349+
335350 return ( count ( $ this ->resources ) ? true : false );
336351
337352 }
0 commit comments