-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathNetwork_Container.php
More file actions
87 lines (74 loc) · 1.91 KB
/
Copy pathNetwork_Container.php
File metadata and controls
87 lines (74 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Carbon_Fields\Container;
use Carbon_Fields\Datastore\Datastore;
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
/**
* Theme options container class.
*/
class Network_Container extends Theme_Options_Container {
/**
* ID of the site the container is operating with
*
* @see init()
* @var int
*/
protected $site_id;
/**
* {@inheritDoc}
*/
public function __construct( $id, $title, $type, $condition_collection, $condition_translator ) {
parent::__construct( $id, $title, $type, $condition_collection, $condition_translator );
if ( ! is_multisite() ) {
Incorrect_Syntax_Exception::raise( 'The "' . $title . '" container will not be available because your site is not a multisite.' );
return;
}
$this->set_datastore( Datastore::make( 'network' ), $this->has_default_datastore() );
$this->set_site_id( SITE_ID_CURRENT_SITE );
}
/**
* {@inheritDoc}
*/
public function init() {
$registered = $this->register_page();
if ( $registered ) {
add_action( 'network_admin_menu', array( $this, '_attach' ) );
}
}
/**
* Check if a network site exists by id
*
* @param integer $id
* @return boolean
*/
protected function site_exists( $id ) {
global $wpdb;
$network = $wpdb->get_row( $wpdb->prepare(
"SELECT id FROM {$wpdb->site} WHERE id = %d", $id
) );
return ! empty( $network );
}
/**
* Get the site ID the container is operating with.
*
* @return integer
*/
public function get_site_id() {
return $this->site_id;
}
/**
* Set the site ID the container will operate with.
*
* @param int $id
* @return self $this
*/
public function set_site_id( $id ) {
$id = intval( $id );
if ( ! $this->site_exists( $id ) ) {
Incorrect_Syntax_Exception::raise( 'The specified site id #' . $id . ' does not exist' );
return $this;
}
$this->site_id = $id;
$this->datastore->set_object_id( $this->get_site_id() );
return $this;
}
}