class-simple-job-board-settings-general.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly
  2. /**
  3. * Simple_Job_Board_Settings_General Class
  4. *
  5. * This file saves the slugs of custom post type and taxonomies. User can
  6. * defined the "jopost" custom post type, "job category", "job type" &
  7. * "job location" taxonomies slugs according to your site requirements.
  8. *
  9. * @link https://wordpress.org/plugins/simple-job-board
  10. * @since 2.2.3
  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_General {
  18. /**
  19. * Initialize the class and set its properties.
  20. *
  21. * @since 2.2.3
  22. */
  23. public function __construct() {
  24. // Filter -> Add Settings General Tab
  25. add_filter('sjb_settings_tab_menus', array($this, 'sjb_add_settings_tab'), 20);
  26. // Action -> Add Settings General Section
  27. add_action('sjb_settings_tab_section', array($this, 'sjb_add_settings_section'), 20);
  28. // Action -> Save Settings General Section
  29. add_action('sjb_save_setting_sections', array($this, 'sjb_save_settings_section'));
  30. }
  31. /**
  32. * Add Settings General Tab.
  33. *
  34. * @since 2.2.3
  35. *
  36. * @param array $tabs Settings Tab
  37. * @return array $tabs Merge array of Settings Tab with General Tab.
  38. */
  39. public function sjb_add_settings_tab($tabs) {
  40. $tabs['general'] = esc_html__('General', 'simple-job-board');
  41. return $tabs;
  42. }
  43. /**
  44. * Add Settings General Section.
  45. *
  46. * This function is used to display settings general section & also display
  47. * the stored settings.
  48. *
  49. * @since 2.2.3
  50. */
  51. public function sjb_add_settings_section() {
  52. ?>
  53. <!-- General -->
  54. <div id="settings-general" class="sjb-admin-settings" style="display: block;">
  55. <?php
  56. // Get Custom Post Type & Taxonomies Options
  57. $jobpost_slug = get_option( 'job_board_jobpost_slug' ) ? get_option( 'job_board_jobpost_slug' ) : 'jobs';
  58. $category_slug = get_option( 'job_board_job_category_slug' ) ? get_option( 'job_board_job_category_slug') : 'job-category';
  59. $job_type_slug = get_option('job_board_job_type_slug') ? get_option('job_board_job_type_slug') : 'job-type';
  60. $job_location_slug = get_option('job_board_job_location_slug') ? get_option('job_board_job_location_slug') : 'job-location';
  61. ?>
  62. <form method="post" id="general_options_form">
  63. <?php
  64. /**
  65. * Action -> Add new section before general section content.
  66. *
  67. * @since 2.2.0
  68. */
  69. do_action('sjb_general_options_before');
  70. ?>
  71. <h4 class="first">
  72. <?php
  73. /**
  74. * Modify the title of General Options Section
  75. *
  76. * @since 2.2.0
  77. *
  78. * @param string General Options Section Title
  79. */
  80. echo apply_filters('sjb_general_option_title', esc_html__('General Options', 'simple-job-board'));
  81. ?>
  82. </h4>
  83. <div class="sjb-section">
  84. <div class="sjb-content">
  85. <?php
  86. /**
  87. * Action -> Add new fields at start of general section.
  88. *
  89. * @since 2.2.0
  90. */
  91. do_action( 'sjb_general_options_start' );
  92. ?>
  93. <div class="sjb-form-group">
  94. <label><?php echo esc_html__( 'Jobpost Custom Post Type Slug:', 'simple-job-board' ); ?></label>
  95. <input type="text" name="jobpost_slug" value="<?php echo esc_attr($jobpost_slug); ?>" size="30" maxlength="25">
  96. </div>
  97. <div class="sjb-form-group">
  98. <label><?php echo esc_html__('Job Category Taxonomy Slug:', 'simple-job-board'); ?></label>
  99. <input type="text" name="job_category_slug" value="<?php echo esc_attr($category_slug); ?>" size="30" maxlength="25" />
  100. </div>
  101. <div class="sjb-form-group">
  102. <label><?php echo esc_html__('Job Type Taxonomy Slug:', 'simple-job-board'); ?></label>
  103. <input type="text" name="job_type_slug" value="<?php echo esc_attr($job_type_slug); ?>" size="30" maxlength="25" />
  104. </div>
  105. <div class="sjb-form-group">
  106. <label><?php echo esc_html__('Job Location Taxonomy Slug:', 'simple-job-board'); ?></label>
  107. <input type="text" name="job_location_slug" value="<?php echo esc_attr($job_location_slug); ?>" size="30" maxlength="25"/>
  108. </div>
  109. <?php
  110. /**
  111. * Action -> Add new fields at the end of general section.
  112. *
  113. * @since 2.2.0
  114. */
  115. do_action( 'sjb_general_options_end' );
  116. ?>
  117. </div>
  118. </div>
  119. <?php
  120. /**
  121. * Action -> Add new section after general section content .
  122. *
  123. * @since 2.2.0
  124. */
  125. do_action('sjb_general_options_after');
  126. ?>
  127. <input type="hidden" value="1" name="admin_notices">
  128. <input type="submit" name="general_options_submit" id="general-options-form-submit" class="button button-primary" value="<?php echo esc_html__('Save Changes', 'simple-job-board'); ?>">
  129. </form>
  130. </div>
  131. <?php
  132. }
  133. /**
  134. * Save Settings General Section.
  135. *
  136. * This function save the custom post type & taxonomies slugs in WP options.
  137. *
  138. * @since 2.2.3
  139. */
  140. public function sjb_save_settings_section() {
  141. $jobpost_slug = filter_input(INPUT_POST, 'jobpost_slug');
  142. $job_category_slug = filter_input(INPUT_POST, 'job_category_slug');
  143. $job_type_slug = filter_input(INPUT_POST, 'job_type_slug');
  144. $job_location_slug = filter_input(INPUT_POST, 'job_location_slug');
  145. if ( isset( $jobpost_slug ) || isset( $job_category_slug ) || isset( $job_type_slug ) || isset( $job_location_slug ) ) {
  146. // Save Custom Post Type Slug in WP Option
  147. ( !empty( $jobpost_slug ) ) ? update_option( 'job_board_jobpost_slug', $jobpost_slug ) : update_option( 'job_board_jobpost_slug', '' );
  148. // Save Category Taxonomy Slug in WP Option
  149. ( !empty( $job_category_slug ) ) ? update_option( 'job_board_job_category_slug', $job_category_slug ) : update_option( 'job_board_job_category_slug', '' );
  150. // Save Job Type Taxonomy Slug in WP Option
  151. ( !empty( $job_type_slug ) ) ? update_option( 'job_board_job_type_slug', $job_type_slug ) : update_option( 'job_board_job_type_slug', '' );
  152. // Save Job Location Taxonomy Slug in WP Option
  153. (!empty($job_location_slug) ) ? update_option( 'job_board_job_location_slug', $job_location_slug ) : update_option( 'job_board_job_location_slug', '' );
  154. }
  155. }
  156. }