class-simple-job-board-shortcode-jobpost.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. if (!defined('ABSPATH')) {
  3. exit;
  4. } // Exit if accessed directly
  5. /**
  6. * Simple_Job_Board_Shortcode_Jobpost Class
  7. *
  8. * This class lists the jobs on frontend for [jobpost] shortcode.
  9. *
  10. * @link https://wordpress.org/plugins/simple-job-board
  11. * @since 2.2.3
  12. * @since 2.4.0 Revised Inputs & Outputs Sanitization & Escaping
  13. *
  14. * @package Simple_Job_Board
  15. * @subpackage Simple_Job_Board/includes/shortcodes
  16. * @author PressTigers <support@presstigers.com>
  17. */
  18. class Simple_Job_Board_Shortcode_Jobpost {
  19. /**
  20. * Constructor
  21. */
  22. public function __construct() {
  23. // Hook -> Add Job Listing ShortCode
  24. add_shortcode('jobpost', array($this, 'jobpost_shortcode'));
  25. // add_action('init', array($this, 'gggb_init'));
  26. }
  27. public function gggb_init() {
  28. // Hook -> Add Job Listing ShortCode
  29. // add_shortcode('jobpost', array($this, 'jobpost_shortcode'));
  30. // register_block_type( 'simple-job-board/gutenberg-blocks', array(
  31. // 'render_callback' => 'jobpost_shortcode',
  32. // ) );
  33. }
  34. /**
  35. * List all Jobs.
  36. *
  37. * @since 1.0.0
  38. *
  39. * @param array $atts Shortcode attribute
  40. * @return HTML $html Job Listing HTML Structure.
  41. */
  42. public function jobpost_shortcode( $atts, $content ) {
  43. /**
  44. * Enqueue Frontend Scripts.
  45. *
  46. * @since 2.2.4
  47. */
  48. do_action('sjb_enqueue_scripts');
  49. ob_start();
  50. global $job_query;
  51. // Shortcode Default Array
  52. $shortcode_args = array(
  53. 'posts' => '15',
  54. 'category' => '',
  55. 'type' => '',
  56. 'location' => '',
  57. 'keywords' => '',
  58. 'order' => 'DESC',
  59. 'search' => 'true',
  60. );
  61. $atts = is_array($atts) ? apply_filters('sjb_shortcode_atts', array_map('sanitize_text_field', $atts)) : '';
  62. // Combine User Defined Shortcode Attributes with Known Attributes
  63. $shortcode_args = shortcode_atts(apply_filters('sjb_output_jobs_defaults', $shortcode_args, $atts), $atts);
  64. // Get paged variable.
  65. if (get_query_var('paged')) {
  66. $paged = (int) get_query_var('paged');
  67. } elseif (get_query_var('page')) {
  68. $paged = (int) get_query_var('page');
  69. } else {
  70. $paged = 1;
  71. }
  72. // WP Query Default Arguments
  73. $args = apply_filters(
  74. 'sjb_output_jobs_args', array(
  75. 'post_status' => 'publish',
  76. 'posts_per_page' => esc_attr($shortcode_args['posts']),
  77. 'post_type' => 'jobpost',
  78. 'paged' => $paged,
  79. 'order' => esc_attr($shortcode_args['order']),
  80. ), $atts
  81. );
  82. // Merge $arg array on each $_GET element
  83. $args['jobpost_category'] = (!empty($_GET['selected_category']) && -1 != $_GET['selected_category'] ) ? esc_attr($_GET['selected_category']) : esc_attr($shortcode_args['category']);
  84. $args['jobpost_job_type'] = (!empty($_GET['selected_jobtype']) && -1 != $_GET['selected_jobtype'] ) ? esc_attr($_GET['selected_jobtype']) : esc_attr($shortcode_args['type']);
  85. $args['jobpost_location'] = (!empty($_GET['selected_location']) && -1 != $_GET['selected_location'] ) ? esc_attr($_GET['selected_location']) : esc_attr($shortcode_args['location']);
  86. $args['s'] = ( NULL != filter_input(INPUT_GET, 'search_keywords') ) ? sanitize_text_field($_GET['search_keywords']) : '';
  87. // Job Query
  88. $job_query = new WP_Query($args);
  89. /**
  90. * Fires before listing jobs on job listing page.
  91. *
  92. * @since 2.2.0
  93. */
  94. do_action('sjb_job_filters_before');
  95. /**
  96. * Template -> Job Listing Wrapper Start:
  97. *
  98. * - SJB Starting of Job Listing Wrapper
  99. */
  100. get_simple_job_board_template('listing/listing-wrapper-start.php');
  101. if ('false' != strtolower($shortcode_args['search']) && !empty($shortcode_args['search'])):
  102. /**
  103. * Template -> Job Filters:
  104. *
  105. * - Keywords Search.
  106. * - Job Category Filter.
  107. * - Job Type Filter.
  108. * - Job Location Filter.
  109. *
  110. * Search jobs by keywords, category, location & type.
  111. */
  112. get_simple_job_board_template('job-filters.php', array('per_page' => $shortcode_args['posts'], 'order' => $shortcode_args['order'], 'categories' => $shortcode_args['category'], 'job_types' => $shortcode_args['type'], 'atts' => $atts, 'location' => $shortcode_args['location'], 'keywords' => $shortcode_args['keywords']));
  113. endif;
  114. /**
  115. * Template -> Job Listing Start:
  116. *
  117. * - SJB Starting of Job List
  118. */
  119. get_simple_job_board_template('listing/job-listings-start.php');
  120. /**
  121. * Fires before listing jobs on job listing page.
  122. *
  123. * @since 2.2.0
  124. */
  125. do_action('sjb_job_listing_before');
  126. if ($job_query->have_posts()):
  127. global $counter, $post_count;
  128. $counter = 1;
  129. $post_count = $job_query->post_count;
  130. while ($job_query->have_posts()): $job_query->the_post();
  131. /**
  132. * Hook -> sjb_job_listing_view
  133. *
  134. * @hooked sjb_job_listing_view - 10
  135. *
  136. * Display the user defined job listing view:
  137. *
  138. * - Either job listing grid view or list view.
  139. *
  140. * @since 2.2.3
  141. */
  142. do_action('sjb_job_listing_view');
  143. endwhile;
  144. /**
  145. * Template -> Pagination:
  146. *
  147. * - Add Pagination to Resulted Jobs.
  148. */
  149. get_simple_job_board_template('listing/job-pagination.php', array('job_query' => $job_query));
  150. else:
  151. /**
  152. * Template -> No Job Found:
  153. *
  154. * - Display Message on No Job Found.
  155. */
  156. get_simple_job_board_template_part('listing/content-no-jobs-found');
  157. endif;
  158. wp_reset_postdata();
  159. /**
  160. * Fires after listing jobs on job listing page.
  161. *
  162. * @since 2.2.0
  163. */
  164. do_action('sjb_job_listing_after');
  165. /**
  166. * Template -> Job Listing End:
  167. *
  168. * - SJB Ending of Job List.
  169. */
  170. get_simple_job_board_template('listing/job-listings-end.php');
  171. /**
  172. * Template -> Job Listing Wrapper End:
  173. *
  174. * - SJB Endding of Job Listing Wrapper
  175. */
  176. get_simple_job_board_template('listing/listing-wrapper-end.php');
  177. $html = ob_get_clean();
  178. /**
  179. * Filter -> Modify the Job Listing Shortcode
  180. *
  181. * @since 2.2.0
  182. *
  183. * @param HTML $html Job Listing HTML Structure.
  184. */
  185. return apply_filters('sjb_job_listing_shortcode', $html . do_shortcode($content), $atts);
  186. }
  187. }
  188. new Simple_Job_Board_Shortcode_Jobpost();