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