Skip to content

Commit 1e70c2c

Browse files
committed
Added get_carbon_network_option()
1 parent b4563cc commit 1e70c2c

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

app/Plugin.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,40 @@ public static function get_carbon_plugin_option( $key, $cache = true ) {
205205

206206
}
207207

208+
/**
209+
* Get Carbon Fields network container option (if multisite enabled)
210+
*
211+
* @param string $key The name of the option key
212+
* @param string $container The name of the Carbon Fields network container
213+
* @param bool $cache Whether or not to attempt to get cached value
214+
* @param int $site_id The network site ID to use - default: SITE_ID_CURRENT_SITE
215+
* @return mixed The value of specified Carbon Fields option key
216+
* @link https://carbonfields.net/docs/containers-usage/ Carbon Fields containers
217+
* @since 0.4.1
218+
*
219+
*/
220+
public static function get_carbon_network_option( $key, $container = null, $cache = true, $site_id = null ) {
221+
222+
if( !$site_id ) {
223+
if( !defined( 'SITE_ID_CURRENT_SITE' ) ) return null;
224+
$site_id = SITE_ID_CURRENT_SITE;
225+
}
226+
227+
if( !$container ) $container = self::$config->get( 'network/default_options_container' );
228+
$key = self::prefix( $key );
229+
230+
if( $cache ) {
231+
// Attempt to get value from cache, else fetch value from database
232+
return self::$cache->get_object( $key, function() use ( &$key ) {
233+
return carbon_get_network_option( $site_id, $key, $container );
234+
});
235+
} else {
236+
// Return uncached value
237+
return carbon_get_network_option( $site_id, $key, $container );
238+
}
239+
240+
}
241+
208242
/**
209243
* Get plugin option from WordPress Settings API Class, with object caching
210244
* (if available).

plugin.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
"php": "5.6",
1010
"carbon_fields": "2.1.1",
1111
"wordpress-toolkit": "0.1.3"
12+
},
13+
"network": {
14+
"default_options_container": "global_settings"
1215
}
1316
}

0 commit comments

Comments
 (0)