Updates for the job plugin
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 1 Mar 2016 19:54:27 +0000 (14:54 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 1 Mar 2016 19:54:27 +0000 (14:54 -0500)
controllers/admin.php
index.php
views/deniedAccess.php [new file with mode: 0644]
views/front/jobDetail.php
views/optionsPage.php [new file with mode: 0644]
views/page.php [new file with mode: 0644]

index 73b24ac..e315bd7 100644 (file)
@@ -28,7 +28,23 @@ class emmet_employment_admin
         $this->pluginDirName = $path;
         $this->wpdb = $wpdb;
         $jobs = new emmet_employment_job($path);
-        //add_action('admin_menu', array($this, 'add_job_menus'));
+        add_action('admin_menu', array($this, 'add_job_menus'));
+        add_action('admin_init', array($this, 'job_settings_init') );
+    }
+
+    static public function activate_plugin()
+    {
+        emmet_employment_admin::add_capability();
+    }
+
+    static public function add_capability()
+    {
+        $roles = get_editable_roles();
+        foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) {
+            if (isset($roles[$key]) && $role->has_cap(EMMET_EMP_BUILT_IN_CAPABILITY)) {
+                $role->add_cap(EMMET_EMP_NEW_CAPABILITY);
+            }
+        }
     }
 
     /**
@@ -36,30 +52,69 @@ class emmet_employment_admin
      */
     public function add_job_menus()
     {
+        //add_submenu_page(
+            //'edit.php?post_type=' . EMMET_EMP_POST_TYPE,
+            //'applications',
+            //'Applications',
+            //'edit_posts',
+            //'applications',
+            //array($this, 'get_applications')
+        //);
         add_submenu_page(
             'edit.php?post_type=' . EMMET_EMP_POST_TYPE,
-            'applications',
-            'Applications',
+            'settings',
+            'Settings',
             'edit_posts',
-            'applications',
-            array($this, 'get_applications')
+            EMMET_EMP_SETTINGS,
+            array($this, 'show_job_settings')
+        );
+    }
+
+    public function emmetjobs_option_page_capability()
+    {
+        return EMMET_EMP_NEW_CAPABILITY;
+    }
+
+    public function job_settings_init()
+    {
+        add_settings_section(
+            'emmetjobs_setting_section',
+            'Edit Form Settings',
+            array($this, 'emmetjobs_settings_section_callback'),
+            EMMET_EMP_SETTINGS
+        );
+        $fieldNames = array(
+            array(
+                'name'  => 'employment_form_page',
+                'label' => 'Page for the Form',
+                'type'  => 'page'
+            )
         );
-//        add_submenu_page(
-//            'edit.php?post_type=' . EMMET_EMP_POST_TYPE,
-//            'settings',
-//            'Settings',
-//            'manage_options',
-//            'job_settings',
-//            array($this, 'show_job_settings')
-//        );
+
+        foreach ($fieldNames as $field) {
+            $this->emmetjobs_add_setting_text_field(
+                $field['name'],
+                $field['label'],
+                $field['type']
+            );
+        }
+        register_setting(EMMET_EMP_SETTINGS, EMMET_EMP_SETTING_NAME, array($this, 'sanitize_options'));
     }
 
+    public function sanitize_options($input)
+    {
+        return $input;
+    }
     /**
      * show job settings
      */
     public function show_job_settings()
     {
-        echo '<p>Job Settings</p>';
+        if (current_user_can(EMMET_EMP_NEW_CAPABILITY)) {
+            include $this->pluginDirName . 'views/optionsPage.php';
+        } else {
+            include $this->pluginDirName . 'views/deniedAccess.php';
+        }
     }
 
     /**
@@ -145,4 +200,43 @@ class emmet_employment_admin
         $this->pluginDirName = $dir;
     }
 
+    public function emmetjobs_settings_section_callback()
+    {
+        echo __('Employment Form Page', 'wordpress');
+    }
+
+    public function emmetjobs_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;
+        }
+        add_settings_field(
+            $name,
+            $label,
+            array($this, $callback),
+            EMMET_EMP_SETTINGS,
+            'emmetjobs_setting_section',
+            $name
+        );
+    }
+
+    public function render_page_field($fieldName)
+    {
+        static $options;
+        if (!$options) {
+            $options = get_option(EMMET_EMP_SETTINGS);
+        }
+        include $this->pluginDirName . 'views/page.php';
+    }
 }
index d9c2033..c5e19ab 100644 (file)
--- a/index.php
+++ b/index.php
@@ -14,6 +14,9 @@ defined('ABSPATH') or die();
  */
 define('EMMET_EMP_PLUGIN_PATH_FILE', __FILE__);
 define('EMMET_EMP_VERSION', '0.0.1');
+define('EMMET_EMP_SETTING_NAME', 'emmetjobs_settings');
+define('EMMET_EMP_SETTINGS', 'emmetjobs_settings');
+define('EMMET_EMP_NEW_CAPABILITY', 'edit_posts');
 define('EMMET_EMP_VRS_OPTION_NAME', 'emmet_jobs_db_version');
 define('EMMET_EMP_POST_TYPE', 'emmet_jobs');
 define('EMMET_EMP_TAX_CATEGORIES', 'emmet_jobscategory');
diff --git a/views/deniedAccess.php b/views/deniedAccess.php
new file mode 100644 (file)
index 0000000..23bc9e4
--- /dev/null
@@ -0,0 +1 @@
+<div class="wrap"><p>You do not have permission to edit Jobs Setting</p></div>
index 52128f1..dd28eee 100644 (file)
@@ -35,3 +35,6 @@
     <?php endif;?>
 
     <a target="_blank" href="<?php echo get_template_directory_uri();?>/assets/employment-form.pdf">Employment Application</a>
+    <?php if ($applyOnlineHref) : ?>
+    <a href="<?php echo $applyOnlineHref;?>">Apply Online</a>
+    <?php endif;?>
diff --git a/views/optionsPage.php b/views/optionsPage.php
new file mode 100644 (file)
index 0000000..7309ff8
--- /dev/null
@@ -0,0 +1,16 @@
+<style>
+table.form-table th {width: 250px; text-align: right;}
+table.form-table td input[type=text] {width: 400px;}
+table.form-table td textarea {width: 500px; height: 200px;}
+</style>
+<div class="wrap">
+    <form action="options.php" method="post">
+        <h2>Employment Plugin Settings</h2>
+<?php
+settings_errors(EMMET_EMP_SETTINGS);
+settings_fields(EMMET_EMP_SETTINGS);
+do_settings_sections(EMMET_EMP_SETTINGS);
+submit_button();
+?>
+    </form>
+</div>
diff --git a/views/page.php b/views/page.php
new file mode 100644 (file)
index 0000000..70bc14b
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+wp_dropdown_pages(
+    array(
+        'depth'            => 0,
+        'child_of'         => 0,
+        'selected'         => $options[$fieldName],
+        'echo'             => 1,
+        'name'             => EMMET_EMP_SETTINGS . '['.$fieldName.']',
+        'id'               => 'glm_block_page',
+        'show_option_none' => 'None',
+        'post_status'      => 'publish',
+        'post_type'        => 'page'
+    )
+);
+?>
+</select>