| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class ConvertKitSettingsSection |
| 5 |
*/ |
| 6 |
abstract class ConvertKitSettingsSection { |
| 7 |
public $is_registerable = true; |
| 8 |
public $name; |
| 9 |
public $title; |
| 10 |
public $tab_text; |
| 11 |
public $settings_key; |
| 12 |
|
| 13 |
public $api; |
| 14 |
public $options; |
| 15 |
|
| 16 |
/** |
| 17 |
* Constructor |
| 18 |
*/ |
| 19 |
public function __construct() { |
| 20 |
global $convertkit_settings; |
| 21 |
|
| 22 |
$this->api = $convertkit_settings->api; |
| 23 |
$this->options = get_option($this->settings_key); |
| 24 |
if (empty($this->tab_text)) $this->tab_text = $this->title; |
| 25 |
|
| 26 |
$this->register_section(); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Register settings section |
| 31 |
*/ |
| 32 |
public function register_section() { |
| 33 |
if(false == get_option($this->settings_key)) { |
| 34 |
add_option($this->settings_key); |
| 35 |
} |
| 36 |
|
| 37 |
add_settings_section( |
| 38 |
$this->name, // Section name (machine-readable) |
| 39 |
$this->title, // Section title |
| 40 |
array($this, 'print_section_info'), // Info callback |
| 41 |
$this->settings_key // Settings page |
| 42 |
); |
| 43 |
|
| 44 |
$this->register_fields(); |
| 45 |
|
| 46 |
register_setting( |
| 47 |
$this->settings_key, // Page |
| 48 |
$this->settings_key, // Settings DB Key |
| 49 |
array($this, 'sanitize_settings') |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Renders the section |
| 55 |
*/ |
| 56 |
public function render() { |
| 57 |
do_settings_sections( $this->settings_key ); |
| 58 |
settings_fields( $this->settings_key ); |
| 59 |
submit_button(); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Register settings fields |
| 64 |
*/ |
| 65 |
abstract public function register_fields(); |
| 66 |
|
| 67 |
/** |
| 68 |
* Prints help info for this section |
| 69 |
*/ |
| 70 |
abstract public function print_section_info(); |
| 71 |
} |
| 72 |
|