Skip to content

Commit 9ccf8cb

Browse files
committed
Started adding support for network pages.
1 parent e484d03 commit 9ccf8cb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

includes/AdminSettingsPage.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class AdminSettingsPage {
2727
*/
2828
protected $_field_container;
2929

30+
/**
31+
* @var bool
32+
*/
33+
protected $_network = false;
34+
3035
/**
3136
* AdminSettingsPage constructor.
3237
*
@@ -38,13 +43,21 @@ public function __construct( array $page_args, array $sections ) {
3843
$this->_sections = $sections;
3944
$this->_field_container = $field_container = new FieldContainer();
4045

46+
$this->_network = ! empty( $page_args['network'] );
47+
4148
$defaults = [
4249
'capability' => 'manage_options',
4350
'function' => '',
4451
'icon_url' => '',
52+
'network' => false,
4553
'position' => null,
4654
];
4755

56+
// If creating a network settings page, use a different default permission
57+
if ( $this->_network ) {
58+
$defaults['capability'] = 'manage_network_options';
59+
}
60+
4861
$page = array_merge( $defaults, $page_args, [ 'function' => [ $this, 'renderPage' ] ] );
4962

5063
// Allow `slug` as an alias for `menu_slug`
@@ -107,7 +120,12 @@ public function __construct( array $page_args, array $sections ) {
107120
}
108121

109122
add_action( 'admin_init', [ $this, 'onAdminInit' ] );
110-
add_action( 'admin_menu', [ $this, 'onAdminMenu' ] );
123+
124+
if ( $this->_network ) {
125+
add_action( 'network_admin_menu', [ $this, 'onAdminMenu' ] );
126+
} else {
127+
add_action( 'admin_menu', [ $this, 'onAdminMenu' ] );
128+
}
111129

112130
}
113131

@@ -248,4 +266,4 @@ public function renderPage() {
248266
] );
249267
}
250268

251-
}
269+
}

0 commit comments

Comments
 (0)