Contact Listing for WP Job Manager - Version 1.0.0

Version Description

Download this release

Release Info

Developer adampickering
Plugin Icon wp plugin Contact Listing for WP Job Manager
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

includes/class-wp-job-manager-contact-listing-form.php ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Base form class. Grab the form values, add settings, and
4
+ * output the correct form.
5
+ *
6
+ * @since WP Job Manager - Contact Listing 1.0.0
7
+ *
8
+ * @return void
9
+ */
10
+ abstract class Astoundify_Job_Manager_Contact_Listing_Form extends Astoundify_Job_Manager_Contact_Listing {
11
+
12
+ /**
13
+ * @var $jobs_form_id
14
+ */
15
+ public $forms;
16
+
17
+ /**
18
+ * Form-specific methods
19
+ */
20
+ abstract protected function setup_actions();
21
+ abstract protected function get_forms();
22
+ abstract protected function output_form( $form );
23
+ abstract protected function notification_email($arg1, $arg2, $arg3);
24
+
25
+ /**
26
+ * Set the form values, remove the default application template
27
+ * and attach our own. Call and of the children's special actions.
28
+ *
29
+ * @since WP Job Manager - Contact Listing 1.0.0
30
+ *
31
+ * @return void
32
+ */
33
+ public function __construct() {
34
+ global $job_manager;
35
+
36
+ $this->forms = apply_filters( 'job_manager_contact_listing_forms', array(
37
+ 'job_listing' => array(
38
+ 'contact' => get_option( 'job_manager_form_contact', false )
39
+ ),
40
+ 'resume' => array(
41
+ 'contact' => get_option( 'resume_manager_form_contact', false )
42
+ )
43
+ ) );
44
+
45
+ add_filter( 'job_manager_settings', array( $this, 'job_manager_settings' ) );
46
+ add_filter( 'resume_manager_settings', array( $this, 'resume_manager_settings' ) );
47
+
48
+ if ( ! parent::$active_plugin ) {
49
+ return;
50
+ }
51
+
52
+ $this->setup_actions();
53
+
54
+ // Output the shortcode
55
+ remove_action( 'job_manager_application_details_email', array( $job_manager->post_types, 'application_details_email' ) );
56
+ add_action( 'job_manager_application_details_email', array( $this, 'job_manager_application_details_email' ) );
57
+
58
+ if ( class_exists( 'WP_Resume_Manager' ) ) {
59
+ global $resume_manager;
60
+
61
+ remove_action( 'resume_manager_contact_details', array( $resume_manager->post_types, 'contact_details_email' ) );
62
+ add_action( 'resume_manager_contact_details', array( $this, 'job_manager_application_details_email' ) );
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Add settings fields to select the appropriate form for each listing type.
68
+ *
69
+ * @since WP Job Manager - Contact Listing 1.0.0
70
+ *
71
+ * @return void
72
+ */
73
+ public function job_manager_settings($settings) {
74
+ $args = array(
75
+ 'post_type' => 'job_listing',
76
+ 'key' => 'job_listings',
77
+ 'option' => 'job_manager'
78
+ );
79
+
80
+ $settings = $this->add_settings( $args, $settings );
81
+
82
+ return $settings;
83
+ }
84
+
85
+ /**
86
+ * Add settings fields to select the appropriate form for each listing type.
87
+ *
88
+ * @since WP Job Manager - Contact Listing 1.0.0
89
+ *
90
+ * @return void
91
+ */
92
+ public function resume_manager_settings($settings) {
93
+ $args = array(
94
+ 'post_type' => 'resume',
95
+ 'key' => 'resume_listings',
96
+ 'option' => 'resume_manager'
97
+ );
98
+
99
+ $settings = $this->add_settings( $args, $settings );
100
+
101
+ return $settings;
102
+ }
103
+
104
+ private function add_settings( $args, $settings ) {
105
+ $post_type = $args[ 'post_type' ];
106
+ $forms = $this->forms[ $post_type ];
107
+
108
+ $p_type_obj = get_post_type_object( $post_type );
109
+
110
+ foreach ( $forms as $key => $value ) {
111
+ $settings[ $args[ 'key' ] ][1][] = array(
112
+ 'name' => sprintf( '%s_form_%s', $args[ 'option' ], $key ),
113
+ 'std' => null,
114
+ 'label' => sprintf( __( '%s a %s Form', 'wp-job-manager-contact-listing' ), ucfirst( $key ), $p_type_obj->labels->singular_name ),
115
+ 'desc' => '',
116
+ 'type' => 'select',
117
+ 'options' => $this->get_forms()
118
+ );
119
+ }
120
+
121
+ return $settings;
122
+ }
123
+
124
+ /**
125
+ * Output the necessary form shortocde.
126
+ *
127
+ * @since WP Job Manager - Contact Listing 1.0.0
128
+ *
129
+ * @return void
130
+ */
131
+ public function job_manager_application_details_email( $apply ) {
132
+ $plugin = parent::$active_plugin;
133
+ $post = get_post();
134
+
135
+ if ( ! is_a( $post, 'WP_Post' ) ) {
136
+ return;
137
+ }
138
+
139
+ $form = isset( $this->forms[ $post->post_type ][ 'contact' ] ) ? $this->forms[ $post->post_type ][ 'contact' ] : false;
140
+
141
+ if ( ! $form ) {
142
+ return;
143
+ }
144
+
145
+ do_action( 'job_manager_contact_listing_form_' . $plugin, $form );
146
+ }
147
+
148
+ }
includes/forms/cf7.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Contact Form 7 support.
4
+ *
5
+ * @since WP Job Manager - Contact Listing 1.0.0
6
+ *
7
+ * @return void
8
+ */
9
+ class Astoundify_Job_Manager_Contact_Listing_Form_CF7 extends Astoundify_Job_Manager_Contact_Listing_Form {
10
+
11
+ /**
12
+ * Load the base form class.
13
+ *
14
+ * @since WP Job Manager - Contact Listing 1.0.0
15
+ *
16
+ * @return void
17
+ */
18
+ public function __construct() {
19
+ parent::__construct();
20
+ }
21
+
22
+ /**
23
+ * Hook into processing and attach our own things.
24
+ *
25
+ * @since WP Job Manager - Contact Listing 1.0.0
26
+ *
27
+ * @return void
28
+ */
29
+ public function setup_actions() {
30
+ add_filter( 'wpcf7_mail_components', array( $this, 'notification_email' ), 10, 3 );
31
+ add_action( 'job_manager_contact_listing_form_cf7', array( $this, 'output_form' ) );
32
+ }
33
+
34
+ /**
35
+ * Output the shortcode.
36
+ *
37
+ * @since WP Job Manager - Contact Listing 1.0.0
38
+ *
39
+ * @return void
40
+ */
41
+ public function output_form( $form = 0 ) {
42
+ $args = apply_filters( 'job_manager_contact_listing_cf7_apply_form_args', '' );
43
+
44
+ echo do_shortcode( sprintf( '[contact-form-7 id="%s" %s]', $form, $args ) );
45
+ }
46
+
47
+ /**
48
+ * Set the notification email when sending an email.
49
+ *
50
+ * @since WP Job Manager - Contact Listing 1.0.0
51
+ *
52
+ * @return string The email to notify.
53
+ */
54
+ public function notification_email( $components, $cf7, $three ) {
55
+ $unit = $cf7->posted_data[ '_wpcf7_unit_tag' ];
56
+
57
+ if ( ! preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $unit, $matches ) )
58
+ return $components;
59
+
60
+ $post_id = (int) $matches[2];
61
+ $object = get_post( $post_id );
62
+
63
+ if ( ! array_search( $cf7->id, $this->forms[ $object->post_type ] ) ) {
64
+ return $components;
65
+ }
66
+
67
+ $recipient = $object->_application ? $object->_application : $object->_candidate_email;
68
+
69
+ $components[ 'recipient' ] = $recipient;
70
+
71
+ return $components;
72
+ }
73
+
74
+ /**
75
+ * Get all forms and return in a simple array for output.
76
+ *
77
+ * @since WP Job Manager - Contact Listing 1.0.0
78
+ *
79
+ * @return void
80
+ */
81
+ public function get_forms() {
82
+ $forms = array( 0 => __( 'Please select a form', 'wp-job-manager-contact-listing' ) );
83
+
84
+ $_forms = get_posts(
85
+ array(
86
+ 'numberposts' => -1,
87
+ 'post_type' => 'wpcf7_contact_form',
88
+ )
89
+ );
90
+
91
+ if ( ! empty( $_forms ) ) {
92
+
93
+ foreach ( $_forms as $_form ) {
94
+ $forms[ $_form->ID ] = $_form->post_title;
95
+ }
96
+ }
97
+
98
+ return $forms;
99
+ }
100
+
101
+ }
includes/forms/gravityforms.php ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Gravity Forms support.
4
+ *
5
+ * @since WP Job Manager - Contact Listing 1.0.0
6
+ *
7
+ * @return void
8
+ */
9
+ class Astoundify_Job_Manager_Contact_Listing_Form_GravityForms extends Astoundify_Job_Manager_Contact_Listing_Form {
10
+
11
+ /**
12
+ * Load the base form class.
13
+ *
14
+ * @since WP Job Manager - Contact Listing 1.0.0
15
+ *
16
+ * @return void
17
+ */
18
+ public function __construct() {
19
+ parent::__construct();
20
+ }
21
+
22
+ public function setup_actions() {
23
+ add_action( 'job_manager_contact_listing_form_gravityforms', array( $this, 'output_form' ) );
24
+ add_filter( 'gform_notification', array( $this, 'notification_email' ), 10, 3 );
25
+ }
26
+
27
+ /**
28
+ * Output the shortcode.
29
+ *
30
+ * @since WP Job Manager - Contact Listing 1.0.0
31
+ *
32
+ * @return void
33
+ */
34
+ public function output_form( $form = 0 ) {
35
+ $args = apply_filters( 'job_manager_contact_listing_gravityforms_apply_form_args', 'title="false" description="false" ajax="true"' );
36
+
37
+ echo do_shortcode( sprintf( '[gravityform id="%s" %s]', $form, $args ) );
38
+ }
39
+
40
+ /**
41
+ * Set the notification email when sending an email.
42
+ *
43
+ * @since WP Job Manager - Contact Listing 1.0.0
44
+ *
45
+ * @return string The email to notify.
46
+ */
47
+ public function notification_email( $notification, $form, $entry ) {
48
+ if ( 'no-reply@listingowner.com' != $notification[ 'to' ] ) {
49
+ return $notification;
50
+ }
51
+
52
+ $notification[ 'toType' ] = 'email';
53
+
54
+ $listing = false;
55
+ $fields = $form[ 'fields' ];
56
+
57
+ foreach ( $fields as $check ) {
58
+ if ( $check[ 'inputName' ] == 'Listing ID' ) {
59
+ $listing = $check[ 'id' ];
60
+ }
61
+ }
62
+
63
+ $object = get_post( $listing );
64
+
65
+ if ( ! array_search( $form[ 'id' ], $this->forms[ $object->post_type ] ) ) {
66
+ return;
67
+ }
68
+
69
+ $to = $object->_application ? $object->_application : $object->_candidate_email;
70
+
71
+ $notification[ 'to' ] = $to;
72
+
73
+ return $notification;
74
+ }
75
+
76
+ /**
77
+ * Get all forms and return in a simple array for output.
78
+ *
79
+ * @since WP Job Manager - Contact Listing 1.0.0
80
+ *
81
+ * @return void
82
+ */
83
+ public function get_forms() {
84
+ $forms = array( 0 => __( 'Please select a form', 'wp-job-manager-contact-listing' ) );
85
+
86
+ $_forms = RGFormsModel::get_forms( null, 'title' );
87
+
88
+ if ( ! empty( $_forms ) ) {
89
+ foreach ( $_forms as $_form ) {
90
+ $forms[ $_form->id ] = $_form->title;
91
+ }
92
+ }
93
+
94
+ return $forms;
95
+ }
96
+
97
+ }
includes/forms/ninjaforms.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ninja Forms support.
4
+ *
5
+ * @since WP Job Manager - Contact Listing 1.0.0
6
+ *
7
+ * @return void
8
+ */
9
+ class Astoundify_Job_Manager_Contact_Listing_Form_NinjaForms extends Astoundify_Job_Manager_Contact_Listing_Form {
10
+
11
+ /**
12
+ * Load the base form class.
13
+ *
14
+ * @since WP Job Manager - Contact Listing 1.0.0
15
+ *
16
+ * @return void
17
+ */
18
+ public function __construct() {
19
+ parent::__construct();
20
+ }
21
+
22
+ /**
23
+ * Hook into processing and attach our own things.
24
+ *
25
+ * @since WP Job Manager - Contact Listing 1.0.0
26
+ *
27
+ * @return void
28
+ */
29
+ public function setup_actions() {
30
+ add_action( 'job_manager_contact_listing_form_ninjaforms', array( $this, 'output_form' ) );
31
+ add_action( 'ninja_forms_email_admin', array( $this, 'notification_email' ) );
32
+ }
33
+
34
+ /**
35
+ * Output the shortcode.
36
+ *
37
+ * @since WP Job Manager - Contact Listing 1.0.0
38
+ *
39
+ * @return void
40
+ */
41
+ public function output_form( $form = 0 ) {
42
+ $args = apply_filters( 'job_manager_contact_listing_ninjaforms_apply_form_args', '' );
43
+
44
+ echo do_shortcode( sprintf( '[ninja_forms_display_form id="%s" %s]', $form, $args ) );
45
+ }
46
+
47
+ /**
48
+ * Set the notification email when sending an email.
49
+ *
50
+ * @since WP Job Manager - Contact Listing 1.0.0
51
+ *
52
+ * @return string The email to notify.
53
+ */
54
+ public function notification_email($one, $two, $three) {
55
+ global $ninja_forms_processing;
56
+
57
+ $form_id = $ninja_forms_processing->get_form_ID();
58
+
59
+ $object = $field_id = null;
60
+ $fields = $ninja_forms_processing;
61
+
62
+ foreach ( $fields->data[ 'field_data' ] as $field ) {
63
+ if ( 'Listing ID' == $field[ 'data' ][ 'label' ] ) {
64
+ $field_id = $field[ 'id' ];
65
+
66
+ break;
67
+ }
68
+ }
69
+
70
+ $object = get_post( $ninja_forms_processing->get_field_value( $field_id ) );
71
+
72
+ if ( ! array_search( $form_id, $this->forms[ $object->post_type ] ) ) {
73
+ return;
74
+ }
75
+
76
+ $this->_proper_ninja_email = $object->_application ? $object->_application : $object->_candidate_email;
77
+
78
+ add_filter( 'wp_mail', array( $this, 'proper_email' ) );
79
+ }
80
+
81
+ /**
82
+ * @missing
83
+ *
84
+ * @since WP Job Manager - Contact Listing 1.0.0
85
+ *
86
+ * @return $mail
87
+ */
88
+ public function proper_email( $mail ) {
89
+ if ( filter_var( $this->_proper_ninja_email, FILTER_VALIDATE_EMAIL ) ) {
90
+ $mail[ 'to' ] = $this->_proper_ninja_email;
91
+ }
92
+
93
+ remove_filter( 'wp_mail', array( $this, 'proper_email' ) );
94
+
95
+ return $mail;
96
+ }
97
+
98
+ /**
99
+ * Get all forms and return in a simple array for output.
100
+ *
101
+ * @since WP Job Manager - Contact Listing 1.0.0
102
+ *
103
+ * @return void
104
+ */
105
+ public function get_forms() {
106
+ $forms = array( 0 => __( 'Please select a form', 'wp-job-manager-contact-listing' ) );
107
+
108
+ $_forms = ninja_forms_get_all_forms();
109
+
110
+ if ( ! empty( $_forms ) ) {
111
+
112
+ foreach ( $_forms as $_form ) {
113
+ $forms[ $_form['id'] ] = $_form['data']['form_title'];
114
+ }
115
+ }
116
+
117
+ return $forms;
118
+ }
119
+
120
+ }
readme.txt ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === WP Job Manager - Contact Listing ===
2
+
3
+ Author URI: http://astoundify.com
4
+ Plugin URI: https://github.com/Astoundify/wp-job-manager-contact-listing/
5
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=contact@appthemer.com&item_name=Donation+for+Astoundify WP Job Manager Contact Listing
6
+ Contributors: spencerfinnell
7
+ Tags: job, job listing, job apply, gravity forms, wp job manager, gravity forms, gravityforms, ninja forms, ninjaforms, contact form 7, cf7
8
+ Requires at least: 3.5
9
+ Tested up to: 3.9.1
10
+ Stable Tag: 1.0.0
11
+ License: GPLv3
12
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
13
+
14
+ Allow sites using the WP Job Manager plugin to contact listings via their favorite form builder plugin.
15
+
16
+ == Description ==
17
+
18
+ Sites using the [WP Job Manager](http://wordpress.org/plugins/wp-job-manager/) plugin can use any of the supported plugins and allow visitors to contact the connected application email (or resume author) directly.
19
+
20
+ **Supported Form Plugins**
21
+
22
+ * Gravity Forms
23
+ * Ninja Forms
24
+ * Contact Form 7
25
+
26
+ = Where can I use this? =
27
+
28
+ Astoundify has released the first fully integrated WP Job Manager theme. Check out ["Jobify"](http://themeforest.net/item/jobify-job-board-wordpress-theme/5247604?ref=Astoundify)
29
+
30
+ The plugin can also be used on any theme but no extra styling (outside the CSS that comes with the form plugins) is used.
31
+
32
+ == Frequently Asked Questions ==
33
+
34
+ = What settings do I need for Gravity Forms? =
35
+
36
+ **Video Tutorial:** https://vimeo.com/85469722
37
+
38
+ You **must** create a *hidden* field with the following specific settings:
39
+
40
+ * **Label:** Application Email
41
+ * **Allow field to be dynamically populated:** `application_email`
42
+
43
+ [View an image of the settings](https://i.cloudup.com/XfRsp5B1VH.png)
44
+
45
+ The Job/Resume listing must also have an email address associated with it, not a URL to a website.
46
+
47
+ **Next**, create a new form notification with the "Send To" field set to "Email" and "dummy@dummy.com" as the value.
48
+
49
+ = What settings do I need for Ninja Forms? =
50
+
51
+ **Video Tutorial:** https://vimeo.com/89439524/
52
+
53
+ You **must** create a *hidden* field with the following specific settings:
54
+
55
+ * **Label:** `application_email`
56
+ * **Default Value:** `Post/Page ID`
57
+
58
+ [View an image of the settings](https://i.cloudup.com/pnfVzYBFiN.png)
59
+
60
+ The Job/Resume listing must also have an email address associated with it, not a URL to a website.
61
+
62
+ In "Administrator Email Settings" add a *dummy* email address as the first email to send a notification to. You can add real email addresses under this if you do need an actual admin confirmation.
63
+
64
+ = What settings do I need for Contact Form 7? =
65
+
66
+ No special settings needed.
67
+
68
+ = I am using Jobify and it's not working =
69
+
70
+ **Please make sure you have the latest version of Jobify from ThemeForest**
71
+
72
+ If you have purchased Jobify and still have questions, please post on our dedicated support forum: http://support.astoundify.com
73
+
74
+ == Installation ==
75
+
76
+ 1. Install and Activate
77
+ 2. Go to "Job Listings > Settings" and choose the forms you would like to use.
78
+ 3. Visit the FAQ for specifics on each form plugin.
79
+
80
+ == Changelog ==
81
+
82
+ = 1.0.0: May 31, 2013 =
83
+
84
+ * First official release!
wp-job-manager-contact-listing.php ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: WP Job Manager - Contact Listing
4
+ * Plugin URI: https://github.com/Astoundify/wp-job-manager-apply-with-forms/
5
+ * Description: Contact job listings or resume listings with your choice of Gravity Forms, Ninja Forms, or Contact Form 7
6
+ * Author: Astoundify
7
+ * Author URI: http://astoundify.com
8
+ * Version: 1.0.0
9
+ * Text Domain: wp-job-manager-contact-listing
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ class Astoundify_Job_Manager_Contact_Listing {
16
+
17
+ /**
18
+ * @var $instance
19
+ */
20
+ private static $instance;
21
+
22
+ /**
23
+ * @var $active_plugin;
24
+ */
25
+ public static $active_plugin;
26
+
27
+ /**
28
+ * Make sure only one instance is only running.
29
+ */
30
+ public static function instance() {
31
+ if ( ! isset ( self::$instance ) ) {
32
+ self::$instance = new self;
33
+ }
34
+
35
+ return self::$instance;
36
+ }
37
+
38
+ /**
39
+ * Start things up.
40
+ *
41
+ * @since WP Job Manager - Contact Listing 1.0.0
42
+ */
43
+ public function __construct() {
44
+ $this->setup_globals();
45
+ $this->load_textdomain();
46
+
47
+ $this->find_plugin();
48
+ }
49
+
50
+ /**
51
+ * Set some smart defaults to class variables. Allow some of them to be
52
+ * filtered to allow for early overriding.
53
+ *
54
+ * @since WP Job Manager - Contact Listing 1.0.0
55
+ *
56
+ * @return void
57
+ */
58
+ private function setup_globals() {
59
+ $this->file = __FILE__;
60
+
61
+ $this->basename = plugin_basename( $this->file );
62
+ $this->plugin_dir = plugin_dir_path( $this->file );
63
+ $this->plugin_url = plugin_dir_url ( $this->file );
64
+
65
+ $this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' );
66
+ $this->domain = 'wp-job-contact-listing';
67
+ }
68
+
69
+ /**
70
+ * Loads the plugin language files
71
+ *
72
+ * @since WP Job Manager - Contact Listing 1.0.0
73
+ */
74
+ public function load_textdomain() {
75
+ $locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
76
+ $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
77
+
78
+ $mofile_local = $this->lang_dir . $mofile;
79
+ $mofile_global = WP_LANG_DIR . '/' . $this->domain . '/' . $mofile;
80
+
81
+ if ( file_exists( $mofile_global ) ) {
82
+ return load_textdomain( $this->domain, $mofile_global );
83
+ } elseif ( file_exists( $mofile_local ) ) {
84
+ return load_textdomain( $this->domain, $mofile_local );
85
+ }
86
+
87
+ return false;
88
+ }
89
+
90
+ /**
91
+ * Find the plugin we are using to apply. It simply goes down the list
92
+ * in order so the first active plugin that meets requirements will
93
+ * be assumed the correct one.
94
+ *
95
+ * @since WP Job Manager - Contact Listing 1.0.0
96
+ *
97
+ * @return void
98
+ */
99
+ private function find_plugin() {
100
+ $supported = $this->supported_plugins();
101
+
102
+ foreach ( $supported as $key => $plugin ) {
103
+ if ( $plugin[ 'dependancy' ] ) {
104
+ self::$active_plugin = $key;
105
+
106
+ break;
107
+ }
108
+ }
109
+
110
+ $this->init_plugin();
111
+ }
112
+
113
+ /**
114
+ * Load the base form class and the necessary form class for the active plugin.
115
+ *
116
+ * @since WP Job Manager - Contact Listing 1.0.0
117
+ *
118
+ * @return void
119
+ */
120
+ private function init_plugin() {
121
+ if ( ! isset( self::$active_plugin ) ) {
122
+ return;
123
+ }
124
+
125
+ $plugin = $this->supported_plugins()[ self::$active_plugin ];
126
+
127
+ $plugin_file = sprintf( $this->plugin_dir . 'includes/forms/%s.php', self::$active_plugin );
128
+ $plugin_class = sprintf( 'Astoundify_Job_Manager_Contact_Listing_Form_%s', $plugin[ 'class' ] );
129
+
130
+ if ( ! file_exists( $plugin_file ) ) {
131
+ return false;
132
+ }
133
+
134
+ include_once( $this->plugin_dir . '/includes/class-wp-job-manager-contact-listing-form.php' );
135
+ include_once( $plugin_file );
136
+
137
+ if ( ! class_exists( $plugin_class ) ) {
138
+ return false;
139
+ }
140
+
141
+ new $plugin_class;
142
+ }
143
+
144
+ /**
145
+ * Retrieve a list of supported plugins.
146
+ *
147
+ * @since WP Job Manager - Contact Listing 1.0.0
148
+ *
149
+ * @return void
150
+ */
151
+ public function supported_plugins() {
152
+ $supported = array(
153
+ 'gravityforms' => array(
154
+ 'dependancy' => class_exists( 'GFForms' ),
155
+ 'class' => 'GravityForms'
156
+ ),
157
+ 'ninjaforms' => array(
158
+ 'dependancy' => defined( 'NINJA_FORMS_DIR' ),
159
+ 'class' => 'NinjaForms'
160
+ ),
161
+ 'cf7' => array(
162
+ 'dependancy' => defined( 'WPCF7_VERSION' ),
163
+ 'class' => 'CF7'
164
+ )
165
+ );
166
+
167
+ return apply_filters( 'job_manager_contact_listing_supported_plugins', $supported );
168
+ }
169
+
170
+ }
171
+ add_action( 'init', array( 'Astoundify_Job_Manager_Contact_Listing', 'instance' ) );