class-simple-job-board-settings-job-features.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php if (!defined('ABSPATH')) { exit; } // Exit if accessed directly
  2. /**
  3. * Simple_Job_Board_Settings_Job_Features Class
  4. *
  5. * This file used to define the settings for the job features. User can create
  6. * generic job features that will add to the newly created job.
  7. *
  8. * @link https://wordpress.org/plugins/simple-job-board
  9. * @since 2.2.3
  10. * @since 2.3.2 Added Application Form Labels' Editing Feature
  11. * @since 2.4.0 Revised Inputs & Outputs Sanitization & Escaping
  12. * @since 2.5.0 Added before & after action hooks for the job features section.
  13. *
  14. * @package Simple_Job_Board
  15. * @subpackage Simple_Job_Board/admin/settings
  16. * @author PressTigers <support@presstigers.com>
  17. */
  18. class Simple_Job_Board_Settings_Job_Features {
  19. /**
  20. * Initialize the class and set its properties.
  21. *
  22. * @since 2.2.3
  23. */
  24. public function __construct() {
  25. // Filter -> Add Settings Job Features Tab
  26. add_filter('sjb_settings_tab_menus', array($this, 'sjb_add_settings_tab'), 40);
  27. // Action -> Add Settings Job Features Section
  28. add_action('sjb_settings_tab_section', array($this, 'sjb_add_settings_section'), 40);
  29. // Action -> Save Settings Job Features Section
  30. add_action('sjb_save_setting_sections', array($this, 'sjb_save_settings_section'));
  31. }
  32. /**
  33. * Add Settings Job Features Tab.
  34. *
  35. * @since 2.2.3
  36. *
  37. * @param array $tabs Settings Tab
  38. * @return array $tabs Merge array of Settings Tab with Job Features Tab.
  39. */
  40. public function sjb_add_settings_tab($tabs) {
  41. $tabs['job_features'] = esc_html__('Job Features', 'simple-job-board');
  42. return $tabs;
  43. }
  44. /**
  45. * Add Settings Job Features section.
  46. *
  47. * @since 2.2.3
  48. */
  49. public function sjb_add_settings_section() {
  50. ?>
  51. <!-- Job Features -->
  52. <div id="settings-job_features" class="sjb-admin-settings" style="display: none;">
  53. <h4 class="first"><?php esc_html_e('Default Feature List', 'simple-job-board'); ?></h4>
  54. <div class="sjb-section settings-fields">
  55. <?php
  56. /**
  57. * Action -> Add new section before job feature section.
  58. *
  59. * @since 2.5.0
  60. */
  61. do_action('sjb_jobfeature_before');
  62. ?>
  63. <form method="post" action="" id="job_feature_form">
  64. <ul id="settings_job_features">
  65. <?php
  66. // Get Job Features From DB
  67. $job_features = get_option('jobfeature_settings_options');
  68. $fields = unserialize($job_features);
  69. // Display Job Features
  70. if (NULL != $fields):
  71. foreach ($fields as $field => $val) {
  72. if ('jobfeature_' == substr($field, 0, 11)) {
  73. // Escaping all array value
  74. $val = ( is_array($val) ) ? array_map('esc_attr', $val) : esc_attr($val);
  75. $field = preg_replace('/[^\p{L} 0-9]/u', '_', $field);
  76. /**
  77. * New Label Index Insertion:
  78. *
  79. * - Addition of new index "label"
  80. * - Data Legacy Checking
  81. */
  82. $label = isset($val['label']) ? $val['label'] : esc_html__(ucwords(str_replace('_', ' ', substr($field, 11))), 'simple-job-board');
  83. $value = isset($val['value']) ? $val['value'] : $val;
  84. $feature_value = ( 'empty' === $value ) ? '<input type="text" value=" " name="' . $field . '[value]" />' : '<input type="text" value="' . $value . '" name="' . $field . '[value]" />';
  85. echo '<li class="' . $field . '"><strong>' . esc_html__('Field Name', 'simple-job-board') . ': </strong><label class="sjb-editable-label" for="' . $field . '">' . $label . '</label><input type="hidden" name="' . $field . '[label]" value="' . $label . '" >' . $feature_value . ' &nbsp; <div class="button removeField">' . esc_html__('Delete', 'simple-job-board') . '</div></li>';
  86. }
  87. }
  88. endif;
  89. ?>
  90. </ul>
  91. <input type="hidden" name="job_features" value="job_features" />
  92. <input type="hidden" value="1" name="admin_notices" />
  93. </form>
  94. </div>
  95. <!-- Add Job Features -->
  96. <h4><?php _e('Add New Feature', 'simple-job-board'); ?></h4>
  97. <div class="sjb-section">
  98. <div class="sjb-content-featured">
  99. <div class="sjb-form-group">
  100. <label class="sjb-featured-label"><?php esc_html_e('Feature', 'simple-job-board'); ?></label>
  101. <input type="text" id="settings_jobfeature_name" />
  102. </div>
  103. <div class="sjb-form-group">
  104. <label class="sjb-featured-label"><?php esc_html_e('Value', 'simple-job-board'); ?></label>
  105. <input type="text" id="settings_jobfeature_value" />
  106. </div>
  107. <input type="submit" class="button" id="settings_addFeature" value="<?php echo esc_html__('Add Field', 'simple-job-board'); ?>" />
  108. </div>
  109. </div>
  110. <?php
  111. /**
  112. * Action -> Add new section after job feature section.
  113. *
  114. * @since 2.5.0
  115. */
  116. do_action('sjb_jobfeature_after');
  117. ?>
  118. <input type="submit" name="jobfeature_submit" id="jobfeature_form" class="button button-primary" value="<?php echo esc_html__('Save Changes', 'simple-job-board'); ?>" />
  119. </div>
  120. <?php
  121. }
  122. /**
  123. * Save Settings Job Features Section.
  124. *
  125. * This function is used to save the generic job features. All these
  126. * features are displayed on creation of new job.
  127. *
  128. * @since 2.2.3
  129. */
  130. public function sjb_save_settings_section() {
  131. $POST_data = filter_input_array(INPUT_POST);
  132. $features = filter_input(INPUT_POST, 'job_features');
  133. // Save Form Data to WP Option
  134. if (!empty($POST_data) && ( $features )) {
  135. $job_features = serialize($POST_data);
  136. // Save Job Features in WP Options || Add Option if not exist.
  137. (FALSE !== get_option('jobfeature_settings_options')) ?
  138. update_option('jobfeature_settings_options', $job_features) :
  139. add_option('jobfeature_settings_options', $job_features, '', 'no');
  140. }
  141. }
  142. }