class-simple-job-board-settings-email-notifications.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly
  2. /**
  3. * Simple_Job_Board_Settings_Email_Notifications class
  4. *
  5. * This file used to define the settings for the email notifications. User can
  6. * enable/disable emails receiving for Admin/HR/Applicant.
  7. *
  8. * @link https://wordpress.org/plugins/simple-job-board
  9. * @since 2.2.3
  10. * @since 2.3.2 Added Filter for HR Email Address
  11. * @since 2.4.0 Revised Inputs & Outputs Sanitization & Escaping
  12. *
  13. * @package Simple_Job_Board
  14. * @subpackage Simple_Job_Board/admin/settings
  15. * @author PressTigers <support@presstigers.com>
  16. */
  17. class Simple_Job_Board_Settings_Email_Notifications {
  18. /**
  19. * Initialize the class and set its properties.
  20. *
  21. * @since 2.2.3
  22. */
  23. public function __construct() {
  24. // Filter -> Add Settings Email Notifications Tab
  25. add_filter('sjb_settings_tab_menus', array($this, 'sjb_add_settings_tab'), 70);
  26. // Action -> Add Settings Email Notifications Section
  27. add_action('sjb_settings_tab_section', array($this, 'sjb_add_settings_section'), 70);
  28. // Action -> Save Settings Email Notifications Section
  29. add_action('sjb_save_setting_sections', array($this, 'sjb_save_settings_section'));
  30. }
  31. /**
  32. * Add Settings Email Notifications Tab.
  33. *
  34. * @since 2.2.3
  35. *
  36. * @param array $tabs Settings Tab
  37. * @return array $tabs Merge array of Settings Tab with "Email Notification" Tab.
  38. */
  39. public function sjb_add_settings_tab($tabs) {
  40. $tabs['email_notifications'] = esc_html__( 'Email Notifications', 'simple-job-board' );
  41. return $tabs;
  42. }
  43. /**
  44. * Add Settings Email Notifications Section.
  45. *
  46. * @since 2.2.3
  47. */
  48. public function sjb_add_settings_section() {
  49. ?>
  50. <!-- Notification -->
  51. <div id="settings-email_notifications" class="sjb-admin-settings" style="display: none;">
  52. <?php
  53. /**
  54. * Action -> Add new section before notifications settings .
  55. *
  56. * @since 2.2.0
  57. */
  58. do_action('sjb_notifications_settings_before');
  59. $hr_email = ( FALSE !== get_option('settings_hr_email') ) ? get_option('settings_hr_email') : '';
  60. $admin_email = ( FALSE !== get_option( 'settings_admin_email' ) ) ? get_option( 'settings_admin_email' ) : get_option( 'admin_email' );
  61. ?>
  62. <h4 class="first"><?php _e('Enable Email Notification', 'simple-job-board'); ?></h4>
  63. <form method="post" id="email_notification_form">
  64. <div class="sjb-section">
  65. <div class="sjb-content-email-notify">
  66. <?php
  67. /**
  68. * Action -> Add new fields at the start of notification section.
  69. *
  70. * @since 2.2.0
  71. */
  72. do_action('sjb_email_notifications_settings_start');
  73. ?>
  74. <div class="sjb-form-group">
  75. <label><?php echo esc_html__('HR Email:', 'simple-job-board'); ?><input type="hidden" name="empty_form_check" value="empty_form_submitted"></label>
  76. <?php $HR = '<input type="email" name="hr_email" value="' . esc_attr( $hr_email ) . '" size="30">';
  77. echo apply_filters( 'sjb_settings_hr_email', $HR );
  78. ?>
  79. </div>
  80. <div class="sjb-form-group right-align">
  81. <input type="checkbox" name="email_notification[]" value="hr_email" <?php if ('yes' === get_option('job_board_hr_notification')) echo 'checked="checked"'; ?>/>
  82. <label><?php echo esc_html__('Enable the HR Email Notification', 'simple-job-board'); ?></label>
  83. </div>
  84. <div class="sjb-form-group">
  85. <label><?php echo esc_html__('Admin Email:', 'simple-job-board'); ?></label>
  86. <?php
  87. $ADMIN = '<input type="email" name="admin_email" value="' . esc_attr( $admin_email ) . '" size="30">';
  88. echo apply_filters('sjb_settings_admin_email', $ADMIN);
  89. ?>
  90. </div>
  91. <div class="sjb-form-group right-align">
  92. <input type="checkbox" name="email_notification[]" value="admin_email" <?php if ('yes' === get_option('job_board_admin_notification')) echo 'checked="checked"'; ?> />
  93. <label><?php echo esc_html__('Enable the Admin Email Notification', 'simple-job-board'); ?></label>
  94. </div>
  95. <div class="sjb-form-group right-align">
  96. <input type="checkbox" name="email_notification[]" value="applicant_email" <?php if ('yes' === get_option('job_board_applicant_notification')) echo 'checked="checked"'; ?>/>
  97. <label><?php echo esc_html__('Enable the Applicant Email Notification', 'simple-job-board'); ?></label>
  98. </div>
  99. <?php
  100. /**
  101. * Action -> Add new fields at the end of notification section.
  102. *
  103. * @since 2.2.0
  104. */
  105. do_action('sjb_notifications_settings_end');
  106. ?>
  107. </div>
  108. </div>
  109. <?php
  110. /**
  111. * Action -> Add new section after notifications settings .
  112. *
  113. * @since 2.2.0
  114. */
  115. do_action('sjb_notifications_settings_after');
  116. ?>
  117. <input type="hidden" value="1" name="admin_notices" />
  118. <input type="submit" name="job_email_notification" id="job_email_notification" class="button button-primary" value="<?php echo esc_html__('Save Changes', 'simple-job-board'); ?>" />
  119. </form>
  120. </div>
  121. <?php
  122. }
  123. /**
  124. * Save Settings Email Notification Section.
  125. *
  126. * This function is used to save the email notifications settings. User can
  127. * enable/disable the notifications for Admin/HR/Applicant.
  128. *
  129. * @since 2.2.3
  130. */
  131. public function sjb_save_settings_section() {
  132. $notifications_status = filter_input( INPUT_POST, 'email_notification', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
  133. $empty_form_check = filter_input( INPUT_POST, 'empty_form_check' );
  134. if ( ( isset( $notifications_status ) ) || NULL != $empty_form_check ) {
  135. // Empty checkboxes status
  136. $hr_email_status = $admin_email_status = $applicant_email_status = 'no';
  137. // Save Notifications Settings
  138. if ( !empty( $notifications_status ) ) {
  139. foreach ( $notifications_status as $notification ) {
  140. if ( 'hr_email' === $notification ) {
  141. update_option('job_board_hr_notification', 'yes');
  142. $hr_email_status = 'yes';
  143. } elseif ( 'admin_email' === $notification ) {
  144. update_option('job_board_admin_notification', 'yes');
  145. $admin_email_status = 'yes';
  146. } elseif ( 'applicant_email' === $notification ) {
  147. update_option('job_board_applicant_notification', 'yes');
  148. $applicant_email_status = 'yes';
  149. }
  150. }
  151. }
  152. // HR Email
  153. $hr_email = filter_input( INPUT_POST, 'hr_email' );
  154. // Admin Email
  155. $admin_email = filter_input(INPUT_POST, 'admin_email');
  156. if ( !empty( $hr_email ) ) {
  157. ( false !== get_option('settings_hr_email') ) ? update_option('settings_hr_email', sanitize_email( $hr_email ) ) : add_option('settings_hr_email', sanitize_email( $hr_email ) );
  158. } elseif(isset($hr_email) && '' === $hr_email) {
  159. update_option('settings_hr_email', '' );
  160. }
  161. if (!empty($admin_email)) {
  162. ( false !== get_option('settings_admin_email') ) ? update_option('settings_admin_email', sanitize_email($admin_email)) : add_option('settings_admin_email', sanitize_email($admin_email));
  163. } elseif ( isset($admin_email) && '' === $admin_email) {
  164. update_option('settings_admin_email', '' );
  165. }
  166. // Disable HR Notification
  167. if ( 'no' === $hr_email_status ) {
  168. update_option('job_board_hr_notification', 'no');
  169. }
  170. // Disable Admin Notification
  171. if ( 'no' === $admin_email_status ) {
  172. update_option('job_board_admin_notification', 'no');
  173. }
  174. // Disable Applicant Notification
  175. if ( 'no' === $applicant_email_status ) {
  176. update_option('job_board_applicant_notification', 'no');
  177. }
  178. }
  179. }
  180. }