|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Carbon_Fields\Container; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon_Fields\Datastore\Datastore; |
|
6
|
|
|
use Carbon_Fields\Exception\Incorrect_Syntax_Exception; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Theme options container class. |
|
10
|
|
|
*/ |
|
11
|
|
|
class Network_Container extends Theme_Options_Container { |
|
12
|
|
|
/** |
|
13
|
|
|
* ID of the site the container is working with |
|
14
|
|
|
* |
|
15
|
|
|
* @see init() |
|
16
|
|
|
* @var int |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $site_id; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct( $id, $title, $type, $condition_collection, $condition_translator ) { |
|
21
|
|
|
parent::__construct( $id, $title, $type, $condition_collection, $condition_translator ); |
|
22
|
|
|
|
|
23
|
|
|
if( !is_multisite() ) { |
|
|
|
|
|
|
24
|
|
|
Incorrect_Syntax_Exception::raise( 'The ' . $title. ' is unavailable because your site is not multisite. ' ); |
|
25
|
|
|
return ; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$this->set_datastore( Datastore::make( 'network' ), $this->has_default_datastore() ); |
|
30
|
|
|
|
|
31
|
|
|
$this->set_site_id( SITE_ID_CURRENT_SITE ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function init() { |
|
35
|
|
|
$registered = $this->register_page(); |
|
36
|
|
|
if ( $registered ) { |
|
37
|
|
|
add_action( 'network_admin_menu', array( $this, '_attach' ) ); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
View Code Duplication |
public function render() { |
|
|
|
|
|
|
42
|
|
|
$input = stripslashes_deep( $_GET ); |
|
43
|
|
|
$request_settings_updated = isset( $input['settings-updated'] ) ? $input['settings-updated'] : ''; |
|
44
|
|
|
if ( $request_settings_updated === 'true' ) { |
|
45
|
|
|
$this->notifications[] = __( 'Settings saved.', 'carbon-fields' ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
include \Carbon_Fields\DIR . '/templates/Container/network.php'; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function set_site_id( $id ) { |
|
52
|
|
|
if( !function_exists( 'get_blog_status' ) ) { |
|
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if( $this->site_exists( $id ) ) { |
|
|
|
|
|
|
57
|
|
|
$this->site_id = $id; |
|
58
|
|
|
} else { |
|
59
|
|
|
Incorrect_Syntax_Exception::raise( 'The specified site id ' . $id . ' does not exist' ); |
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$this->datastore->set_object_id( $this->get_site_id() ); |
|
64
|
|
|
|
|
65
|
|
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function get_site_id() { |
|
69
|
|
|
return $this->site_id; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
protected function site_exists( $id ) { |
|
73
|
|
|
return ( bool ) get_blog_status( $id, 'domain' ); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|