Skip to content

Commit 6c92262

Browse files
committed
Add support for top level admin menu page setup.
There are new fields, `parent_slug`, `icon_url`, `position`, for `SettingsPage` options. Those options closely related to the `add_menu_page()` function arguments and have the same defaults. If `parent_slug` value is `own`, page will be a top level menu.
1 parent e8c2a0d commit 6c92262

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

lib/Oow/Settings/SettingsPage.php

+31-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function __construct(array $options = array())
2525
$options = array_merge(array(
2626
'sanitize_callback' => '',
2727
'sections' => array(),
28-
'fields' => array()
28+
'fields' => array(),
29+
'parent_slug' => 'options-general.php',
30+
'icon_url' => '',
31+
'position' => null,
2932
), $options);
3033

3134
$this->registry = $options;
@@ -74,17 +77,16 @@ public function addField(Field $field)
7477
public function render()
7578
{
7679
$reg = $this->registry;
77-
?>
80+
?>
7881
<div class="wrap">
79-
<div class="icon32" id="icon-options-general"><br></div>
80-
<h2><?php echo $reg['page_title']; ?></h2>
82+
<h1><?php echo $reg['page_title']; ?></h1>
8183
<form action="options.php" method="post">
82-
<?php settings_fields($reg['option_name']); ?>
83-
<?php do_settings_sections($reg['option_name']); ?>
84-
<?php submit_button(); ?>
84+
<?php settings_fields($reg['option_name']); ?>
85+
<?php do_settings_sections($reg['option_name']); ?>
86+
<?php submit_button(); ?>
8587
</form>
8688
</div>
87-
<?php
89+
<?php
8890
}
8991

9092
/** @Hook(tag="admin_init") */
@@ -110,12 +112,26 @@ public function setMenu()
110112
{
111113
$reg = $this->registry;
112114

113-
add_options_page(
114-
$reg['page_title'],
115-
$reg['menu_title'],
116-
$reg['capability'],
117-
$reg['option_name'],
118-
array($this, 'render')
119-
);
115+
if ($reg['parent_slug'] == 'own') {
116+
117+
add_menu_page(
118+
$reg['page_title'],
119+
$reg['menu_title'],
120+
$reg['capability'],
121+
$reg['option_name'],
122+
array($this, 'render'),
123+
$reg['icon_url'],
124+
$reg['position']
125+
);
126+
} else {
127+
add_submenu_page(
128+
$reg['parent_slug'],
129+
$reg['page_title'],
130+
$reg['menu_title'],
131+
$reg['capability'],
132+
$reg['option_name'],
133+
array($this, 'render')
134+
);
135+
}
120136
}
121137
}

0 commit comments

Comments
 (0)