From 31f80341d17c7c066491fe39d2619c0cba208505 Mon Sep 17 00:00:00 2001 From: Seb Kay Date: Mon, 5 Feb 2024 08:14:53 +0000 Subject: [PATCH] Move options set up to Plugin class --- inc/options-content.php | 67 -------------------------- inc/options.php | 101 ++++++++++++++++++++++++++-------------- src/Plugin.php | 28 +++++++++-- 3 files changed, 90 insertions(+), 106 deletions(-) delete mode 100644 inc/options-content.php diff --git a/inc/options-content.php b/inc/options-content.php deleted file mode 100644 index ea0b8c1..0000000 --- a/inc/options-content.php +++ /dev/null @@ -1,67 +0,0 @@ - - -
-

- -

- -
- - - -

- -

- - - - - - - - - - - - - - - - -
- - - -
- - - -

- -
- - - -
- -
- - -
-
diff --git a/inc/options.php b/inc/options.php index 7da04ce..af31a16 100644 --- a/inc/options.php +++ b/inc/options.php @@ -1,36 +1,65 @@ - include WPT_DIR_PATH.'/inc/options-content.php' - ); -} - -add_action('admin_menu', 'wpt_create_options_page'); - -/** - * Register custom options - */ -function wpt_register_options() -{ - register_setting('wpt-options', 'wpt_text_option'); - register_setting('wpt-options', 'wpt_radio_option'); - register_setting('wpt-options', 'wpt_select_option'); -} - -add_action('admin_init', 'wpt_register_options'); + + +
+

+ +

+ +
+ + + +

+ +

+ + + + + + + + + + + + + + + + +
+ + + +
+ + + +

+ +
+ + + +
+ +
+ + +
+
diff --git a/src/Plugin.php b/src/Plugin.php index d8c4895..3271cda 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -15,10 +15,32 @@ public function logger(): Logger return $this->logger ??= new Logger(); } - public function run(): void + public function options(): void { - add_action('plugins_loaded', function () { - require_once WPT_DIR_PATH.'/inc/options.php'; + \add_action('admin_menu', function () { + if (! \current_user_can('administrator')) { + return; + } + + \add_submenu_page( + 'options-general.php', + \WPT_PLUGIN_NAME, + \WPT_PLUGIN_NAME, + 'manage_options', + 'wpt-settings', + fn () => include \WPT_DIR_PATH.'/inc/options.php' + ); + }, 10); + + \add_action('admin_init', function () { + \register_setting('wpt-options', 'wpt_text_option'); + \register_setting('wpt-options', 'wpt_radio_option'); + \register_setting('wpt-options', 'wpt_select_option'); }, 10); } + + public function run(): void + { + \add_action('plugins_loaded', [$this, 'options'], 10); + } }