| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit Settings class |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Class ConvertKit_Settings_Base |
| 11 |
*/ |
| 12 |
abstract class ConvertKit_Settings_Base { |
| 13 |
|
| 14 |
/** |
| 15 |
* Setting |
| 16 |
* |
| 17 |
* @var bool |
| 18 |
*/ |
| 19 |
public $is_registerable = true; |
| 20 |
|
| 21 |
/** |
| 22 |
* Section name |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
public $name; |
| 27 |
|
| 28 |
/** |
| 29 |
* Section title |
| 30 |
* |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
public $title; |
| 34 |
|
| 35 |
/** |
| 36 |
* Section tab text |
| 37 |
* |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
public $tab_text; |
| 41 |
|
| 42 |
/** |
| 43 |
* Database key |
| 44 |
* |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
public $settings_key; |
| 48 |
|
| 49 |
/** |
| 50 |
* API instance |
| 51 |
* |
| 52 |
* @var ConvertKit_API |
| 53 |
*/ |
| 54 |
public $api; |
| 55 |
|
| 56 |
/** |
| 57 |
* Options array |
| 58 |
* |
| 59 |
* @var mixed|void |
| 60 |
*/ |
| 61 |
public $options; |
| 62 |
|
| 63 |
/** |
| 64 |
* If false, we will hide the submit button. |
| 65 |
* |
| 66 |
* @var bool |
| 67 |
*/ |
| 68 |
protected $show_submit = true; |
| 69 |
|
| 70 |
/** |
| 71 |
* Constructor |
| 72 |
*/ |
| 73 |
public function __construct() { |
| 74 |
global $convertkit_settings; |
| 75 |
|
| 76 |
$this->api = $convertkit_settings->api; |
| 77 |
$this->options = get_option( $this->settings_key ); |
| 78 |
if ( empty( $this->tab_text ) ) { |
| 79 |
$this->tab_text = $this->title; |
| 80 |
} |
| 81 |
|
| 82 |
$this->register_section(); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Register settings section |
| 87 |
*/ |
| 88 |
public function register_section() { |
| 89 |
if ( false === get_option( $this->settings_key ) ) { |
| 90 |
add_option( $this->settings_key ); |
| 91 |
} |
| 92 |
|
| 93 |
add_settings_section( |
| 94 |
$this->name, |
| 95 |
$this->title, |
| 96 |
array( $this, 'print_section_info' ), |
| 97 |
$this->settings_key |
| 98 |
); |
| 99 |
|
| 100 |
$this->register_fields(); |
| 101 |
|
| 102 |
register_setting( |
| 103 |
$this->settings_key, |
| 104 |
$this->settings_key, |
| 105 |
array( $this, 'sanitize_settings' ) |
| 106 |
); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Renders the section |
| 111 |
*/ |
| 112 |
public function render() { |
| 113 |
do_settings_sections( $this->settings_key ); |
| 114 |
settings_fields( $this->settings_key ); |
| 115 |
if ( $this->show_submit ) { |
| 116 |
submit_button(); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Register settings fields |
| 122 |
*/ |
| 123 |
abstract public function register_fields(); |
| 124 |
|
| 125 |
/** |
| 126 |
* Prints help info for this section |
| 127 |
*/ |
| 128 |
abstract public function print_section_info(); |
| 129 |
} |
| 130 |
|