File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -27,19 +27,23 @@ class Addon extends Service {
2727 *
2828 * @since 1.0.0
2929 *
30+ * @param bool $force Should force update cache.
31+ *
3032 * @return array
3133 */
32- public function get_addons (): array {
34+ public function get_addons ( bool $ force = false ): array {
3335 // Only if current plugin has addons.
34- if ( $ this ->plugin ->has_addons () ) {
36+ if ( ! $ this ->plugin ->has_addons () ) {
3537 return array ();
3638 }
3739
3840 // Get from cache first.
39- $ addons = $ this ->get_transient ( 'addons ' );
40- // If found is cache, return it.
41- if ( false !== $ addons ) {
42- return $ addons ;
41+ if ( ! $ force ) {
42+ $ addons = $ this ->get_transient ( 'addons ' );
43+ // If found is cache, return it.
44+ if ( false !== $ addons ) {
45+ return $ addons ;
46+ }
4347 }
4448
4549 // Get from the API.
@@ -49,7 +53,7 @@ public function get_addons(): array {
4953 // Format the data.
5054 $ addons = array_map ( array ( $ this , 'format_addon_data ' ), $ addons );
5155 // Save to cache.
52- $ this ->set_transient ( 'addons ' , $ addons );
56+ $ this ->set_transient ( 'addons ' , $ addons, DAY_IN_SECONDS );
5357
5458 return $ addons ;
5559 }
You can’t perform that action at this time.
0 commit comments