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.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 3 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 4 years ago
wpcf7cf-options.php
298 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_set_options($settings) {
55 global $wpcf7cf_settings_glob;
56 $wpcf7cf_settings_glob = $settings;
57 update_option(WPCF7CF_OPTIONS, $wpcf7cf_settings_glob);
58 }
59
60 function wpcf7cf_reset_options() {
61 delete_option(WPCF7CF_OPTIONS);
62 }
63
64 add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
65 function wpcf7cf_load_page_options_wp_admin_style() {
66 wp_register_style( 'wpcf7cf_admin_css', plugins_url('admin-style.css',__FILE__), [], WPCF7CF_VERSION );
67 wp_enqueue_style( 'wpcf7cf_admin_css' );
68 }
69
70
71 add_action('admin_menu', 'wpcf7cf_admin_add_page');
72 function wpcf7cf_admin_add_page() {
73 add_submenu_page('wpcf7', __( 'Conditional Fields', 'cf7-conditional-fields' ), __( 'Conditional Fields', 'cf7-conditional-fields' ), WPCF7_ADMIN_READ_WRITE_CAPABILITY, 'wpcf7cf', 'wpcf7cf_options_page' );
74 }
75
76 function wpcf7cf_options_page() {
77 $settings = wpcf7cf_get_settings();
78
79 if (isset($_POST['reset'])) {
80 echo '<div id="message" class="updated fade"><p><strong>' . __( 'Settings restored to defaults', 'cf7-conditional-fields' ) . '</strong></p></div>';
81 } else if (isset($_REQUEST['settings-updated'])) {
82 echo '<div id="message" class="updated fade"><p><strong>' . __( 'Settings updated', 'cf7-conditional-fields' ) . '</strong></p></div>';
83 }
84
85 ?>
86
87 <div class="wrap wpcf7cf-admin-wrap">
88 <h2><?php _e( 'Conditional Fields for Contact Form 7 Settings', 'cf7-conditional-fields'); ?></h2>
89 <?php if (!$settings['notice_dismissed']) { ?>
90 <div class="wpcf7cf-admin-notice notice notice-warning is-dismissible" data-notice-id="">
91 <div style="padding: 10px 0;">
92 <?php _e( '<strong>Notice</strong>: These are global settings for Conditional Fields for Contact Form 7.', 'cf7-conditional-fields'); ?>
93 <br><br>
94 <strong><?php _e( 'How to create/edit conditional fields?', 'cf7-conditional-fields'); ?></strong>
95 <ol>
96 <li><?php _e( 'Create a new Contact Form or edit an existing one', 'cf7-conditional-fields'); ?></li>
97 <li><?php _e( 'Create at least one [group] inside the form', 'cf7-conditional-fields'); ?></li>
98 <li><?php _e( 'Save the Contact Form', 'cf7-conditional-fields'); ?></li>
99 <li><?php _e( 'Go to the <strong><em>Conditional Fields</em></strong> Tab', 'cf7-conditional-fields'); ?></li>
100 </ol>
101 <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>
102 </div>
103 </div>
104 <?php } ?>
105 <form action="options.php" method="post">
106 <?php settings_fields(WPCF7CF_OPTIONS); ?>
107
108 <input type="hidden" name="<?php echo WPCF7CF_OPTIONS.'[notice_dismissed]' ?>" value="<?php echo $settings['notice_dismissed'] ?>" />
109
110 <?php
111
112 echo '<h3>' . __( 'Default animation Settings', 'cf7-conditional-fields') . '</h3>';
113 wpcf7cf_input_fields_wrapper_start();
114
115 wpcf7cf_input_select('animation', array(
116 'label' => __( 'Animation', 'cf7-conditional-fields'),
117 'description' => __( 'Use animations while showing/hiding groups', 'cf7-conditional-fields'),
118 'select_options' => array('yes' => __( 'Enabled', 'cf7-conditional-fields'), 'no'=> __( 'Disabled', 'cf7-conditional-fields'))
119 ));
120
121 wpcf7cf_input_field('animation_intime', array(
122 'label' => __( 'Animation In time', 'cf7-conditional-fields'),
123 'description' => __( 'A positive integer value indicating the time, in milliseconds, it will take for each group to show.', 'cf7-conditional-fields'),
124 ));
125
126 wpcf7cf_input_field('animation_outtime', array(
127 'label' => __( 'Animation Out Time', 'cf7-conditional-fields'),
128 'description' => __( 'A positive integer value indicating the time, in milliseconds, it will take for each group to hide.', 'cf7-conditional-fields'),
129 ));
130
131 wpcf7cf_input_fields_wrapper_end();
132 submit_button();
133
134 if (!WPCF7CF_IS_PRO) {
135 ?>
136 <h3><?php _e( 'Conditional Fields PRO', 'cf7-conditional-fields'); ?></h3>
137 <?php _e( 'Get Conditional Fields PRO to unlock the full potential of CF7', 'cf7-conditional-fields'); ?>
138 <ul class="wpcf7cf-list">
139 <li><?php _e( 'Repeaters', 'cf7-conditional-fields'); ?></li>
140 <li><?php _e( 'Regular expressions', 'cf7-conditional-fields'); ?></li>
141 <li><?php _e( 'Toggle buttons', 'cf7-conditional-fields'); ?></li>
142 <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>
143 <li><?php _e( 'Multistep (with Summary)', 'cf7-conditional-fields'); ?></li>
144 <li><?php _e( 'More comming soon (Calculated Fields, ...)', 'cf7-conditional-fields'); ?></li>
145 </ul>
146 <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>
147 <?php
148 }
149 do_action('wpcf7cf_after_animation_settings');
150
151 echo '<h3>' . __( 'Advanced Settings', 'cf7-conditional-fields') . '</h3>';
152 wpcf7cf_input_fields_wrapper_start();
153
154 wpcf7cf_input_select('conditions_ui', array(
155 'label' => __( 'Conditional Fields UI', 'cf7-conditional-fields'),
156 'description' => sprintf(
157 // translators: max recommended conditions
158 __( '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 ),
159 'select_options' => array('normal'=> __( 'Normal', 'cf7-conditional-fields'), 'text_only' => __( 'Text mode', 'cf7-conditional-fields'))
160 ));
161
162 wpcf7cf_input_fields_wrapper_end();
163
164 submit_button();
165
166 ?>
167
168 </form></div>
169
170 <h3><?php _e( 'Restore Default Settings', 'cf7-conditional-fields' ); ?></h3>
171 <form method="post" id="reset-form" action="">
172 <p class="submit">
173 <input name="reset" class="button button-secondary" type="submit" value="<?php _e( 'Restore defaults', 'cf7-conditional-fields' ); ?>" >
174 <input type="hidden" name="action" value="reset" />
175 </p>
176 </form>
177 <script>
178 (function($){
179 $('#reset-form').submit(function() {
180 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' ) );
181 });
182 }(jQuery))
183 </script>
184
185 <?php
186 }
187
188 function wpcf7cf_input_fields_wrapper_start() {
189 echo '<table class="form-table" role="presentation"><tbody>';
190 }
191 function wpcf7cf_input_fields_wrapper_end() {
192 echo '</tbody></table>';
193 }
194
195 function wpcf7cf_input_field($slug, $args) {
196 $settings = wpcf7cf_get_settings();
197
198 $defaults = array(
199 'label'=>'',
200 'desription' => '',
201 'default' => wpcf7cf_get_default_settings()[$slug],
202 'label_editable' => false
203 );
204
205 $args = wp_parse_args( $args, $defaults );
206 extract($args);
207
208 $label; $description; $default; $label_editable;
209
210 if (!key_exists($slug, $settings)) {
211 $settings[$slug] = $default;
212 $settings[$slug.'_label'] = $label;
213 }
214
215 ?>
216
217 <tr>
218 <th scope="row">
219
220 <?php if ($label_editable) { ?>
221 <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>
222 <?php } else { ?>
223 <label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label>
224 <?php } ?>
225
226 </th>
227 <td>
228 <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.']' ?>">
229 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
230 <?php echo $description ?><?php if (!empty($default)) echo ' (' . __( 'Default:', 'cf7-conditional-fields' ) . ' '.$default.')' ?>
231 </p>
232 </td>
233 </tr>
234
235 <?php
236
237 }
238
239 function wpcf7cf_input_select($slug, $args) {
240 $settings = wpcf7cf_get_settings();
241
242 $defaults = array(
243 'label'=>'',
244 'desription' => '',
245 'select_options' => array(), // array($name => $value)
246 'default' => wpcf7cf_get_default_settings()[$slug],
247 );
248
249 $args = wp_parse_args( $args, $defaults );
250 extract($args);
251
252 $label; $description; $select_options; $default;
253
254 if (!key_exists($slug, $settings)) {
255 $settings[$slug] = $default;
256 }
257
258 ?>
259 <tr>
260 <th scope="row"><label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label></th>
261 <td>
262 <select id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
263 <?php foreach($select_options as $value => $text) { ?>
264 <option value="<?php echo $value ?>" <?php echo $settings[$slug]==$value?'selected':'' ?>><?php echo $text ?></option>
265 <?php } ?>
266 </select>
267 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
268 <?php echo $description ?><?php if (!empty($default)) echo ' (' . __( 'Default:', 'cf7-conditional-fields' ) . ' '.$select_options[$default].')' ?>
269 </p>
270 </td>
271 </tr>
272 <?php
273 }
274
275 add_action('admin_init', 'wpcf7cf_admin_init');
276 function wpcf7cf_admin_init(){
277
278 if(isset($_POST['reset']) && current_user_can( 'wpcf7_edit_contact_forms' ) ) {
279 wpcf7cf_reset_options();
280 }
281
282 register_setting( WPCF7CF_OPTIONS, WPCF7CF_OPTIONS, 'wpcf7cf_options_sanitize' );
283 }
284
285 function wpcf7cf_options_sanitize($input) {
286 return $input;
287 }
288
289 add_action( 'wp_ajax_wpcf7cf_dismiss_notice', 'wpcf7cf_dismiss_notice' );
290 function wpcf7cf_dismiss_notice() {
291 $notice_id = sanitize_text_field($_POST['noticeId'] ?? '');
292 $notice_suffix = $notice_id ? '_'.$notice_id : $notice_id;
293
294 $settings = wpcf7cf_get_settings();
295 $settings['notice_dismissed'.$notice_suffix] = true;
296 wpcf7cf_set_options($settings);
297 }
298