| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Class UIDashboard |
| 10 |
* |
| 11 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 12 |
*/ |
| 13 |
class UISettings extends UIPageForm { |
| 14 |
/** |
| 15 |
* Class constructor. |
| 16 |
* |
| 17 |
* @param TemplateHandler $templateHandler The template handler object used for rendering. |
| 18 |
* @param string $domain The domain for the settings object. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function __construct( TemplateHandler $templateHandler, string $domain ) { |
| 23 |
parent::__construct( $templateHandler, $domain, 'settings', __( 'Settings', 'double-opt-in' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Render the license subpage content |
| 28 |
*/ |
| 29 |
protected function theContent( $slug, $page, $settings ) { |
| 30 |
$deleteOptionItems = array( |
| 31 |
0 => 'never', |
| 32 |
); |
| 33 |
|
| 34 |
for ( $i = 1; $i < 31; $i ++ ) { |
| 35 |
$deleteOptionItems[ $i ] = $i; |
| 36 |
} |
| 37 |
|
| 38 |
$deleteOptionPeriod = array( |
| 39 |
'months' => 'months', |
| 40 |
'days' => 'days', |
| 41 |
'years' => 'years' |
| 42 |
) |
| 43 |
|
| 44 |
?> |
| 45 |
<h2> |
| 46 |
<?php _e( 'Settings', 'double-opt-in' ); ?> |
| 47 |
</h2> |
| 48 |
|
| 49 |
<div class="option"> |
| 50 |
<div class="label"> |
| 51 |
<label for="delete"><?php _e( 'Delete Opt-Ins', 'double-opt-in' ); ?></label> |
| 52 |
</div> |
| 53 |
<div class="input"> |
| 54 |
<select id="delete" name="delete"> |
| 55 |
<?php |
| 56 |
foreach ( $deleteOptionItems as $month => $label ): |
| 57 |
?> |
| 58 |
<option value="<?php esc_attr_e( $month ); ?>" <?php echo $month == $settings['delete'] ? ' selected="selected" ' : ''; ?> > |
| 59 |
<?php _e( $label, 'double-opt-in' ); ?> |
| 60 |
</option> |
| 61 |
<?php endforeach; ?> |
| 62 |
</select> |
| 63 |
|
| 64 |
<select id="delete_period" name="delete_period"> |
| 65 |
<?php |
| 66 |
foreach ( $deleteOptionPeriod as $key => $value ): |
| 67 |
?> |
| 68 |
<option value="<?php esc_attr_e( $key ); ?>" <?php echo $key == $settings['delete_period'] ? ' selected="selected" ' : ''; ?> > |
| 69 |
<?php _e( $value, 'double-opt-in' ); ?> |
| 70 |
</option> |
| 71 |
<?php endforeach; ?> |
| 72 |
</select> |
| 73 |
|
| 74 |
<p> |
| 75 |
<?php _e( 'Select the period of time after which all data will be deleted automatically. As for the european GDPR it is recommend to use the smallest period of time as possible.', 'double-opt-in' ); ?> |
| 76 |
</p> |
| 77 |
</div> |
| 78 |
</div> |
| 79 |
|
| 80 |
<div class="option"> |
| 81 |
<div class="label"> |
| 82 |
<label for="delete_unconfirmed"><?php _e( 'Delete unconfirmed Opt-Ins', 'double-opt-in' ); ?></label> |
| 83 |
</div> |
| 84 |
<div class="input"> |
| 85 |
<select id="delete_unconfirmed" name="delete_unconfirmed"> |
| 86 |
<?php |
| 87 |
foreach ( $deleteOptionItems as $month => $label ): |
| 88 |
?> |
| 89 |
<option value="<?php esc_attr_e( $month ); ?>" <?php echo $month == $settings['delete_unconfirmed'] ? ' selected="selected" ' : ''; ?> > |
| 90 |
<?php _e( $label, 'double-opt-in' ); ?> |
| 91 |
</option> |
| 92 |
<?php endforeach; ?> |
| 93 |
</select> |
| 94 |
|
| 95 |
<select id="delete_unconfirmed_period" name="delete_unconfirmed_period"> |
| 96 |
<?php |
| 97 |
foreach ( $deleteOptionPeriod as $key => $value ): |
| 98 |
?> |
| 99 |
<option value="<?php esc_attr_e( $key ); ?>" <?php echo $key == $settings['delete_unconfirmed_period'] ? ' selected="selected" ' : ''; ?> > |
| 100 |
<?php _e( $value, 'double-opt-in' ); ?> |
| 101 |
</option> |
| 102 |
<?php endforeach; ?> |
| 103 |
</select> |
| 104 |
<p> |
| 105 |
<?php _e( 'Select the period of time after which all unconfirmed data will be deleted automatically. As for the european GDPR it is recommend to use the smallest period of time as possible.', 'double-opt-in' ); ?> |
| 106 |
</p> |
| 107 |
</div> |
| 108 |
</div> |
| 109 |
|
| 110 |
<div class="option"> |
| 111 |
<div class="label"> |
| 112 |
<label for="support"><?php _e( 'Support Forge12 Double Opt-in: ', 'double-opt-in' ); ?></label> |
| 113 |
</div> |
| 114 |
<div class="input"> |
| 115 |
<input type="hidden" class="toggle" name="support" |
| 116 |
value="<?php esc_attr_e( $settings['support'] ); ?>" |
| 117 |
data-before="<?php _e( 'On', 'double-opt-in' ); ?>" |
| 118 |
data-after="<?php _e( 'Off', 'double-opt-in' ); ?>"/> |
| 119 |
|
| 120 |
<p> |
| 121 |
<?php _e( 'The Footer will contain a noscript referral to support Forge12 Double Opt-in.', 'double-opt-in' ); ?> |
| 122 |
</p> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
<?php |
| 126 |
do_action( 'f12_cf7_doubleoptin_ui_settings_render', $settings ); |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Display the sidebar content for the specified page. |
| 131 |
* |
| 132 |
* @param string $slug The slug of the current page. |
| 133 |
* @param string $page The current page. |
| 134 |
* |
| 135 |
* @return void |
| 136 |
*/ |
| 137 |
protected function theSidebar( $slug, $page ) { |
| 138 |
if ( $page != 'settings' ) { |
| 139 |
return; |
| 140 |
} |
| 141 |
?> |
| 142 |
<div class="box"> |
| 143 |
<h2> |
| 144 |
<?php _e( 'Hint:', 'double-opt-in' ); ?> |
| 145 |
</h2> |
| 146 |
<p> |
| 147 |
<?php _e( "In the table on the left side, you'll find an list global settings. They will affect all forms using the double opt-in.", 'double-opt-in' ); ?> |
| 148 |
</p> |
| 149 |
</div> |
| 150 |
<?php |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Retrieves the settings array. |
| 155 |
* |
| 156 |
* @param array $settings The existing settings array. |
| 157 |
* |
| 158 |
* @return array The updated settings array. |
| 159 |
*/ |
| 160 |
public function getSettings( $settings ) { |
| 161 |
$settings = array_merge( $settings, array( |
| 162 |
'support' => 1, |
| 163 |
'delete' => 0, |
| 164 |
'delete_unconfirmed' => 7, |
| 165 |
'delete_period' => 'months', |
| 166 |
'delete_unconfirmed_period' => 'months', |
| 167 |
) |
| 168 |
); |
| 169 |
|
| 170 |
return $settings; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Update the settings based on the POST data. |
| 175 |
* |
| 176 |
* @param array $settings The current settings. |
| 177 |
* |
| 178 |
* @return array The updated settings. |
| 179 |
*/ |
| 180 |
protected function onSave( $settings ) { |
| 181 |
if ( isset( $_POST['delete'] ) ) { |
| 182 |
$settings['delete'] = (int) $_POST['delete']; |
| 183 |
} |
| 184 |
|
| 185 |
if ( isset( $_POST['delete_unconfirmed'] ) ) { |
| 186 |
$settings['delete_unconfirmed'] = (int) $_POST['delete_unconfirmed']; |
| 187 |
} |
| 188 |
|
| 189 |
if ( isset( $_POST['support'] ) ) { |
| 190 |
$settings['support'] = (int) $_POST['support']; |
| 191 |
} else { |
| 192 |
$settings['support'] = 0; |
| 193 |
} |
| 194 |
|
| 195 |
if ( isset( $_POST['delete_period'] ) ) { |
| 196 |
$settings['delete_period'] = sanitize_text_field( $_POST['delete_period'] ); |
| 197 |
} |
| 198 |
|
| 199 |
if ( isset( $_POST['delete_unconfirmed_period'] ) ) { |
| 200 |
$settings['delete_unconfirmed_period'] = sanitize_text_field( $_POST['delete_unconfirmed_period'] ); |
| 201 |
} |
| 202 |
|
| 203 |
return $settings; |
| 204 |
} |
| 205 |
} |
| 206 |
} |