From 59ccd52ba7d36164fb9b62ec34d27beaa7bc9081 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 8 Feb 2018 12:23:32 -0500 Subject: [PATCH] Adding new checkbox in setting, lock down menus. Locking down the import and setting to only those with manage_options. Add setting for Show Application Link. --- controllers/admin.php | 95 +++++++++++++++++++++++++++---------------- views/checkbox.php | 3 ++ 2 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 views/checkbox.php diff --git a/controllers/admin.php b/controllers/admin.php index 4fe47c9..5148c8a 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -37,30 +37,36 @@ class glm_employment_admin */ public function add_job_menus() { - add_submenu_page( - 'edit.php?post_type=' . GLM_EMP_POST_TYPE, - 'applications', - 'Applications', - 'edit_posts', - 'applications', - array($this, 'get_applications') - ); - add_submenu_page( - 'edit.php?post_type=' . GLM_EMP_POST_TYPE, - 'import', - 'Import', - 'edit_posts', - 'import', - array($this, 'import') - ); - add_submenu_page( - 'edit.php?post_type=' . GLM_EMP_POST_TYPE, - 'settings', - 'Settings', - 'edit_posts', - GLM_EMP_SETTINGS, - array($this, 'show_job_settings') - ); + $plugin_options = get_option(GLM_EMP_SETTING_NAME); + $showApplicationLink = $plugin_options['show_applications']; + if ( $showApplicationLink ) { + add_submenu_page( + 'edit.php?post_type=' . GLM_EMP_POST_TYPE, + 'applications', + 'Applications', + 'edit_posts', + 'applications', + array($this, 'get_applications') + ); + } + if ( current_user_can( 'manage_options' ) ) { + add_submenu_page( + 'edit.php?post_type=' . GLM_EMP_POST_TYPE, + 'import', + 'Import', + 'edit_posts', + 'import', + array($this, 'import') + ); + add_submenu_page( + 'edit.php?post_type=' . GLM_EMP_POST_TYPE, + 'settings', + 'Settings', + 'edit_posts', + GLM_EMP_SETTINGS, + array($this, 'show_job_settings') + ); + } } static public function activate_plugin() @@ -113,6 +119,11 @@ class glm_employment_admin 'name' => 'employment_form_page', 'label' => 'Page for the Form', 'type' => 'page' + ), + array( + 'name' => 'show_applications', + 'label' => 'Show Application link (deprecated)', + 'type' => 'checkbox' ) ); @@ -185,18 +196,21 @@ class glm_employment_admin public function glmjobs_add_setting_text_field($name, $label, $type) { switch ($type) { - case 'text': - $callback = 'render_text_field'; - break; - case 'textarea': - $callback = 'render_textarea_field'; - break; - case 'page': - $callback = 'render_page_field'; - break; - default: - return false; - break; + case 'checkbox': + $callback = 'render_checkbox_field'; + break; + case 'text': + $callback = 'render_text_field'; + break; + case 'textarea': + $callback = 'render_textarea_field'; + break; + case 'page': + $callback = 'render_page_field'; + break; + default: + return false; + break; } add_settings_field( $name, @@ -226,6 +240,15 @@ class glm_employment_admin include $this->pluginDirName . 'views/text.php'; } + public function render_checkbox_field( $fieldName ) + { + static $options; + if (!$options) { + $options = get_option(GLM_EMP_SETTINGS); + } + include $this->pluginDirName . 'views/checkbox.php'; + } + public function render_textarea_field($fieldName) { static $options; diff --git a/views/checkbox.php b/views/checkbox.php new file mode 100644 index 0000000..6d95a35 --- /dev/null +++ b/views/checkbox.php @@ -0,0 +1,3 @@ + + > -- 2.17.1