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.7 0.2 0.2.1 0.2.2 0.2.3
cf7-conditional-fields / wpcf7cf-options.php
cf7-conditional-fields Last commit date
js 2 years ago jsdoc-out 2 years ago Wpcf7cfMailParser.php 4 years ago admin-style.css 2 years ago admin-style.css.map 2 years ago admin-style.scss 4 years ago admin.php 2 years ago cf7cf.php 2 years ago contact-form-7-conditional-fields.php 2 years ago init.php 2 years ago readme.txt 2 years ago style.css 3 years ago tg_pane_group.php 5 years ago wpcf7cf-options.php 2 years ago
wpcf7cf-options.php
314 lines
1 <?php
2
3 define('WPCF7CF_SLUG', 'wpcf7cf');
4 define('WPCF7CF_OPTIONS', WPCF7CF_SLUG.'_options');
5 define('WPCF7CF_TEXT_DOMAIN', WPCF7CF_SLUG.'_text_domain');
6
7 define('WPCF7CF_DEFAULT_ANIMATION', 'yes');
8 define('WPCF7CF_DEFAULT_ANIMATION_INTIME', 200);
9 define('WPCF7CF_DEFAULT_ANIMATION_OUTTIME', 200);
10 define('WPCF7CF_DEFAULT_CONDITIONS_UI', 'normal');
11 define('WPCF7CF_DEFAULT_NOTICE_DISMISSED', false);
12
13 if ( ! defined( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY' ) ) {
14 define( 'WPCF7_ADMIN_READ_WRITE_CAPABILITY', 'publish_pages' );
15 }
16
17 global $wpcf7cf_default_settings_glob;
18 $wpcf7cf_default_settings_glob = false;
19 function wpcf7cf_get_default_settings() {
20 global $wpcf7cf_default_settings_glob;
21 if ($wpcf7cf_default_settings_glob) return $wpcf7cf_default_settings_glob;
22
23 $wpcf7cf_default_settings_glob = array(
24 'animation' => WPCF7CF_DEFAULT_ANIMATION,
25 'animation_intime' => WPCF7CF_DEFAULT_ANIMATION_INTIME,
26 'animation_outtime' => WPCF7CF_DEFAULT_ANIMATION_OUTTIME,
27 'conditions_ui' => WPCF7CF_DEFAULT_CONDITIONS_UI,
28 'notice_dismissed' => WPCF7CF_DEFAULT_NOTICE_DISMISSED
29 );
30 $wpcf7cf_default_settings_glob = apply_filters('wpcf7cf_default_options', $wpcf7cf_default_settings_glob);
31 return $wpcf7cf_default_settings_glob;
32 }
33
34 global $wpcf7cf_settings_glob;
35 $wpcf7cf_settings_glob = false;
36 function wpcf7cf_get_settings() {
37 global $wpcf7cf_settings_glob;
38 if ($wpcf7cf_settings_glob) {
39 return $wpcf7cf_settings_glob;
40 }
41
42 $wpcf7cf_default_settings = wpcf7cf_get_default_settings();
43 $wpcf7cf_saved_settings = get_option(WPCF7CF_OPTIONS);
44
45 if (!$wpcf7cf_saved_settings) {
46 $wpcf7cf_saved_settings = [];
47 }
48
49 $wpcf7cf_settings_glob = array_merge($wpcf7cf_default_settings,$wpcf7cf_saved_settings);
50
51 return $wpcf7cf_settings_glob;
52 }
53
54 function wpcf7cf_get_dismiss_notice_nonce() {
55 // We use the same nonce for all admin notices, because we don't care about users trying to hack themselves.
56 // This nonce is only intended to prevent CSRF attacks.
57 static $nonce = false;
58 if (!$nonce) {
59 $nonce = wp_create_nonce( 'wpcf7cf_dismiss_notice' );
60 }
61 return $nonce;
62 }
63
64 function wpcf7cf_set_options($settings) {
65 global $wpcf7cf_settings_glob;
66 $wpcf7cf_settings_glob = $settings;
67 update_option(WPCF7CF_OPTIONS, $wpcf7cf_settings_glob);
68 }
69
70 function wpcf7cf_reset_options() {
71 delete_option(WPCF7CF_OPTIONS);
72 }
73
74 add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
75 function wpcf7cf_load_page_options_wp_admin_style() {
76 wp_register_style( 'wpcf7cf_admin_css', plugins_url('admin-style.css',__FILE__), [], WPCF7CF_VERSION );
77 wp_enqueue_style( 'wpcf7cf_admin_css' );
78 }
79
80
81 add_action('admin_menu', 'wpcf7cf_admin_add_page');
82 function wpcf7cf_admin_add_page() {
83 add_submenu_page('wpcf7', __( 'Conditional Fields', 'cf7-conditional-fields' ), __( 'Conditional Fields', 'cf7-conditional-fields' ), WPCF7_ADMIN_READ_WRITE_CAPABILITY, 'wpcf7cf', 'wpcf7cf_options_page' );
84 }
85
86 function wpcf7cf_options_page() {
87 $settings = wpcf7cf_get_settings();
88
89 if (isset($_POST['reset'])) {
90 echo '<div id="message" class="updated fade"><p><strong>' . __( 'Settings restored to defaults', 'cf7-conditional-fields' ) . '</strong></p></div>';
91 } else if (isset($_REQUEST['settings-updated'])) {
92 echo '<div id="message" class="updated fade"><p><strong>' . __( 'Settings updated', 'cf7-conditional-fields' ) . '</strong></p></div>';
93 }
94
95 ?>
96
97 <div class="wrap wpcf7cf-admin-wrap">
98 <h2><?php _e( 'Conditional Fields for Contact Form 7 Settings', 'cf7-conditional-fields'); ?></h2>
99 <?php if (!$settings['notice_dismissed']) { ?>
100 <div class="wpcf7cf-admin-notice notice notice-warning is-dismissible" data-notice-id="" data-nonce="<?php echo wpcf7cf_get_dismiss_notice_nonce() ?>">
101 <div style="padding: 10px 0;">
102 <?php _e( '<strong>Notice</strong>: These are global settings for Conditional Fields for Contact Form 7.', 'cf7-conditional-fields'); ?>
103 <br><br>
104 <strong><?php _e( 'How to create/edit conditional fields?', 'cf7-conditional-fields'); ?></strong>
105 <ol>
106 <li><?php _e( 'Create a new Contact Form or edit an existing one', 'cf7-conditional-fields'); ?></li>
107 <li><?php _e( 'Create at least one [group] inside the form', 'cf7-conditional-fields'); ?></li>
108 <li><?php _e( 'Save the Contact Form', 'cf7-conditional-fields'); ?></li>
109 <li><?php _e( 'Go to the <strong><em>Conditional Fields</em></strong> Tab', 'cf7-conditional-fields'); ?></li>
110 </ol>
111 <a href="https://conditional-fields-cf7.bdwm.be/conditional-fields-for-contact-form-7-tutorial/" target="_blank"><?php _e( 'Show me an example', 'cf7-conditional-fields'); ?></a> | <a class="notice-dismiss-alt" href="#"><?php _e( 'Dismiss notice', 'cf7-conditional-fields'); ?></a>
112 </div>
113 </div>
114 <?php } ?>
115 <form action="options.php" method="post">
116 <?php settings_fields(WPCF7CF_OPTIONS); ?>
117
118 <input type="hidden" name="<?php echo WPCF7CF_OPTIONS.'[notice_dismissed]' ?>" value="<?php echo $settings['notice_dismissed'] ?>" />
119
120 <?php
121
122 echo '<h3>' . __( 'Default animation Settings', 'cf7-conditional-fields') . '</h3>';
123 wpcf7cf_input_fields_wrapper_start();
124
125 wpcf7cf_input_select('animation', array(
126 'label' => __( 'Animation', 'cf7-conditional-fields'),
127 'description' => __( 'Use animations while showing/hiding groups', 'cf7-conditional-fields'),
128 'select_options' => array('yes' => __( 'Enabled', 'cf7-conditional-fields'), 'no'=> __( 'Disabled', 'cf7-conditional-fields'))
129 ));
130
131 wpcf7cf_input_field('animation_intime', array(
132 'label' => __( 'Animation In time', 'cf7-conditional-fields'),
133 'description' => __( 'A positive integer value indicating the time, in milliseconds, it will take for each group to show.', 'cf7-conditional-fields'),
134 ));
135
136 wpcf7cf_input_field('animation_outtime', array(
137 'label' => __( 'Animation Out Time', 'cf7-conditional-fields'),
138 'description' => __( 'A positive integer value indicating the time, in milliseconds, it will take for each group to hide.', 'cf7-conditional-fields'),
139 ));
140
141 wpcf7cf_input_fields_wrapper_end();
142 submit_button();
143
144 if (!WPCF7CF_IS_PRO) {
145 ?>
146 <h3><?php _e( 'Conditional Fields PRO', 'cf7-conditional-fields'); ?></h3>
147 <?php _e( 'Get Conditional Fields PRO to unlock the full potential of CF7', 'cf7-conditional-fields'); ?>
148 <ul class="wpcf7cf-list">
149 <li><?php _e( 'Repeaters', 'cf7-conditional-fields'); ?></li>
150 <li><?php _e( 'Regular expressions', 'cf7-conditional-fields'); ?></li>
151 <li><?php _e( 'Toggle buttons', 'cf7-conditional-fields'); ?></li>
152 <li><?php _e( 'Additional operators', 'cf7-conditional-fields'); ?>< <code>&lt;</code> <code>&gt;</code> <code>&le;</code> <code>&ge;</code> <code><?php _e( 'is empty', 'cf7-conditional-fields'); ?></code></li>
153 <li><?php _e( 'Multistep (with Summary)', 'cf7-conditional-fields'); ?></li>
154 <li><?php _e( 'More comming soon (Calculated Fields, ...)', 'cf7-conditional-fields'); ?></li>
155 </ul>
156 <p><a target="_blank" class="button button-primary" href="https://conditional-fields-cf7.bdwm.be/contact-form-7-conditional-fields-pro/"><?php _e( 'Get PRO', 'cf7-conditional-fields'); ?></a></p>
157 <?php
158 }
159 do_action('wpcf7cf_after_animation_settings');
160
161 echo '<h3>' . __( 'Advanced Settings', 'cf7-conditional-fields') . '</h3>';
162 wpcf7cf_input_fields_wrapper_start();
163
164 wpcf7cf_input_select('conditions_ui', array(
165 'label' => __( 'Conditional Fields UI', 'cf7-conditional-fields'),
166 'description' => sprintf(
167 // translators: max recommended conditions
168 __( 'If you want to add more than %s conditions, it\'s recommended to switch to <strong>Text mode</strong> mode for better performance.', 'cf7-conditional-fields' ), WPCF7CF_MAX_RECOMMENDED_CONDITIONS ),
169 'select_options' => array('normal'=> __( 'Normal', 'cf7-conditional-fields'), 'text_only' => __( 'Text mode', 'cf7-conditional-fields'))
170 ));
171
172 wpcf7cf_input_fields_wrapper_end();
173
174 submit_button();
175
176 ?>
177
178 </form></div>
179
180 <h3><?php _e( 'Restore Default Settings', 'cf7-conditional-fields' ); ?></h3>
181 <form method="post" id="reset-form" action="">
182 <p class="submit">
183 <input name="reset" class="button button-secondary" type="submit" value="<?php _e( 'Restore defaults', 'cf7-conditional-fields' ); ?>" >
184 <input type="hidden" name="action" value="reset" />
185 </p>
186 </form>
187 <script>
188 (function($){
189 $('#reset-form').submit(function() {
190 return confirm( __( 'Are you sure you want to reset the plugin settings to the default values? All changes you have previously made will be lost.', 'cf7-conditional-fields' ) );
191 });
192 }(jQuery))
193 </script>
194
195 <?php
196 }
197
198 function wpcf7cf_input_fields_wrapper_start() {
199 echo '<table class="form-table" role="presentation"><tbody>';
200 }
201 function wpcf7cf_input_fields_wrapper_end() {
202 echo '</tbody></table>';
203 }
204
205 function wpcf7cf_input_field($slug, $args) {
206 $settings = wpcf7cf_get_settings();
207
208 $defaults = array(
209 'label'=>'',
210 'desription' => '',
211 'default' => wpcf7cf_get_default_settings()[$slug],
212 'label_editable' => false
213 );
214
215 $args = wp_parse_args( $args, $defaults );
216 extract($args);
217
218 $label; $description; $default; $label_editable;
219
220 if (!key_exists($slug, $settings)) {
221 $settings[$slug] = $default;
222 $settings[$slug.'_label'] = $label;
223 }
224
225 ?>
226
227 <tr>
228 <th scope="row">
229
230 <?php if ($label_editable) { ?>
231 <span class="label editable"><input type="text" data-default-value="<?php echo $label ?>" value="<?php echo $settings[$slug.'_label'] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug.'_label' ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.'_label]' ?>"></span>
232 <?php } else { ?>
233 <label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label>
234 <?php } ?>
235
236 </th>
237 <td>
238 <input type="text" data-default-value="<?php echo $default ?>" value="<?php echo $settings[$slug] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
239 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
240 <?php echo $description ?><?php if (!empty($default)) echo ' (' . __( 'Default:', 'cf7-conditional-fields' ) . ' '.$default.')' ?>
241 </p>
242 </td>
243 </tr>
244
245 <?php
246
247 }
248
249 function wpcf7cf_input_select($slug, $args) {
250 $settings = wpcf7cf_get_settings();
251
252 $defaults = array(
253 'label'=>'',
254 'desription' => '',
255 'select_options' => array(), // array($name => $value)
256 'default' => wpcf7cf_get_default_settings()[$slug],
257 );
258
259 $args = wp_parse_args( $args, $defaults );
260 extract($args);
261
262 $label; $description; $select_options; $default;
263
264 if (!key_exists($slug, $settings)) {
265 $settings[$slug] = $default;
266 }
267
268 ?>
269 <tr>
270 <th scope="row"><label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label></th>
271 <td>
272 <select id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
273 <?php foreach($select_options as $value => $text) { ?>
274 <option value="<?php echo $value ?>" <?php echo $settings[$slug]==$value?'selected':'' ?>><?php echo $text ?></option>
275 <?php } ?>
276 </select>
277 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
278 <?php echo $description ?><?php if (!empty($default)) echo ' (' . __( 'Default:', 'cf7-conditional-fields' ) . ' '.$select_options[$default].')' ?>
279 </p>
280 </td>
281 </tr>
282 <?php
283 }
284
285 add_action('admin_init', 'wpcf7cf_admin_init');
286 function wpcf7cf_admin_init(){
287
288 if(isset($_POST['reset']) && current_user_can( 'wpcf7_edit_contact_forms' ) ) {
289 wpcf7cf_reset_options();
290 }
291
292 register_setting( WPCF7CF_OPTIONS, WPCF7CF_OPTIONS, 'wpcf7cf_options_sanitize' );
293 }
294
295 function wpcf7cf_options_sanitize($input) {
296 return $input;
297 }
298
299 add_action( 'wp_ajax_wpcf7cf_dismiss_notice', 'wpcf7cf_dismiss_notice' );
300 function wpcf7cf_dismiss_notice() {
301
302 // check nonce
303 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'wpcf7cf_dismiss_notice' ) ) {
304 wp_send_json_error( array( 'message' => __( 'Nonce verification failed', 'cf7-conditional-fields' ) ) );
305 }
306
307 $notice_id = sanitize_text_field($_POST['noticeId'] ?? '');
308 $notice_suffix = $notice_id ? '_'.$notice_id : $notice_id;
309
310 $settings = wpcf7cf_get_settings();
311 $settings['notice_dismissed'.$notice_suffix] = true;
312 wpcf7cf_set_options($settings);
313 }
314