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