| 1 |
<?php |
| 2 |
|
| 3 |
class EasyOptInsSettings |
| 4 |
{ |
| 5 |
var $settings; |
| 6 |
var $sanitize_done = false; |
| 7 |
|
| 8 |
function __construct($settings) |
| 9 |
{ |
| 10 |
$this->settings = $settings; |
| 11 |
|
| 12 |
add_action('admin_menu', array($this, 'settings_menu')); |
| 13 |
add_action('admin_init', array($this, 'settings_init')); |
| 14 |
} |
| 15 |
|
| 16 |
function settings_content() |
| 17 |
{ |
| 18 |
$this->plugin_options = get_option('easy_opt_in_settings'); |
| 19 |
?> |
| 20 |
|
| 21 |
<div class="dh_easy_opt_in_settings"> |
| 22 |
<?php echo get_screen_icon(); ?> <h2>Settings</h2> |
| 23 |
|
| 24 |
<?php settings_errors('easy_opt_in_settings_group'); ?> |
| 25 |
|
| 26 |
<form method="post" action="options.php"> |
| 27 |
<?php |
| 28 |
settings_fields('easy_opt_in_settings_group'); |
| 29 |
do_settings_sections(basename(__FILE__)); |
| 30 |
|
| 31 |
submit_button(); |
| 32 |
?> |
| 33 |
</form> |
| 34 |
</div> |
| 35 |
<?php |
| 36 |
} |
| 37 |
|
| 38 |
function settings_menu() |
| 39 |
{ |
| 40 |
add_submenu_page('edit.php?post_type=easy-opt-ins', 'Settings', 'Settings', 'manage_options', basename(__FILE__), array($this, 'settings_content')); |
| 41 |
} |
| 42 |
|
| 43 |
function settings_init() |
| 44 |
{ |
| 45 |
|
| 46 |
$provider_id = $this->settings[ 'provider' ]; |
| 47 |
$provider_settings = $this->settings[ 'providers' ][ $provider_id ][ 'settings' ]; |
| 48 |
|
| 49 |
register_setting('easy_opt_in_settings_group', 'easy_opt_in_settings', array($this, 'sanitize')); |
| 50 |
|
| 51 |
add_settings_section('setting_api_settings', 'MailChimp API Settings', false, basename(__FILE__)); |
| 52 |
|
| 53 |
foreach ( $provider_settings as $setting => $params ) { |
| 54 |
$params[ 'provider_id' ] = $provider_id; |
| 55 |
$params[ 'setting' ] = $setting; |
| 56 |
add_settings_field( |
| 57 |
"easy_opt_in_settings[{$provider_id}_{$setting}]" |
| 58 |
, $params[ 'title' ] |
| 59 |
, array( $this, 'provider_setting' ) |
| 60 |
, basename( __FILE__ ) |
| 61 |
, 'setting_api_settings' |
| 62 |
, $params |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public function provider_setting( $args ) { |
| 68 |
|
| 69 |
// !dd( $args, $this->settings ); |
| 70 |
|
| 71 |
echo str_replace( |
| 72 |
array( '{{setting_name}}' ) |
| 73 |
, array( "easy_opt_in_settings[{$args['provider_id']}_{$args['setting']}]" ) |
| 74 |
, $args[ 'html' ] |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
public function callback_api_key() |
| 79 |
{ |
| 80 |
printf( |
| 81 |
'<input type="text" id="api_key" name="easy_opt_in_settings[api_key]" class="large-text" value="%s" />'. |
| 82 |
'<p class="description"><a tabindex="-1" href="http://admin.mailchimp.com/account/api" target="_blank">Where can I find my Campaign Monitor API key?</a></p>', |
| 83 |
esc_attr($this->plugin_options['api_key']) |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
public function callback_double_opt_in() |
| 88 |
{ |
| 89 |
|
| 90 |
$plugin_options = $this->plugin_options; |
| 91 |
|
| 92 |
K::input( 'easy_opt_in_settings[double_opt_in]' |
| 93 |
, array( |
| 94 |
'type' => 'radio', |
| 95 |
'value' => 'true', |
| 96 |
'checked' => K::get_var( 'double_opt_in', $plugin_options ) !== 'false' ? 'checked' : null, |
| 97 |
) |
| 98 |
, array( 'format' => '<div><label>:input Yes</label></div>' ) |
| 99 |
); |
| 100 |
K::input( 'easy_opt_in_settings[double_opt_in]' |
| 101 |
, array( |
| 102 |
'type' => 'radio', |
| 103 |
'value' => 'false', |
| 104 |
'checked' => K::get_var( 'double_opt_in', $plugin_options ) === 'false' ? 'checked' : null, |
| 105 |
) |
| 106 |
, array( 'format' => '<div><label>:input No</label></div>' ) |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
public function sanitize($input) |
| 111 |
{ |
| 112 |
// Update notice |
| 113 |
if( ! $this->sanitize_done ) { |
| 114 |
add_settings_error('easy_opt_in_settings_group', '200', 'Settings saved.', 'updated'); |
| 115 |
$this->sanitize_done = true; |
| 116 |
} |
| 117 |
return $input; |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
?> |
| 123 |
|