-
Notifications
You must be signed in to change notification settings - Fork 2
/
wp-job-manager-formidable-apply.php
201 lines (169 loc) · 5.33 KB
/
wp-job-manager-formidable-apply.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* Plugin Name: WP Job Manager - Apply With Formidable Forms
* Plugin URI: https://github.com/Astoundify/wp-job-manager-gravityforms-apply/
* Description: Apply to jobs that have added an email address via Formidable Forms
* Author: Astoundify
* Author URI: http://astoundify.com
* Version: 1.0
* Text Domain: job_manager_formidable_apply
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
class Astoundify_Job_Manager_Apply_Formidable {
/**
* @var $instance
*/
private static $instance;
/**
* @var $jobs_form_id
*/
private $jobs_form_id;
/**
* @var $resumes_form_id
*/
private $resumes_form_id;
/**
* Make sure only one instance is only running.
*/
public static function get_instance() {
if ( ! class_exists( 'FrmAppHelper' ) ) {
return;
}
if ( ! isset ( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Start things up.
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*/
public function __construct() {
$this->jobs_form_id = get_option( 'job_manager_job_apply' );
$this->resumes_form_id = get_option( 'job_manager_resume_apply' );
$this->setup_actions();
$this->setup_globals();
$this->load_textdomain();
}
/**
* Set some smart defaults to class variables. Allow some of them to be
* filtered to allow for early overriding.
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*
* @return void
*/
private function setup_globals() {
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
$this->plugin_dir = plugin_dir_path( $this->file );
$this->plugin_url = plugin_dir_url ( $this->file );
$this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' );
$this->domain = 'job_manager_formidable_apply';
}
/**
* Loads the plugin language files
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*/
public function load_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
$mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
$mofile_local = $this->lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
if ( file_exists( $mofile_global ) ) {
return load_textdomain( $this->domain, $mofile_global );
} elseif ( file_exists( $mofile_local ) ) {
return load_textdomain( $this->domain, $mofile_local );
}
return false;
}
/**
* Setup the default hooks and actions
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*
* @return void
*/
private function setup_actions() {
add_filter( 'job_manager_settings', array( $this, 'job_manager_settings' ) );
add_filter( 'frm_email_value' , array( $this, 'application_email' ) );
add_filter( 'frm_to_email' , array( $this, 'notification_email' ), 10, 4 );
}
private static function get_forms() {
$forms = array( 0 => __( 'Please select a form', 'job_manager_formidable_apply' ) );
$where = apply_filters( 'frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", '' );
$frm_form = new FrmForm();
$_forms = $frm_form->getAll( $where, ' ORDER BY name' );
if ( ! empty( $_forms ) ) {
foreach ( $_forms as $_form ) {
$forms[ $_form->id ] = $_form->title;
}
}
return $forms;
}
/**
* Add a setting in the admin panel to enter the ID of the Gravity Form to use.
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*
* @param array $settings
* @return array $settings
*/
public function job_manager_settings( $settings ) {
$settings[ 'job_listings' ][1][] = array(
'name' => 'job_manager_job_apply',
'std' => null,
'label' => __( 'Jobs Formidable Form', 'job_manager_formidable_apply' ),
'desc' => __( 'The ID of the Formidable Form you created for contacting employers.', 'job_manager_formidable_apply' ),
'type' => 'select',
'options' => self::get_forms()
);
if ( class_exists( 'WP_Resume_Manager' ) ) {
$settings[ 'job_listings' ][1][] = array(
'name' => 'job_manager_resume_apply',
'std' => null,
'label' => __( 'Resumes Formidable Form', 'job_manager_formidable_apply' ),
'desc' => __( 'The ID of the Formidable Form you created for contacting employees.', 'job_manager_formidable_apply' ),
'type' => 'select',
'options' => self::get_forms()
);
}
return $settings;
}
/**
* Dynamically populate the application email field.
*
* @since WP Job Manager - Apply with Formidable Forms 1.2.0
*
* @return string The email to notify.
*/
public function application_email() {
global $post;
if ( $post->_application ) {
return $post->_application;
} else {
return $post->_candidate_email;
}
}
/**
* Set the notification email when sending an email.
*
* @since WP Job Manager - Apply with Formidable Forms 1.0
*
* @return string The email to notify.
*/
public function notification_email( $recipients, $values, $form_id, $args ) {
if ( $form_id == $this->jobs_form_id || $form_id == $this->resumes_form_id ) {
foreach ( $values as $value ) {
if ( is_email( $value ) ) {
$recipients[] = $value;
}
}
}
return $recipients;
}
}
add_action( 'init', array( 'Astoundify_Job_Manager_Apply_Formidable', 'get_instance' ) );