simple-job-board-template-functions.php 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. <?php
  2. /**
  3. * Template Functions
  4. *
  5. * Template functions specifically created for job listings.
  6. *
  7. * @link https://wordpress.org/plugins/simple-job-board
  8. *
  9. * @package Simple_Job_Board
  10. * @subpackage Simple_Job_Board/Templates
  11. * @since 2.1.0
  12. */
  13. if (!function_exists('get_simple_job_board_template')) {
  14. /**
  15. * Get and include template files.
  16. *
  17. * @since 2.1.0
  18. *
  19. * @param mixed $template_name
  20. * @param array $args (default: array())
  21. * @param string $template_path (default: '')
  22. * @param string $default_path (default: '')
  23. * @return void
  24. */
  25. function get_simple_job_board_template($template_name, $args = array(), $template_path = 'simple_job_board', $default_path = '') {
  26. if ($args && is_array($args)) {
  27. extract($args);
  28. }
  29. include( locate_simple_job_board_template($template_name, $template_path, $default_path) );
  30. }
  31. }
  32. if (!function_exists('locate_simple_job_board_template')) {
  33. /**
  34. * Locate a template and return the path for inclusion.
  35. *
  36. * This is the load order:
  37. *
  38. * yourtheme / $template_path / $template_name
  39. * yourtheme / $template_name
  40. * $default_path / $template_name
  41. *
  42. * @since 2.1.0
  43. *
  44. * @param string $template_name
  45. * @param string $template_path (default: 'simple_job_board')
  46. * @param string|bool $default_path (default: '') False to not load a default
  47. * @return string $template_name
  48. */
  49. function locate_simple_job_board_template($template_name, $template_path = 'simple_job_board', $default_path = '') {
  50. // Look within passed path within the theme - this is priority
  51. $template = locate_template(
  52. array(
  53. trailingslashit($template_path) . $template_name,
  54. $template_name
  55. )
  56. );
  57. // Get default template
  58. if (!$template && $default_path !== false) {
  59. $default_path = $default_path ? $default_path : untrailingslashit(plugin_dir_path(dirname(__DIR__))) . '/templates/';
  60. if (file_exists(trailingslashit($default_path) . $template_name)) {
  61. $template = trailingslashit($default_path) . $template_name;
  62. }
  63. }
  64. // Return what we found
  65. return apply_filters('simple_job_board_locate_template', $template, $template_name, $template_path);
  66. }
  67. }
  68. if (!function_exists('get_simple_job_board_template_part')) {
  69. /**
  70. * Get template part (for templates in loops).
  71. *
  72. * @since 2.1.0
  73. *
  74. * @param string $slug
  75. * @param string $name (default: '')
  76. * @param string $template_path (default: 'simple_job_board')
  77. * @param string|bool $default_path (default: '') False to not load a default
  78. */
  79. function get_simple_job_board_template_part($slug, $name = '', $template_path = 'simple_job_board', $default_path = '') {
  80. $template = '';
  81. if ($name) {
  82. $template = locate_simple_job_board_template("{$slug}-{$name}.php", $template_path, $default_path);
  83. }
  84. // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/simple_job_board/slug.php
  85. if (!$template) {
  86. $template = locate_simple_job_board_template("{$slug}.php", $template_path, $default_path);
  87. }
  88. if ($template) {
  89. load_template($template, FALSE);
  90. }
  91. }
  92. }
  93. if (!function_exists('sjb_body_classes')) {
  94. /**
  95. * Add custom body classes
  96. *
  97. * @since 2.1.0
  98. *
  99. * @param array $classes
  100. * @return array
  101. */
  102. function sjb_body_classes($classes) {
  103. $classes = (array) $classes;
  104. $classes[] = trim(sanitize_title(wp_get_theme()));
  105. if (is_sjb()) {
  106. $classes[] = 'sjb';
  107. }
  108. return array_unique($classes);
  109. }
  110. }
  111. add_filter('body_class', 'sjb_body_classes');
  112. if (!function_exists('sjb_the_job_category')) {
  113. /**
  114. * Job Categories.
  115. *
  116. * @since 2.1.0
  117. */
  118. function sjb_the_job_category($post = NULL) {
  119. if ($job_categories = sjb_get_the_job_category($post)) {
  120. $count = sizeof($job_categories);
  121. foreach ($job_categories as $job_category) {
  122. echo $job_category->name;
  123. if ($count > 1) {
  124. echo ',&nbsp;';
  125. }
  126. $count--;
  127. }
  128. }
  129. }
  130. }
  131. if ( !function_exists('sjb_get_the_job_category') ) {
  132. /**
  133. * sjb_get_the_job_category function.
  134. *
  135. * @since 2.1.0
  136. * @access public
  137. *
  138. * @param mixed $post (default: null)
  139. * @return void
  140. */
  141. function sjb_get_the_job_category($post = NULL) {
  142. $post = get_post($post);
  143. if ($post->post_type !== 'jobpost') {
  144. return;
  145. }
  146. $categories = wp_get_post_terms($post->ID, 'jobpost_category');
  147. /**
  148. * Job Categories.
  149. *
  150. * @since 2.1.0
  151. *
  152. * @param $categories Job Categories.
  153. * @param $post Post Object.
  154. */
  155. return apply_filters('sjb_the_job_category', $categories, $post);
  156. }
  157. }
  158. if (!function_exists('sjb_the_job_type')) {
  159. /**
  160. * sjb_the_job_type function.
  161. *
  162. * @since 2.1.0
  163. * @access public
  164. *
  165. * @return void
  166. */
  167. function sjb_the_job_type($post = NULL) {
  168. if ($job_types = sjb_get_the_job_type($post)) {
  169. $count = sizeof($job_types);
  170. foreach ($job_types as $job_type) {
  171. echo esc_attr(strip_tags($job_type->name));
  172. if ($count > 1) {
  173. echo ', ';
  174. }
  175. $count--;
  176. }
  177. }
  178. }
  179. }
  180. if (!function_exists('sjb_get_the_job_type')) {
  181. /**
  182. * sjb_get_the_job_type function.
  183. *
  184. * @since 2.1.0
  185. * @access public
  186. *
  187. * @param mixed $post (default: null)
  188. * @return void
  189. */
  190. function sjb_get_the_job_type($post = NULL) {
  191. $post = get_post($post);
  192. if ($post->post_type !== 'jobpost') {
  193. return;
  194. }
  195. $types = wp_get_post_terms($post->ID, 'jobpost_job_type');
  196. /**
  197. * Job Type.
  198. *
  199. * @since 2.1.0
  200. *
  201. * @param $types Job Types.
  202. * @param $post Post Object.
  203. */
  204. return apply_filters('sjb_the_job_type', $types, $post);
  205. }
  206. }
  207. if (!function_exists('sjb_the_job_location')) {
  208. /**
  209. * sjb_the_job_location function.
  210. *
  211. * @since 2.1.0
  212. *
  213. * @return void
  214. */
  215. function sjb_the_job_location($post = NULL) {
  216. $post = get_post($post);
  217. if ($job_locations = sjb_get_the_job_location($post)) {
  218. $count = sizeof($job_locations);
  219. foreach ($job_locations as $location) {
  220. echo esc_attr(strip_tags($location->name));
  221. if ($count > 1) {
  222. echo ',&nbsp;';
  223. }
  224. $count--;
  225. }
  226. }
  227. }
  228. }
  229. if (!function_exists('sjb_get_the_job_location')) {
  230. /**
  231. * sjb_get_the_job_location function.
  232. *
  233. * @since 2.1.0
  234. *
  235. * @param mixed $post (default: NULL)
  236. * @return void
  237. */
  238. function sjb_get_the_job_location($post = NULL) {
  239. $post = get_post($post);
  240. if ($post->post_type !== 'jobpost') {
  241. return;
  242. }
  243. $locations = wp_get_post_terms($post->ID, 'jobpost_location');
  244. /**
  245. * Job Location.
  246. *
  247. * @since 2.1.0
  248. *
  249. * @param $locations Job Locations.
  250. * @param $post Post Object
  251. */
  252. return apply_filters('sjb_the_job_location', $locations, $post);
  253. }
  254. }
  255. if (!function_exists('sjb_the_company_name')) {
  256. /**
  257. * Display or retrieve the current company name with optional content.
  258. *
  259. * @since 2.1.0
  260. *
  261. * @param mixed $id (default: null)
  262. * @return void
  263. */
  264. function sjb_the_company_name($before = '', $after = '', $echo = true, $post = NULL) {
  265. $company_name = sjb_get_the_company_name($post);
  266. if (strlen($company_name) == 0)
  267. return;
  268. $company_name = esc_attr(strip_tags($company_name));
  269. $company_name = $before . $company_name . $after;
  270. if ($echo)
  271. echo $company_name;
  272. else
  273. return $company_name;
  274. }
  275. }
  276. if (!function_exists('sjb_get_the_company_name')) {
  277. /**
  278. * sjb_get_the_company_name function.
  279. *
  280. * @since 2.1.0
  281. *
  282. * @param int $post (default: null)
  283. * @return string
  284. */
  285. function sjb_get_the_company_name($post = NULL) {
  286. $post = get_post($post);
  287. if ($post->post_type !== 'jobpost') {
  288. return '';
  289. }
  290. /**
  291. * Company Name.
  292. *
  293. * @since 2.1.0
  294. *
  295. * @param $post->simple_job_board_company_name Company Name.
  296. * @param $post Post Object
  297. */
  298. return apply_filters('sjb_the_company_name', $post->simple_job_board_company_name, $post);
  299. }
  300. }
  301. if (!function_exists('sjb_the_job_posting_time')) {
  302. /**
  303. * Display or retrieve the job posting time.
  304. *
  305. * @since 2.1.0
  306. *
  307. * @param mixed $id (default: null)
  308. * @return void
  309. */
  310. function sjb_the_job_posting_time($post = NULL) {
  311. $job_posting_time = sjb_get_the_job_posting_time($post);
  312. if (strlen($job_posting_time) == 0)
  313. return;
  314. echo esc_attr(strip_tags($job_posting_time));
  315. }
  316. }
  317. if (!function_exists('sjb_get_the_job_posting_time')) {
  318. /**
  319. * sjb_get_the_job_posting_time function.
  320. *
  321. * @since 2.1.0
  322. *
  323. * @param int $post (default: null)
  324. * @return string
  325. */
  326. function sjb_get_the_job_posting_time($post = NULL) {
  327. $post = get_post($post);
  328. if ($post->post_type !== 'jobpost') {
  329. return '';
  330. }
  331. /**
  332. * Job Posted Date.
  333. *
  334. * @since 2.1.0
  335. *
  336. * @param human_time_diff(get_post_time('U'), current_time('timestamp')) Job Posted Date.
  337. * @param $post Post Object
  338. */
  339. return apply_filters('sjb_the_job_posting_time', human_time_diff(get_post_time('U'), current_time('timestamp')), $post);
  340. }
  341. }
  342. if (!function_exists('sjb_get_the_company_website')) {
  343. /**
  344. * sjb_get_the_company_website function.
  345. *
  346. * @since 2.1.0
  347. *
  348. * @param int $post (default: null)
  349. * @return void
  350. */
  351. function sjb_get_the_company_website($post = NULL) {
  352. $post = get_post($post);
  353. if ($post->post_type !== 'jobpost') {
  354. return;
  355. }
  356. $website = $post->simple_job_board_company_website;
  357. if ($website && !strstr($website, 'http:') && !strstr($website, 'https:')) {
  358. $website = 'http://' . $website;
  359. }
  360. /**
  361. * Company Website.
  362. *
  363. * @since 2.1.0
  364. *
  365. * @param $website Company Website
  366. * @param $post Post Object
  367. */
  368. return apply_filters('sjb_the_company_website', $website, $post);
  369. }
  370. }
  371. if (!function_exists('sjb_the_company_tagline')) {
  372. /**
  373. * Display or retrieve the current company tagline with optional content.
  374. *
  375. * @since 2.1.0
  376. *
  377. * @param mixed $id (default: null)
  378. * @return void
  379. */
  380. function sjb_the_company_tagline($before = '', $after = '', $echo = TRUE, $post = NULL) {
  381. $company_tagline = sjb_get_the_company_tagline($post);
  382. if (strlen($company_tagline) == 0)
  383. return;
  384. $company_tagline = esc_attr(strip_tags($company_tagline));
  385. $company_tagline = $before . $company_tagline . $after;
  386. if ($echo)
  387. echo $company_tagline;
  388. else
  389. return $company_tagline;
  390. }
  391. }
  392. if (!function_exists('sjb_get_the_company_tagline')) {
  393. /**
  394. * sjb_get_the_company_tagline function.
  395. *
  396. * @since 2.1.0
  397. *
  398. * @param int $post (default: 0)
  399. * @return void
  400. */
  401. function sjb_get_the_company_tagline($post = NULL) {
  402. $post = get_post($post);
  403. if ($post->post_type !== 'jobpost')
  404. return;
  405. /**
  406. * Company Tagline
  407. *
  408. * @since 2.1.0
  409. *
  410. * @param $post->simple_job_board_company_tagline Company Tagline
  411. * @param $post Post Object
  412. */
  413. return apply_filters('sjb_the_company_tagline', $post->simple_job_board_company_tagline, $post);
  414. }
  415. }
  416. if (!function_exists('sjb_the_company_logo')) {
  417. /**
  418. * sjb_the_company_logo function.
  419. *
  420. * @since 2.1.0
  421. *
  422. * @param string $size (default: 'full')
  423. * @param array or object array $atts {
  424. * associative array with "id" & "class" indexes
  425. *
  426. * @type string id => "logo id"
  427. *
  428. * @type string class => "logo class"
  429. * } (default: null)
  430. * @param mixed $default (default: null)
  431. * @return void
  432. */
  433. function sjb_the_company_logo($size = 'full', $atts = NULL, $default = NULL, $post = NULL) {
  434. $logo = sjb_get_the_company_logo($post);
  435. $id = NULL;
  436. $class = NULL;
  437. /* Get logo attributes */
  438. if (!empty($atts)) {
  439. if (is_array($atts)) {
  440. $id = isset($atts['id']) ? $atts['id'] : '';
  441. $class = isset($atts['class']) ? $atts['class'] : '';
  442. } else {
  443. $id = isset($atts->id) ? $atts->id : '';
  444. $class = isset($atts->class) ? $atts->class : '';
  445. }
  446. }
  447. if (!empty($logo) && ( strstr($logo, 'http') || file_exists($logo) )) {
  448. if ($size !== 'full') {
  449. $logo = sjb_get_resized_image($logo, $size);
  450. }
  451. echo '<img src="' . esc_attr($logo) . '" alt="' . esc_attr(sjb_get_the_company_name($post)) . '" class="sjb-img-responsive ' . $class . '" id="' . $id . '"/>';
  452. } elseif ($default) {
  453. echo '<img src="' . esc_attr($default) . '" alt="' . esc_attr(sjb_get_the_company_name($post)) . '" class="sjb-img-responsive ' . $class . '" id="' . $id . '"/>';
  454. } else {
  455. echo '<img src="' . esc_attr(apply_filters('simple_job_board_default_company_logo', plugin_dir_url(dirname(__FILE__)) . 'images/company.png')) . '" alt="' . esc_attr(sjb_get_the_company_name($post)) . '" class="sjb-img-responsive ' . $class . '" id="' . $id . '"/>';
  456. }
  457. }
  458. }
  459. if (!function_exists('sjb_get_the_company_logo')) {
  460. /**
  461. * sjb_get_the_company_logo function.
  462. *
  463. * @since 2.1.0
  464. *
  465. * @param mixed $post (default: null)
  466. * @return string $post->simple_job_board_company_logo Company logo
  467. */
  468. function sjb_get_the_company_logo($post = NULL) {
  469. $post = get_post($post);
  470. if ($post->post_type !== 'jobpost')
  471. return;
  472. /**
  473. * Company Logo
  474. *
  475. * @since 2.1.0
  476. *
  477. * @param $post->simple_job_board_company_logo Company Logo
  478. * @param $post Post Id
  479. */
  480. return apply_filters('sjb_the_company_logo', $post->simple_job_board_company_logo, $post);
  481. }
  482. }
  483. if (!function_exists('sjb_get_resized_image')) {
  484. /**
  485. * Resize and get url of the image
  486. *
  487. * @since 2.1.0
  488. *
  489. * @param string $logo
  490. * @param string $size
  491. * @return string $logo Company logo
  492. */
  493. function sjb_get_resized_image($logo, $size) {
  494. global $_wp_additional_image_sizes;
  495. if ($size !== 'full' && strstr($logo, WP_CONTENT_URL) && (isset($_wp_additional_image_sizes[$size]) || in_array($size, array('thumbnail', 'medium', 'large'
  496. )) )) {
  497. if (in_array($size, array('thumbnail', 'medium', 'large'))) {
  498. $img_width = get_option($size . '_size_w');
  499. $img_height = get_option($size . '_size_h');
  500. $img_crop = get_option($size . '_size_crop');
  501. } else {
  502. $img_width = $_wp_additional_image_sizes[$size]['width'];
  503. $img_height = $_wp_additional_image_sizes[$size]['height'];
  504. $img_crop = $_wp_additional_image_sizes[$size]['crop'];
  505. }
  506. $upload_dir = wp_upload_dir();
  507. $logo_path = str_replace(array($upload_dir['baseurl'], $upload_dir['url'], WP_CONTENT_URL), array($upload_dir['basedir'], $upload_dir['path'], WP_CONTENT_DIR), $logo);
  508. $path_parts = pathinfo($logo_path);
  509. $resized_logo_path = str_replace('.' . $path_parts['extension'], '-' . $size . '.' . $path_parts['extension'], $logo_path);
  510. if (strstr($resized_logo_path, 'http:') || strstr($resized_logo_path, 'https:')) {
  511. return $logo;
  512. }
  513. if (!file_exists($resized_logo_path)) {
  514. ob_start();
  515. $image = wp_get_image_editor($logo_path);
  516. if (!is_wp_error($image)) {
  517. $resize = $image->resize($img_width, $img_height, $img_crop);
  518. if (!is_wp_error($resize)) {
  519. $save = $image->save($resized_logo_path);
  520. if (!is_wp_error($save)) {
  521. $logo = dirname($logo) . '/' . basename($resized_logo_path);
  522. }
  523. }
  524. }
  525. ob_get_clean();
  526. } else {
  527. $logo = dirname($logo) . '/' . basename($resized_logo_path);
  528. }
  529. }
  530. return $logo;
  531. }
  532. }
  533. if (!function_exists('sjb_get_the_excerpt')) {
  534. /**
  535. * Custom Excerpt Function.
  536. *
  537. * @since 1.0.0
  538. *
  539. * @param string $charlength Character length.
  540. * @param string $readmore Read more Enable.
  541. * @param string $readmore_text Read more Text.
  542. * @return string $excerpt Excerpt of Job Description
  543. */
  544. function sjb_get_the_excerpt() {
  545. $excerpt = '<p>' . trim(preg_replace('/<a[^>]*>(.*)<\/a>/iU', '', get_the_excerpt())) . '</p>';
  546. $more = '<p><a href="' . get_the_permalink() . '" class="btn btn-primary">' . esc_html__('Read More', 'simple-job-board') . '</a></p>';
  547. return apply_filters('sjb_get_the_excerpt', $excerpt . $more, $excerpt, $more);
  548. }
  549. }
  550. if (!function_exists('sjb_keywords_search_by_title')) {
  551. /**
  552. * Search SQL filter for matching against post title only.
  553. *
  554. * @since 2.1.4
  555. *
  556. * @global Object WP_Query $wp_query
  557. *
  558. * @param string $search Searched Keyword
  559. * @return string $search Search Results from Post Title
  560. */
  561. function sjb_keywords_search_by_title($search, $wp_query) {
  562. if (!empty($search) && !empty($wp_query->query_vars['search_terms']) && isset($wp_query->query['post_type']) && 'jobpost' == $wp_query->query['post_type']) {
  563. global $wpdb;
  564. $q = $wp_query->query_vars;
  565. $n = !empty($q['exact']) ? '' : '%';
  566. $search = array();
  567. foreach ((array) $q['search_terms'] as $term)
  568. $search[] = $wpdb->prepare("$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like($term) . $n);
  569. if (!is_user_logged_in())
  570. $search[] = "$wpdb->posts.post_password = ''";
  571. $search = ' AND ' . implode(' AND ', $search);
  572. }
  573. return $search;
  574. }
  575. }
  576. /* Hook -> Keywords Search By Title */
  577. add_filter('posts_search', 'sjb_keywords_search_by_title', 10, 2);
  578. if (!function_exists('sjb_is_checked')) {
  579. /**
  580. * Assign Default Radio button Check
  581. *
  582. * @since 2.1.0
  583. */
  584. function sjb_is_checked($i) {
  585. $checked = ( $i == 0 ) ? "checked" : NULL;
  586. return $checked;
  587. }
  588. }
  589. if (!function_exists('sjb_job_listing_meta_display')) {
  590. /**
  591. * Displays job meta data on the single job page.
  592. *
  593. * @since 2.1.0
  594. */
  595. function sjb_job_listing_meta_display() {
  596. get_simple_job_board_template('single-jobpost/content-single-job-listing-meta.php', array());
  597. }
  598. }
  599. add_action('sjb_single_job_listing_start', 'sjb_job_listing_meta_display', 20);
  600. if (!function_exists('sjb_job_listing_features')) {
  601. /**
  602. * Displays job features data on the single job page.
  603. *
  604. * @since 2.1.0
  605. */
  606. function sjb_job_listing_features() {
  607. get_simple_job_board_template('single-jobpost/job-features.php', array());
  608. }
  609. }
  610. add_action('sjb_single_job_listing_end', 'sjb_job_listing_features', 20);
  611. if (!function_exists('sjb_job_listing_application_form')) {
  612. /**
  613. * Displays job application form on the single job page
  614. *
  615. * @since 2.1.0
  616. */
  617. function sjb_job_listing_application_form() {
  618. get_simple_job_board_template('single-jobpost/job-application.php', array());
  619. }
  620. }
  621. add_action('sjb_single_job_listing_end', 'sjb_job_listing_application_form', 30);
  622. if (!function_exists('sjb_job_listing_wrapper_start')) {
  623. /**
  624. * Output Content Wrapper start div's
  625. *
  626. * @since 2.2.0
  627. */
  628. function sjb_job_listing_wrapper_start() {
  629. get_simple_job_board_template('global/content-wrapper-start.php');
  630. }
  631. }
  632. add_action('sjb_before_main_content', 'sjb_job_listing_wrapper_start', 10);
  633. if (!function_exists('sjb_job_listing_wrapper_end')) {
  634. /**
  635. * Output Content Wrapper end div's
  636. *
  637. * @since 2.2.0
  638. */
  639. function sjb_job_listing_wrapper_end() {
  640. get_simple_job_board_template('global/content-wrapper-end.php');
  641. }
  642. }
  643. add_action('sjb_after_main_content', 'sjb_job_listing_wrapper_end', 10);
  644. if (!function_exists('sjb_job_listing_view')) {
  645. /**
  646. * Job Listing View
  647. *
  648. * This function displays the user defined job listing view.
  649. *
  650. * @since 2.2.3
  651. */
  652. function sjb_job_listing_view() {
  653. // Display the user defined job listing view
  654. if ('grid-view' === get_option('job_board_listing_view')) {
  655. get_simple_job_board_template('content-job-listing-grid-view.php');
  656. } else {
  657. get_simple_job_board_template('content-job-listing-list-view.php');
  658. }
  659. }
  660. }
  661. // Hook -> Job Listing View
  662. add_action('sjb_job_listing_view', 'sjb_job_listing_view', 10);
  663. if (!function_exists('sjb_job_features_count')) {
  664. /**
  665. * Return Count of Job Features.
  666. *
  667. * @since 2.2.0
  668. */
  669. function sjb_job_features_count() {
  670. global $post;
  671. $keys = get_post_custom_keys(get_the_ID());
  672. $count = 0;
  673. if ($keys != NULL):
  674. foreach ($keys as $key):
  675. if (substr($key, 0, 11) == 'jobfeature_') {
  676. $val = get_post_meta($post->ID, $key, TRUE);
  677. if (is_serialized($val)) {
  678. $val = unserialize($val);
  679. }
  680. if (!empty($val['value'])) {
  681. $count++;
  682. }
  683. }
  684. endforeach;
  685. endif;
  686. return $count;
  687. }
  688. }
  689. if (!function_exists('sjb_front_end_scripts')) {
  690. /**
  691. * Enqueue Frontend Styles & Scripts.
  692. *
  693. * @since 2.2.3
  694. */
  695. function sjb_front_end_scripts() {
  696. // Enqueue Scripts
  697. wp_enqueue_script('simple-job-board-validate-telephone-input');
  698. wp_enqueue_script('simple-job-board-validate-telephone-input-utiliy');
  699. wp_enqueue_script('simple-job-board-front-end');
  700. }
  701. }
  702. // Action -> Enqueue Frontend Styles & Scripts.
  703. add_action('sjb_enqueue_scripts', 'sjb_front_end_scripts');
  704. if (!function_exists('sjb_get_slugs')) {
  705. /**
  706. * Get Current Page Slug.
  707. *
  708. * @since 2.2.4
  709. */
  710. function sjb_get_slugs() {
  711. global $post;
  712. if (is_archive()) {
  713. $link = get_post_type_archive_link('jobpost');
  714. } else {
  715. $link = get_permalink($post->ID);
  716. }
  717. if (empty($link)) {
  718. return FALSE;
  719. } else {
  720. $link = str_replace(home_url('/'), '', $link);
  721. return $link;
  722. }
  723. }
  724. }
  725. if (!function_exists('sjb_is_keyword_search')) {
  726. /**
  727. * Is Category Filter
  728. *
  729. * @since 2.4.0
  730. */
  731. function sjb_is_keyword_search() {
  732. $is_search = ('yes' === get_option('job_board_search_bar') ) ? TRUE : FALSE;
  733. return $is_search;
  734. }
  735. }
  736. if (!function_exists('sjb_is_category_filter')) {
  737. /**
  738. * Is Category Filter
  739. *
  740. * @since 2.4.0
  741. */
  742. function sjb_is_category_filter() {
  743. $is_cat = ( NULL != get_terms('jobpost_category') && ( 'yes' === get_option('job_board_category_filter') ) ) ? TRUE : FALSE;
  744. return $is_cat;
  745. }
  746. }
  747. if (!function_exists('sjb_is_type_filter')) {
  748. /**
  749. * Is Job Type Filter
  750. *
  751. * @since 2.4.0
  752. *
  753. */
  754. function sjb_is_type_filter() {
  755. $is_type = ( NULL != get_terms('jobpost_job_type') && 'yes' === get_option('job_board_jobtype_filter') ) ? TRUE : FALSE;
  756. return $is_type;
  757. }
  758. }
  759. if (!function_exists('sjb_is_location_filter')) {
  760. /**
  761. * Is Job Location Filter
  762. *
  763. * @since 2.4.0
  764. */
  765. function sjb_is_location_filter() {
  766. $is_loc = ( NULL != get_terms('jobpost_location') && 'yes' === get_option('job_board_location_filter') ) ? TRUE : FALSE;
  767. return $is_loc;
  768. }
  769. }
  770. if (!function_exists('sjb_is_filter_dropdowns')) {
  771. /**
  772. * Is Job Filters
  773. *
  774. * @since 2.4.0
  775. */
  776. function sjb_is_filter_dropdowns() {
  777. $filters_dropdowns = ( sjb_is_category_filter() || sjb_is_type_filter() || sjb_is_location_filter() ) ? TRUE : FALSE;
  778. return apply_filters('sjb_is_filter_dropdowns', $filters_dropdowns);
  779. }
  780. }
  781. if (!function_exists('is_sjb')) {
  782. /**
  783. * is_sjb - Returns TRUE when Viewing the Jobpost Pages.
  784. *
  785. * @since 2.4.0
  786. *
  787. * @return bool
  788. */
  789. function is_sjb() {
  790. return apply_filters('is_sjb', ( is_jobpost() || is_jobpost_archive() || is_jobpost_taxonomy() || is_jobpost_shortcode() ) ? TRUE : FALSE );
  791. }
  792. }
  793. if (!function_exists('is_jobpost')) {
  794. /**
  795. * is_jobpost - Returns TRUE when Viewing the Jobpost Single Page.
  796. *
  797. * @since 2.4.0
  798. *
  799. * @return bool
  800. */
  801. function is_jobpost() {
  802. return is_singular(array('jobpost'));
  803. }
  804. }
  805. if (!function_exists('is_jobpost_archive')) {
  806. /**
  807. * is_jobpost_archive - Returns TRUE when Viewing the Job Archive Page.
  808. *
  809. * @since 2.4.0
  810. *
  811. * @return bool
  812. */
  813. function is_jobpost_archive() {
  814. return ( is_post_type_archive('jobpost') );
  815. }
  816. }
  817. if (!function_exists('is_jobpost_taxonomy')) {
  818. /**
  819. * is_jobpost_taxonomy - Returns TRUE when Viewing the Job Taxonomies.
  820. *
  821. * @since 2.4.0
  822. *
  823. * @return bool
  824. */
  825. function is_jobpost_taxonomy() {
  826. return is_tax(get_object_taxonomies('jobpost'));
  827. }
  828. }
  829. if (!function_exists('is_jobpost_shortcode')) {
  830. /**
  831. * is_jobpost_shortcode - Returns TRUE when Viewing the Job Listing.
  832. *
  833. * @since 2.4.0
  834. *
  835. * @return bool
  836. */
  837. function is_jobpost_shortcode() {
  838. global $post;
  839. return is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'jobpost');
  840. }
  841. }
  842. if (!function_exists('sjb_the_title')) {
  843. /**
  844. * Display Job Title
  845. *
  846. * @since 2.4.4
  847. *
  848. * @param string $before Add string befor title.
  849. * @param string $after Add string after title.
  850. * @param bool $echo TRUE/FALSE
  851. * @param object $post Post Object
  852. * @return $job_title Job Title
  853. */
  854. function sjb_the_title($before = '', $after = '', $echo = TRUE, $post = NULL) {
  855. $job_title = sjb_get_the_title($post);
  856. if (strlen($job_title) == 0)
  857. return;
  858. $job_title = esc_attr(strip_tags($job_title));
  859. $job_title = $before . $job_title . $after;
  860. if ($echo)
  861. echo $job_title;
  862. else
  863. return $job_title;
  864. }
  865. }
  866. if (!function_exists('sjb_get_the_title')) {
  867. /**
  868. * Return Job Title
  869. *
  870. * @since 2.4.4
  871. *
  872. * @param object $post Post Object
  873. * @return $job_title Job Title
  874. */
  875. function sjb_get_the_title($post = NULL) {
  876. global $post;
  877. $title = get_the_title();
  878. /**
  879. * Job Title
  880. *
  881. * @since 2.4.4
  882. *
  883. * @param $title Job Title
  884. * @param $post Post Id
  885. */
  886. return apply_filters('sjb_the_title', $title, $post);
  887. }
  888. }
  889. /**
  890. * Single Job Content Start
  891. *
  892. * @since 2.5.0
  893. */
  894. if (!function_exists('sjb_single_job_content_start')) {
  895. function sjb_single_job_content_start() {
  896. get_simple_job_board_template('single-jobpost/single-job-wrapper-start.php');
  897. }
  898. }
  899. add_action('sjb_single_job_content_start', 'sjb_single_job_content_start');
  900. /**
  901. * Single Job Content End
  902. *
  903. * @since 2.5.0
  904. */
  905. if (!function_exists('sjb_single_job_content_end')) {
  906. function sjb_single_job_content_end() {
  907. get_simple_job_board_template('single-jobpost/single-job-wrapper-end.php');
  908. }
  909. }
  910. add_action('sjb_single_job_content_end', 'sjb_single_job_content_end');
  911. /**
  912. * Converts a string (e.g. 'yes' or 'no') to a bool.
  913. *
  914. * @since 2.6.0
  915. *
  916. * @param string $string String to convert.
  917. * @return bool
  918. */
  919. function sjb_string_to_bool( $string ) {
  920. return is_bool( $string ) ? $string : ( 'yes' === $string || 1 === $string || 'true' === $string || '1' === $string );
  921. }