From: Steve Sutton Date: Tue, 1 Mar 2016 19:54:27 +0000 (-0500) Subject: Updates for the job plugin X-Git-Tag: v1.1.0^2~1^2~1 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=3c6e379adeb69f11d5983cc7bc8ca162799f0df7;p=WP-Plugins%2Femmet-employment.git Updates for the job plugin --- diff --git a/controllers/admin.php b/controllers/admin.php index 73b24ac..e315bd7 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -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 '

Job Settings

'; + 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'; + } } diff --git a/index.php b/index.php index d9c2033..c5e19ab 100644 --- 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 index 0000000..23bc9e4 --- /dev/null +++ b/views/deniedAccess.php @@ -0,0 +1 @@ +

You do not have permission to edit Jobs Setting

diff --git a/views/front/jobDetail.php b/views/front/jobDetail.php index 52128f1..dd28eee 100644 --- a/views/front/jobDetail.php +++ b/views/front/jobDetail.php @@ -35,3 +35,6 @@ Employment Application + + Apply Online + diff --git a/views/optionsPage.php b/views/optionsPage.php new file mode 100644 index 0000000..7309ff8 --- /dev/null +++ b/views/optionsPage.php @@ -0,0 +1,16 @@ + +
+
+

Employment Plugin Settings

+ +
+
diff --git a/views/page.php b/views/page.php new file mode 100644 index 0000000..70bc14b --- /dev/null +++ b/views/page.php @@ -0,0 +1,16 @@ + 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' + ) +); +?> +