Adding new checkbox in setting, lock down menus.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Feb 2018 17:23:32 +0000 (12:23 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 8 Feb 2018 17:23:32 +0000 (12:23 -0500)
Locking down the import and setting to only those with manage_options.
Add setting for Show Application Link.

controllers/admin.php
views/checkbox.php [new file with mode: 0644]

index 4fe47c9..5148c8a 100644 (file)
@@ -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 (file)
index 0000000..6d95a35
--- /dev/null
@@ -0,0 +1,3 @@
+<input type="hidden" name="<?php echo GLM_EMP_SETTINGS;?>[<?php echo $fieldName;?>]" value="0">
+<input type="checkbox" name="<?php echo GLM_EMP_SETTINGS;?>[<?php echo $fieldName;?>]"
+           value="1" <?php if ( $options[$fieldName] ) { echo 'checked'; } ?> >