From 3b15b1a28fed472969849606662aea06feb4ecf8 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 11 Dec 2015 09:19:17 -0500 Subject: [PATCH] Updates on the email notifications I have the setting page working and storing the emails. Each property taxomony has a setting for name and email that will be used for the application form. --- controllers/admin.php | 94 +++++++++++++++++++++++++++++++++++++------ controllers/front.php | 63 +++++++++++++++++++++++++---- glm-employment.php | 1 + views/optionsPage.php | 9 ++++- 4 files changed, 144 insertions(+), 23 deletions(-) diff --git a/controllers/admin.php b/controllers/admin.php index 27b4899..07bb7c3 100644 --- a/controllers/admin.php +++ b/controllers/admin.php @@ -29,7 +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') ); + add_action('admin_init', array($this, 'job_settings_init') ); } /** @@ -94,24 +94,86 @@ class staffords_employment_admin 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_filter( + //'option_page_capability_job-setting-group', + //array($this, 'staffords_option_page_capability') + //); + add_settings_section( + 'staffordsjobs_setting_section_two', + 'Edit Confirmations', + array($this, 'staffords_settings_two_section_callback'), + 'staffordsjobs_settings' + ); + add_settings_field( + 'thank_you_text', + 'Thank You Message', + array($this, 'glmclientinfoRenderTextArea'), + 'staffordsjobs_settings', + 'staffordsjobs_setting_section_two', + 'thank_you_text' ); add_settings_section( - 'staffordsjobs_main', - __('Edit Jobs Settings', 'wordpress'), + 'staffordsjobs_setting_section', + 'Edit Notifications', array($this, 'staffords_settings_section_callback'), - 'job-setting-group' + 'staffordsjobs_settings' ); $fieldNames = array( array( - 'name' => 'notificationEmail', - 'label' => 'Notification Email Address', + 'name' => 'notification_name', + 'label' => 'Staffords Notify: Name', + 'type' => 'text' + ), + array( + 'name' => 'notification_email', + 'label' => 'Staffords Notify: Email', + 'type' => 'text' + ), + array( + 'name' => 'from_name', + 'label' => 'From: Name', + 'type' => 'text' + ), + array( + 'name' => 'from_email', + 'label' => 'From: Email', + 'type' => 'text' + ), + array( + 'name' => 'replyto_name', + 'label' => 'Reply-To: Name', + 'type' => 'text' + ), + array( + 'name' => 'replyto_email', + 'label' => 'Reply-To: Email', 'type' => 'text' + ), + array( + 'name' => 'notification_message', + 'label' => 'Notification Message', + 'type' => 'textarea' + ), + ); + $terms = get_terms( + STAFFORDS_EMP_TAX_DEPARTMENTS, + array( + 'hide_empty' => false ) ); + foreach ($terms as $term) { + $termArray[] = $term->name; + $fieldNames[] = array( + 'name' => $term->slug . '_notification_name', + 'label' => $term->name . ': Name', + 'type' => 'text' + ); + $fieldNames[] = array( + 'name' => $term->slug . '_notification_email', + 'label' => $term->name . ': Email', + 'type' => 'text' + ); + } foreach ($fieldNames as $field) { $this->staffords_add_setting_text_field( @@ -120,6 +182,7 @@ class staffords_employment_admin $field['type'] ); } + register_setting(STAFFORDS_EMP_SETTINGS, STAFFORDS_EMP_SETTING_NAME); } public function staffords_add_setting_text_field($name, $label, $type) @@ -140,10 +203,10 @@ class staffords_employment_admin } add_settings_field( $name, - __($label, 'wordpress'), + $label, array($this, $callback), - 'job-setting-group', - STAFFORDS_EMP_SETTINGS, + 'staffordsjobs_settings', + 'staffordsjobs_setting_section', $name ); } @@ -169,6 +232,11 @@ class staffords_employment_admin echo __('Employment Form Email Notification', 'wordpress'); } + public function staffords_settings_two_section_callback() + { + echo __('Employment Form Thank You', 'wordpress'); + } + public function staffords_option_page_capability() { return STAFFORDS_EMP_NEW_CAPABILITY; diff --git a/controllers/front.php b/controllers/front.php index 4698bbc..68cbea8 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -111,16 +111,63 @@ class staffords_employment_front return $form; } + public function get_job_application_properties() + { + if (!$this->appId) { + return false; + } + + $sql = " + SELECT * + FROM " . $this->wpdb->prefix . STAFFORDS_EMP_FORM_TABLE . " + WHERE application = $this->appId + AND form_part = 1"; + $form = $this->wpdb->get_row($sql, ARRAY_A); + $formsData = unserialize($form['form_data']); + //echo '
data from form part table:  ' . print_r($formsData, true) . '
'; + $options = array(); + foreach ( $formsData as $row ) { + foreach ( $row as $elem ) { + if ( $elem['name'] == 'location_preference' ) { + foreach ( $elem['opts'] as $opt ) { + if ( $opt['checked'] ) { + $options[] = str_replace( 'location_preference_', '', $opt['name'] ); + } + } + } + } + } + return $options; + } + 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}>"; + $properies_applied_for = $this->get_job_application_properties(); + $plugin_options = get_option(STAFFORDS_EMP_SETTING_NAME); + if ($jobId = filter_var($_REQUEST['job'], FILTER_VALIDATE_INT)) { + $jobData = get_post($jobId); + $this->jobTitle = $jobTitle = $jobData->post_title; + } + // get the notification emails for this plugin + $fromName = $plugin_options['from_name']; + $from = $plugin_options['from_email']; + $to = $plugin_options['notification_email']; + $name = $plugin_name['replyto_name']; + $email = $plugin_name['replyto_email']; + $message = $plugin_options['notification_message']; + $message .= admin_url() . "edit.php?post_type=staffords_jobs&page=applications\n\n"; + $headers = array(); + $headers[] = "From: {$fromName} <{$from}>"; + $headers[] = "Reply-To: {$name} <{$email}>"; + foreach ( $properies_applied_for as $cc_email ) { + $headers[] = "Cc: " . $plugin_options[$cc_email . '_notification_name'] . " <" . $plugin_options[$cc_email . '_notification_email']. ">"; + } + // get the property for this application + + $depTax = wp_get_post_terms( $job->ID, STAFFORDS_EMP_TAX_DEPARTMENTS, 'name' ); + foreach ($depTax as $depTerm) { + $deps[] = $depTerm->name; + } wp_mail( $to, 'New Online Application Submission', diff --git a/glm-employment.php b/glm-employment.php index 66d5d1c..93e994f 100644 --- a/glm-employment.php +++ b/glm-employment.php @@ -14,6 +14,7 @@ defined('ABSPATH') or die(); */ define('STAFFORDS_EMP_PLUGIN_PATH_FILE', __FILE__); define('STAFFORDS_EMP_VERSION', '0.2.1'); +define('STAFFORDS_EMP_SETTING_NAME', 'staffordsjobs_settings'); define('STAFFORDS_EMP_SETTINGS', 'staffordsjobs_settings'); define('STAFFORDS_EMP_NEW_CAPABILITY', 'staffordsjobs_edit_jobs'); define('STAFFORDS_EMP_BUILT_IN_CAPABILITY', 'edit_posts'); diff --git a/views/optionsPage.php b/views/optionsPage.php index 1ad3c8e..0c8005e 100644 --- a/views/optionsPage.php +++ b/views/optionsPage.php @@ -1,9 +1,14 @@ +

Employment Plugin Settings

-- 2.17.1