class-simple-job-board-admin-meta-boxes-init.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly
  2. /**
  3. * Simple_Job_Board_Meta_Boxes_Init Class
  4. *
  5. * @link https://wordpress.org/plugins/simple-job-board
  6. * @since 2.2.3
  7. * @since 2.4.0 Revised the Nonce Field Checks
  8. *
  9. * @package Simple_Job_Board
  10. * @subpackage Simple_Job_Board/admin
  11. * @author PressTigers <support@presstigers.com>
  12. */
  13. class Simple_Job_Board_Meta_Boxes_Init {
  14. /**
  15. * Initialize the class and set its properties.
  16. *
  17. * @since 2.2.3
  18. */
  19. public function __construct() {
  20. /**
  21. * The class responsible for defining job data meta box options under custom post type in the admin area.
  22. */
  23. require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/meta-boxes/class-simple-job-board-meta-box-job-data.php';
  24. /**
  25. * The class responsible for defining job features meta box options under custom post type in the admin area.
  26. */
  27. require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/meta-boxes/class-simple-job-board-meta-box-job-features.php';
  28. /**
  29. * The class responsible for defining job application meta box options under custom post type in the admin area.
  30. */
  31. require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/meta-boxes/class-simple-job-board-meta-box-job-application.php';
  32. /**
  33. * The class responsible for defining application status meta box options under applicant post type in the admin area.
  34. */
  35. require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/meta-boxes/class-simple-job-board-meta-box-application-status.php';
  36. // Action -> Load WP Media Uploader Scripts.
  37. add_action( 'admin_enqueue_scripts', array( $this, 'admin_script_loader' ) );
  38. // Action -> Post Type -> Jobpost -> Add Meta Boxes.
  39. add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
  40. // Action -> Post Type -> Jobpost -> Save Meta Boxes.
  41. add_action( 'save_post_jobpost', array( $this, 'save_meta_boxes' ), 10, 1 );
  42. // Action -> Post Type -> Jobpost Applicants -> Save Meta Boxes.
  43. add_action( 'save_post_jobpost_applicants', array( $this, 'save_applicants_meta_boxes' ), 10, 1 );
  44. // Action -> Post Type -> Jobpost -> Save Job Features Meta Box.
  45. add_action( 'sjb_save_jobpost_meta', array( 'Simple_Job_Board_Meta_Box_Job_Features', 'sjb_save_jobpost_meta' ), 10 );
  46. // Action -> Post Type -> Jobpost -> Save Job Application Meta Box.
  47. add_action( 'sjb_save_jobpost_meta', array( 'Simple_Job_Board_Meta_Box_Job_Application', 'sjb_save_jobpost_meta' ), 20 );
  48. // Action -> Post Type -> Jobpost -> Save Job Data Meta Box.
  49. add_action( 'sjb_save_jobpost_meta', array( 'Simple_Job_Board_Meta_Box_Job_Data', 'sjb_save_jobpost_meta' ), 30 );
  50. // Action -> Post Type -> Jobpost Applicants -> Save Application Meta Box.
  51. add_action( 'sjb_save_jobpost_applicants_meta', array( 'Simple_Job_Board_Meta_Box_Application_Status', 'sjb_save_jobpost_applicants_meta' ), 10 );
  52. }
  53. /**
  54. * Load backend scripts
  55. *
  56. * @since 2.1.0
  57. */
  58. function admin_script_loader() {
  59. global $pagenow;
  60. if (is_admin() && ( in_array($pagenow, array('post-new.php', 'post.php'))) ) {
  61. wp_enqueue_script('media-upload');
  62. wp_enqueue_script('thickbox');
  63. wp_enqueue_style('thickbox');
  64. }
  65. }
  66. /**
  67. * Add jobpost meta boxes.
  68. *
  69. * @since 2.1.0
  70. */
  71. public function add_meta_boxes() {
  72. global $wp_post_types;
  73. add_meta_box('jobpost_metas', sprintf(esc_html__('%s Features', 'simple-job-board'), $wp_post_types['jobpost']->labels->singular_name), array('Simple_Job_Board_Meta_Box_Job_Features', 'sjb_meta_box_output'), 'jobpost', 'normal', 'high');
  74. add_meta_box('jobpost_application_fields', esc_html__('Application Form Fields', 'simple-job-board'), array('Simple_Job_Board_Meta_Box_Job_Application', 'sjb_meta_box_output'), 'jobpost', 'normal', 'high');
  75. add_meta_box('simple-job-board-post_options', esc_html__('Job Data', 'simple-job-board'), array('Simple_Job_Board_Meta_box_Job_Data', 'sjb_meta_box_output'), 'jobpost', 'normal');
  76. add_meta_box('sjb-application-status', esc_html__('Application Status', 'simple-job-board'), array('Simple_Job_Board_Meta_Box_Application_Status', 'sjb_meta_box_output'), 'jobpost_applicants', 'side');
  77. }
  78. /**
  79. * Save Meta Boxes.
  80. *
  81. * @since 2.1.0
  82. */
  83. public function save_meta_boxes( $post_id ) {
  84. /**
  85. * We need to verify this came from our screen and with proper authorization,
  86. * because the save_post action can be triggered at other times.
  87. */
  88. // Check if nonce is set.
  89. if ( NULL == filter_input( INPUT_POST, 'jobpost_meta_box_nonce' ) ) {
  90. return;
  91. }
  92. // Verify that the nonce is valid.
  93. check_admin_referer( 'sjb_jobpost_meta_box', 'jobpost_meta_box_nonce' );
  94. // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  95. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  96. return;
  97. }
  98. // Check the user's permissions.
  99. if ( NULL != filter_input( INPUT_POST, 'post_type' ) && 'page' == filter_input( INPUT_POST, 'post_type') ) {
  100. if (!current_user_can('edit_page', $post_id)) {
  101. return;
  102. }
  103. } else {
  104. if (!current_user_can('edit_post', $post_id)) {
  105. return;
  106. }
  107. }
  108. /**
  109. * @hooked sjb_save_jobpost_meta - 10
  110. * @hooked sjb_save_jobpost_meta - 20
  111. * @hooked sjb_save_jobpost_meta - 30
  112. *
  113. * Save Jobpost Meta Box:
  114. *
  115. * - Save job features meta box.
  116. * - Save job application meta box.
  117. * - Save job data meta box.
  118. *
  119. * @since 2.2.3
  120. *
  121. * @param int $post_id Post Id
  122. */
  123. do_action( 'sjb_save_jobpost_meta', $post_id );
  124. }
  125. /**
  126. * Save Application Status Meta Box.
  127. *
  128. * @since 2.5.0
  129. */
  130. public function save_applicants_meta_boxes( $post_id ) {
  131. /**
  132. * We need to verify this came from our screen and with proper authorization,
  133. * because the save_post action can be triggered at other times.
  134. */
  135. // Check if nonce is set.
  136. if ( NULL == filter_input( INPUT_POST, 'jobpostapp_meta_box_nonce' ) ) {
  137. return;
  138. }
  139. // Verify that the nonce is valid.
  140. check_admin_referer( 'sjb_jobpostapp_meta_box', 'jobpostapp_meta_box_nonce' );
  141. // If this is an autosave, our form has not been submitted, so we don't want to do anything.
  142. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
  143. return;
  144. }
  145. // Check the user's permissions.
  146. if ( NULL != filter_input( INPUT_POST, 'post_type' ) && 'page' == filter_input( INPUT_POST, 'post_type') ) {
  147. if (!current_user_can('edit_page', $post_id)) {
  148. return;
  149. }
  150. } else {
  151. if (!current_user_can('edit_post', $post_id)) {
  152. return;
  153. }
  154. }
  155. /**
  156. * @hooked sjb_save_jobpost_meta - 10
  157. *
  158. * Save Jobpost Meta Box:
  159. *
  160. * - Save application status meta.
  161. *
  162. * @since 2.5.0
  163. *
  164. * @param int $post_id Post Id
  165. */
  166. do_action( 'sjb_save_jobpost_applicants_meta', $post_id );
  167. }
  168. }
  169. new Simple_Job_Board_Meta_Boxes_Init();