Skip to content

Commit 6193f63

Browse files
committed
Added cache group option, cleaned up get_carbon_network_option()
1 parent 9d60342 commit 6193f63

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

app/Plugin.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function load_plugin() {
3838

3939
if( !$this->verify_dependencies( 'carbon_fields' ) ) return;
4040

41-
// Add TGM plugin activation notices for required/recommended plugins
41+
// Add TGM Plugin Activation notices for required/recommended plugins
4242
new TGMPA();
4343

4444
// Add admin settings page using Carbon Fields framework
@@ -150,11 +150,11 @@ private function verify_dependencies( $deps = true, $args = array() ) {
150150

151151
case 'carbon_fields':
152152

153-
//if( defined('\\Carbon_Fields\\VERSION') || ( defined('\\Carbon_Fields\\VERSION') && version_compare( \Carbon_Fields\VERSION, $version, '<' ) ) ) {
153+
$cf_version = defined('\\Carbon_Fields\\VERSION') ? current( explode( '-', \Carbon_Fields\VERSION ) ) : null;
154154
if( !$args['activate'] && !defined('\\Carbon_Fields\\VERSION') ) {
155155
$notices[] = __( 'An unknown error occurred while trying to load the Carbon Fields framework.', self::$textdomain );
156-
} else if ( defined('\\Carbon_Fields\\VERSION') && version_compare( \Carbon_Fields\VERSION, $version, '<' ) ) {
157-
$notices[] = __( 'An outdated version of Carbon Fields has been detected:', self::$textdomain ) . ' ' . \Carbon_Fields\VERSION . ' (&gt;= ' . self::$config->get( 'dependencies/carbon_fields' ) . ' ' . __( 'required', self::$textdomain ) . ').' . ' <strong>' . self::$config->get( 'plugin/meta/Name' ) . '</strong> ' . __( 'deactivated.', self::$textdomain ) ;
156+
} else if ( defined('\\Carbon_Fields\\VERSION') && version_compare( $cf_version, $version, '<' ) ) {
157+
$notices[] = __( 'An outdated version of Carbon Fields has been detected:', self::$textdomain ) . ' ' . $cf_version . ' (&gt;= ' . self::$config->get( 'dependencies/carbon_fields' ) . ' ' . __( 'required', self::$textdomain ) . ').' . ' <strong>' . self::$config->get( 'plugin/meta/Name' ) . '</strong> ' . __( 'deactivated.', self::$textdomain ) ;
158158
}
159159
break;
160160

@@ -201,7 +201,7 @@ public static function get_carbon_plugin_option( $key, $cache = true ) {
201201
// Attempt to get value from cache, else fetch value from database
202202
return self::$cache->get_object( $key, function() use ( &$key ) {
203203
return carbon_get_theme_option( $key );
204-
});
204+
}, self::$config->get( 'object_cache/group' ), false );
205205
} else {
206206
// Return uncached value
207207
return carbon_get_theme_option( $key );
@@ -221,24 +221,23 @@ public static function get_carbon_plugin_option( $key, $cache = true ) {
221221
* @since 0.5.0
222222
*
223223
*/
224-
public static function get_carbon_network_option( $key, $container = null, $cache = true, $site_id = null ) {
224+
public static function get_carbon_network_option( $key, $cache = true, $site_id = null ) {
225225

226226
if( !$site_id ) {
227227
if( !defined( 'SITE_ID_CURRENT_SITE' ) ) return null;
228228
$site_id = SITE_ID_CURRENT_SITE;
229229
}
230230

231-
if( !$container ) $container = self::$config->get( 'network/default_options_container' );
232231
$key = self::prefix( $key );
233232

234233
if( $cache ) {
235234
// Attempt to get value from cache, else fetch value from database
236-
return self::$cache->get_object( $key, function() use ( &$key ) {
237-
return carbon_get_network_option( $site_id, $key, $container );
238-
});
235+
return self::$cache->get_object( $key, function() use ( &$site_id, &$key ) {
236+
return carbon_get_network_option( $site_id, $key );
237+
}, self::$config->get( 'object_cache/group' ), true );
239238
} else {
240239
// Return uncached value
241-
return carbon_get_network_option( $site_id, $key, $container );
240+
return carbon_get_network_option( $site_id, $key );
242241
}
243242

244243
}

0 commit comments

Comments
 (0)