@@ -27,6 +27,14 @@ class FrmFormApi {
2727 */
2828 protected $ new_days = 90 ;
2929
30+ /**
31+ * If true, calls to get_api_info will bypass cache.
32+ * This is set true by calling force_api_request.
33+ *
34+ * @var bool
35+ */
36+ protected $ force = false ;
37+
3038 /**
3139 * @since 3.06
3240 *
@@ -84,6 +92,18 @@ public function get_cache_key() {
8492 return $ this ->cache_key ;
8593 }
8694
95+ /**
96+ * Flag the force property as true, so the next API request bypasses cache.
97+ * This is used to pull API data for change logs, which are excluded from the cached data.
98+ *
99+ * @since x.x
100+ *
101+ * @return void
102+ */
103+ public function force_api_request () {
104+ $ this ->force = true ;
105+ }
106+
87107 /**
88108 * @since 3.06
89109 *
@@ -96,7 +116,12 @@ public function get_api_info() {
96116 $ url .= '?l= ' . urlencode ( base64_encode ( $ this ->license ) );
97117 }
98118
99- $ addons = $ this ->get_cached ();
119+ if ( $ this ->force ) {
120+ $ addons = false ;
121+ $ this ->force = false ;
122+ } else {
123+ $ addons = $ this ->get_cached ();
124+ }
100125
101126 if ( is_array ( $ addons ) ) {
102127 return $ addons ;
@@ -344,6 +369,8 @@ protected function get_cached_option() {
344369 * @return void
345370 */
346371 protected function set_cached ( $ addons ) {
372+ $ addons = $ this ->reduce_addon_data_before_caching ( $ addons );
373+
347374 $ data = array (
348375 'timeout ' => strtotime ( $ this ->get_cache_timeout ( $ addons ), time () ),
349376 'value ' => wp_json_encode ( $ addons ),
@@ -359,6 +386,74 @@ protected function set_cached( $addons ) {
359386 }
360387 }
361388
389+ /**
390+ * Remove certain add-on API data that we don't need to cache.
391+ * This is to help keep the option data (which is auto-loaded) small.
392+ *
393+ * @since x.x
394+ *
395+ * @param array $addons
396+ *
397+ * @return array
398+ */
399+ private function reduce_addon_data_before_caching ( $ addons ) {
400+ if ( is_subclass_of ( $ this , 'FrmFormApi ' ) ) {
401+ // We only want to modify FrmFormApi. Leave the other APIs alone for now.
402+ return $ addons ;
403+ }
404+
405+ $ reduced_addons = array ();
406+
407+ foreach ( $ addons as $ key => $ addon ) {
408+ if ( ! is_array ( $ addon ) ) {
409+ $ reduced_addons [ $ key ] = $ addon ;
410+ continue ;
411+ }
412+
413+ if ( ! $ this ->should_include_addon_in_cached_data ( $ addon ) ) {
414+ continue ;
415+ }
416+
417+ if ( isset ( $ addon ['changelog ' ] ) ) {
418+ unset( $ addon ['changelog ' ], $ addon ['banners ' ] );
419+ }
420+
421+ $ reduced_addons [ $ key ] = $ addon ;
422+ }
423+
424+ return $ reduced_addons ;
425+ }
426+
427+ /**
428+ * @since x.x
429+ *
430+ * @param array $addon
431+ *
432+ * @return bool True if the add-on should be included in cached data.
433+ */
434+ private function should_include_addon_in_cached_data ( $ addon ) {
435+ if ( isset ( $ addon ['version ' ] ) && '' === $ addon ['version ' ] ) {
436+ // If version is set but blank, the plugin is not actually live.
437+ return false ;
438+ }
439+
440+ if ( isset ( $ addon ['categories ' ] ) ) {
441+ if ( 'views ' === $ addon ['slug ' ] ) {
442+ // Legacy views has no categories set, but we should still
443+ // include it in cache since it is a valid add-on.
444+ return true ;
445+ }
446+
447+ $ categories_are_empty = ! $ addon ['categories ' ] || $ addon ['categories ' ] === array ( 'Strategy11 ' );
448+
449+ if ( $ categories_are_empty ) {
450+ return false ;
451+ }
452+ }
453+
454+ return true ;
455+ }
456+
362457 /**
363458 * If the last check was a a rate limit, we'll need to check again sooner.
364459 *
0 commit comments