From 71e906a583d5324692cd2a9f51d5a669a16c696e Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 9 Dec 2015 17:05:58 -0500 Subject: [PATCH] WIP for adding emails form does email need to work on the setting page. --- controllers/admin.php | 142 ++++++++++++++++++++++++++++++++++++++--- controllers/front.php | 19 ++++++ glm-employment.php | 7 ++ views/deniedAccess.php | 1 + views/optionsPage.php | 10 +++ views/text.php | 2 + views/textArea.php | 1 + 7 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 views/deniedAccess.php create mode 100644 views/optionsPage.php create mode 100644 views/text.php create mode 100644 views/textArea.php diff --git a/controllers/admin.php b/controllers/admin.php index 9b89e32..27b4899 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -29,6 +29,7 @@ class staffords_employment_admin $this->wpdb = $wpdb; $jobs = new staffords_employment_job($path); add_action('admin_menu', array($this, 'add_job_menus')); + add_action('admin-init', array($this, 'job_settings_init') ); } /** @@ -44,14 +45,133 @@ class staffords_employment_admin 'applications', array($this, 'get_applications') ); -// add_submenu_page( -// 'edit.php?post_type=' . STAFFORDS_EMP_POST_TYPE, -// 'settings', -// 'Settings', -// 'manage_options', -// 'job_settings', -// array($this, 'show_job_settings') -// ); + add_submenu_page( + 'edit.php?post_type=' . STAFFORDS_EMP_POST_TYPE, + 'settings', + 'Settings', + STAFFORDS_EMP_NEW_CAPABILITY, + STAFFORDS_EMP_SETTINGS, + array($this, 'show_job_settings') + ); + } + + static public function activate_plugin() + { + staffords_employment_admin::add_capability(); + } + + static public function deactivate_plugin() + { + staffords_employment_admin::remove_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(STAFFORDS_EMP_BUILT_IN_CAPABILITY)) { + $role->add_cap(STAFFORDS_EMP_NEW_CAPABILITY); + } + } + } + + static public function remove_capability() + { + $roles = get_editable_roles(); + foreach ($GLOBALS['wp_roles']->role_objects as $key => $role) { + if (isset($roles[$key]) && $role->has_cap(STAFFORDS_EMP_NEW_CAPABILITY)) { + $role->remove_cap(STAFFORDS_EMP_NEW_CAPABILITY); + } + } + } + + public function staffords_settings_exist() + { + if (false == get_option(STAFFORDS_EMP_SETTINGS)) { + add_option(STAFFORDS_EMP_SETTINGS); + } + } + + public function job_settings_init() + { + register_setting(STAFFORDS_EMP_SETTINGS, STAFFORDS_EMP_SETTINGS); + add_filter( + 'option_page_capability_job-setting-group', + array($this, 'staffords_option_page_capability') + ); + add_settings_section( + 'staffordsjobs_main', + __('Edit Jobs Settings', 'wordpress'), + array($this, 'staffords_settings_section_callback'), + 'job-setting-group' + ); + $fieldNames = array( + array( + 'name' => 'notificationEmail', + 'label' => 'Notification Email Address', + 'type' => 'text' + ) + ); + + foreach ($fieldNames as $field) { + $this->staffords_add_setting_text_field( + $field['name'], + $field['label'], + $field['type'] + ); + } + } + + public function staffords_add_setting_text_field($name, $label, $type) + { + switch ($type) { + case 'text': + $callback = 'glmclientinfoRenderText'; + break; + case 'textarea': + $callback = 'glmclientinfoRenderTextArea'; + break; + case 'state': + $callback = 'glmclientinfoRenderStateSelect'; + break; + default: + return false; + break; + } + add_settings_field( + $name, + __($label, 'wordpress'), + array($this, $callback), + 'job-setting-group', + STAFFORDS_EMP_SETTINGS, + $name + ); + } + + public function glmclientinfoRenderText($fieldName) + { + static $options; + if (!$options) { + $options = get_option(STAFFORDS_EMP_SETTINGS); + } + include $this->pluginDirName . 'views/text.php'; + } + + public function glmclientinfoRenderTextArea($fieldName) + { + static $options; + $options = get_option(STAFFORDS_EMP_SETTINGS); + include $this->pluginDirName . 'views/textArea.php'; + } + + public function staffords_settings_section_callback() + { + echo __('Employment Form Email Notification', 'wordpress'); + } + + public function staffords_option_page_capability() + { + return STAFFORDS_EMP_NEW_CAPABILITY; } /** @@ -59,7 +179,11 @@ class staffords_employment_admin */ public function show_job_settings() { - echo '

Job Settings

'; + if (current_user_can(STAFFORDS_EMP_NEW_CAPABILITY)) { + include $this->pluginDirName . 'views/optionsPage.php'; + } else { + include $this->pluginDirName . 'views/deniedAccess.php'; + } } /** diff --git a/controllers/front.php b/controllers/front.php index 5879ca0..4698bbc 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -111,6 +111,24 @@ class staffords_employment_front return $form; } + public function email_owner() + { + $to = 'steve@localhost'; + $name = 'Person Test'; + $email = 'user@gaslightmedia.com'; + $message .= "A new employment application has been submitted. To review this " + . "application, log into your " + . "Web site administration area.\n\n"; + $message .= admin_url() . "edit.php?post_type@staffords_jobs&page=applications\n\n"; + $headers = "From: Online Employment Application Form \r\nReply-To: {$name} <{$email}>"; + wp_mail( + $to, + 'New Online Application Submission', + $message, + $headers + ); + } + /** * Show the application form */ @@ -144,6 +162,7 @@ class staffords_employment_front if ($formPart == self::FINAL_FORM) { include $this->frontViewDir . '/' . self::SUCCESS_TEMPLATE; unset($_SESSION['glmJobsApplication'], $_SESSION['glmJobsAppForm']); + $this->email_owner(); } else { $form = $this->load_form_settings($formPart); include $this->frontViewDir . '/' . self::FORM_TEMPLATE; diff --git a/glm-employment.php b/glm-employment.php index 1cfa662..66d5d1c 100644 --- a/glm-employment.php +++ b/glm-employment.php @@ -14,6 +14,9 @@ defined('ABSPATH') or die(); */ define('STAFFORDS_EMP_PLUGIN_PATH_FILE', __FILE__); define('STAFFORDS_EMP_VERSION', '0.2.1'); +define('STAFFORDS_EMP_SETTINGS', 'staffordsjobs_settings'); +define('STAFFORDS_EMP_NEW_CAPABILITY', 'staffordsjobs_edit_jobs'); +define('STAFFORDS_EMP_BUILT_IN_CAPABILITY', 'edit_posts'); define('STAFFORDS_EMP_VRS_OPTION_NAME', 'staffords_jobs_db_version'); define('STAFFORDS_EMP_POST_TYPE', 'staffords_jobs'); define('STAFFORDS_EMP_TAX_CATEGORIES', 'staffords_jobscategory'); @@ -27,6 +30,10 @@ define('STAFFORDS_EMP_FORM_TABLE', 'staffords_jobs_app_form'); $wp_upload_dir = wp_upload_dir(); define('STAFFORDS_EMP_UPLOAD_DIR', $wp_upload_dir['basedir'] . '/glm-emp/'); define('STAFFORDS_EMP_UPLOAD_URL', $wp_upload_dir['baseurl'] . '/glm-emp/'); + +register_activation_hook(__FILE__, array('staffords_employment_admin', 'activate_plugin')); +register_deactivation_hook(__FILE__, array('staffords_employment_admin', 'deactivate_plugin')); + /** * Create the upload directory for the resume files if not already there */ diff --git a/views/deniedAccess.php b/views/deniedAccess.php new file mode 100644 index 0000000..d8b6753 --- /dev/null +++ b/views/deniedAccess.php @@ -0,0 +1 @@ +

You do not have permission to edit Client Info

\ No newline at end of file diff --git a/views/optionsPage.php b/views/optionsPage.php new file mode 100644 index 0000000..1ad3c8e --- /dev/null +++ b/views/optionsPage.php @@ -0,0 +1,10 @@ +
+
+

Employment Plugin Settings

+ +
+
diff --git a/views/text.php b/views/text.php new file mode 100644 index 0000000..25f9928 --- /dev/null +++ b/views/text.php @@ -0,0 +1,2 @@ +"> diff --git a/views/textArea.php b/views/textArea.php new file mode 100644 index 0000000..1c2044f --- /dev/null +++ b/views/textArea.php @@ -0,0 +1 @@ + -- 2.17.1