class-evf-settings-email.php
3 years ago
class-evf-settings-general.php
5 years ago
class-evf-settings-integrations.php
6 years ago
class-evf-settings-misc.php
2 years ago
class-evf-settings-page.php
7 years ago
class-evf-settings-recaptcha.php
2 years ago
class-evf-settings-validation.php
6 years ago
class-evf-settings-page.php
139 lines
| 1 | <?php |
| 2 | /** |
| 3 | * EverestForms Settings Page/Tab |
| 4 | * |
| 5 | * @package EverestForms\Admin |
| 6 | * @version 1.0.0 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | if ( ! class_exists( 'EVF_Settings_Page', false ) ) : |
| 12 | |
| 13 | /** |
| 14 | * EVF_Settings_Page. |
| 15 | */ |
| 16 | abstract class EVF_Settings_Page { |
| 17 | |
| 18 | /** |
| 19 | * Setting page id. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $id = ''; |
| 24 | |
| 25 | /** |
| 26 | * Setting page label. |
| 27 | * |
| 28 | * @var string |
| 29 | */ |
| 30 | protected $label = ''; |
| 31 | |
| 32 | /** |
| 33 | * Constructor. |
| 34 | */ |
| 35 | public function __construct() { |
| 36 | add_filter( 'everest_forms_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
| 37 | add_action( 'everest_forms_sections_' . $this->id, array( $this, 'output_sections' ) ); |
| 38 | add_action( 'everest_forms_settings_' . $this->id, array( $this, 'output' ) ); |
| 39 | add_action( 'everest_forms_settings_save_' . $this->id, array( $this, 'save' ) ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get settings page ID. |
| 44 | * |
| 45 | * @since 1.2.0 |
| 46 | * @return string |
| 47 | */ |
| 48 | public function get_id() { |
| 49 | return $this->id; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get settings page label. |
| 54 | * |
| 55 | * @since 1.2.0 |
| 56 | * @return string |
| 57 | */ |
| 58 | public function get_label() { |
| 59 | return $this->label; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Add this page to settings. |
| 64 | * |
| 65 | * @param array $pages Setting pages. |
| 66 | * @return mixed |
| 67 | */ |
| 68 | public function add_settings_page( $pages ) { |
| 69 | $pages[ $this->id ] = $this->label; |
| 70 | |
| 71 | return $pages; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Get settings array. |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | public function get_settings() { |
| 80 | return apply_filters( 'everest_forms_get_settings_' . $this->id, array() ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get sections. |
| 85 | * |
| 86 | * @return array |
| 87 | */ |
| 88 | public function get_sections() { |
| 89 | return apply_filters( 'everest_forms_get_sections_' . $this->id, array() ); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Output sections. |
| 94 | */ |
| 95 | public function output_sections() { |
| 96 | global $current_section; |
| 97 | |
| 98 | $sections = $this->get_sections(); |
| 99 | |
| 100 | if ( empty( $sections ) || 1 === count( $sections ) ) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | echo '<ul class="subsubsub">'; |
| 105 | |
| 106 | $array_keys = array_keys( $sections ); |
| 107 | |
| 108 | foreach ( $sections as $id => $label ) { |
| 109 | echo '<li><a href="' . esc_url( admin_url( 'admin.php?page=evf-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) ) . '" class="' . ( $current_section === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a> ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' </li>'; |
| 110 | } |
| 111 | echo '</ul><br class="clear" />'; |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Output the settings. |
| 116 | */ |
| 117 | public function output() { |
| 118 | $settings = $this->get_settings(); |
| 119 | |
| 120 | EVF_Admin_Settings::output_fields( $settings ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Save settings. |
| 125 | */ |
| 126 | public function save() { |
| 127 | global $current_section; |
| 128 | |
| 129 | $settings = $this->get_settings(); |
| 130 | EVF_Admin_Settings::save_fields( $settings ); |
| 131 | |
| 132 | if ( $current_section ) { |
| 133 | do_action( 'everest_forms_update_options_' . $this->id . '_' . $current_section ); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | endif; |
| 139 |