| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if (!defined('ABSPATH')) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
abstract class UIPageForm extends UIPage |
| 9 |
{ |
| 10 |
/** |
| 11 |
* define if the button for the submit should be displayed or not. |
| 12 |
* if hidden, the wp_nonce will also be removed. Ensure you handle |
| 13 |
* the save process on your own. The onSave function will still be called |
| 14 |
* |
| 15 |
* @var bool |
| 16 |
*/ |
| 17 |
private $hide_submit_button = false; |
| 18 |
|
| 19 |
/** |
| 20 |
* @return mixed |
| 21 |
*/ |
| 22 |
protected function maybeSave() |
| 23 |
{ |
| 24 |
if (isset($_POST['doi_settings_nonce']) && wp_verify_nonce($_POST['doi_settings_nonce'], 'doi_settings_action')) { |
| 25 |
$settings = CF7DoubleOptIn::getInstance()->getSettings(); |
| 26 |
|
| 27 |
$settings = apply_filters('f12_cf7_doubleoptin_ui_' . $this->slug . '_before_on_save', $settings); |
| 28 |
|
| 29 |
$settings = $this->onSave($settings); |
| 30 |
|
| 31 |
$settings = apply_filters('f12_cf7_doubleoptin_ui_' . $this->slug . '_after_on_save', $settings); |
| 32 |
|
| 33 |
update_option('f12-doi-settings', $settings); |
| 34 |
|
| 35 |
Messages::getInstance()->add(__('Settings updated', 'double-opt-in'), 'success'); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Option to hide the submit button |
| 41 |
* |
| 42 |
* @param bool $hide |
| 43 |
* |
| 44 |
* @return void |
| 45 |
*/ |
| 46 |
protected function hideSubmitButton($hide) |
| 47 |
{ |
| 48 |
$this->hide_submit_button = $hide; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns true if the button should be hidden. |
| 53 |
* |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
protected function isSubmitButtonHidden() |
| 57 |
{ |
| 58 |
return $this->hide_submit_button; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Update the settings and return them |
| 63 |
* |
| 64 |
* @param $settings |
| 65 |
* |
| 66 |
* @return array |
| 67 |
*/ |
| 68 |
protected abstract function onSave($settings); |
| 69 |
|
| 70 |
/** |
| 71 |
* @return void |
| 72 |
* @private WordPress HOOK |
| 73 |
*/ |
| 74 |
public function renderContent($slug, $page) |
| 75 |
{ |
| 76 |
if ($this->slug != $page) { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
$this->maybeSave(); |
| 81 |
|
| 82 |
$settings = CF7DoubleOptIn::getInstance()->getSettings(); |
| 83 |
|
| 84 |
echo esc_html(Messages::getInstance()->getAll()); |
| 85 |
?> |
| 86 |
<div class="box"> |
| 87 |
<form action="" method="post"> |
| 88 |
<?php |
| 89 |
do_action('f12_cf7_doubleoptin_ui_' . $page . '_before_content', $settings); |
| 90 |
$this->theContent($slug, $page, $settings); |
| 91 |
do_action('f12_cf7_doubleoptin_ui_' . $page . '_after_content', $settings); |
| 92 |
|
| 93 |
|
| 94 |
if (!$this->isSubmitButtonHidden()): |
| 95 |
wp_nonce_field('doi_settings_action', 'doi_settings_nonce'); |
| 96 |
?> |
| 97 |
<input type="submit" name="doubleoptin-settings-submit" class="button" |
| 98 |
value=" <?php _e('Save', 'double-opt-in'); ?>"/> |
| 99 |
<?php endif; ?> |
| 100 |
</form> |
| 101 |
</div> |
| 102 |
<?php |
| 103 |
} |
| 104 |
} |
| 105 |
} |