$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') );
}
/**
'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;
}
/**
*/
public function show_job_settings()
{
- echo '<p>Job Settings</p>';
+ if (current_user_can(STAFFORDS_EMP_NEW_CAPABILITY)) {
+ include $this->pluginDirName . 'views/optionsPage.php';
+ } else {
+ include $this->pluginDirName . 'views/deniedAccess.php';
+ }
}
/**
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 <server@gaslightmedia.com>\r\nReply-To: {$name} <{$email}>";
+ wp_mail(
+ $to,
+ 'New Online Application Submission',
+ $message,
+ $headers
+ );
+ }
+
/**
* Show the application form
*/
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;
*/
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');
$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
*/