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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 5 years ago Wpcf7cfMailParser.php 6 years ago admin-style.css 6 years ago admin-style.css.map 6 years ago admin-style.scss 6 years ago admin.php 6 years ago cf7cf.php 5 years ago contact-form-7-conditional-fields.php 5 years ago init.php 5 years ago readme.txt 5 years ago style.css 6 years ago tg_pane_group.php 6 years ago wpcf7cf-options.php 6 years ago
wpcf7cf-options.php
287 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__), false, 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', '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</strong></p></div>';
81 } else if (isset($_REQUEST['settings-updated'])) {
82 echo '<div id="message" class="updated fade"><p><strong>Settings updated</strong></p></div>';
83 }
84
85 ?>
86
87 <div class="wrap wpcf7cf-admin-wrap">
88 <h2>Contact Form 7 - Conditional Fields Settings</h2>
89 <?php if (!$settings['notice_dismissed']) { ?>
90 <div class="wpcf7cf-options-notice notice notice-warning is-dismissible"><div style="padding: 10px 0;"><strong>Notice</strong>: These are global settings for Contact Form 7 - Conditional Fields. <br><br><strong>How to create/edit conditional fields?</strong>
91 <ol>
92 <li>Create a new Contact Form or edit an existing one</li>
93 <li>Create at least one [group] inside the form</li>
94 <li>Save the Contact Form</li>
95 <li>go to the <strong><em>Conditional Fields</em></strong> Tab</li>
96 </ol>
97 <a href="https://conditional-fields-cf7.bdwm.be/conditional-fields-for-contact-form-7-tutorial/" target="_blank">Show me an example</a> | <a class="notice-dismiss-2" href="#">Dismiss notice</a>
98 </div></div>
99 <?php } ?>
100 <form action="options.php" method="post">
101 <?php settings_fields(WPCF7CF_OPTIONS); ?>
102
103 <input type="hidden" name="<?php echo WPCF7CF_OPTIONS.'[notice_dismissed]' ?>" value="<?php echo $settings['notice_dismissed'] ?>" />
104
105 <?php
106
107 echo '<h3>Default animation Settings</h3>';
108 wpcf7cf_input_fields_wrapper_start();
109
110 wpcf7cf_input_select('animation', array(
111 'label' => 'Animation',
112 'description' => 'Use animations while showing/hiding groups',
113 'select_options' => array('yes' => 'Enabled', 'no'=> 'Disabled')
114 ));
115
116 wpcf7cf_input_field('animation_intime', array(
117 'label' => 'Animation In time',
118 'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to show.',
119 ));
120
121 wpcf7cf_input_field('animation_outtime', array(
122 'label' => 'Animation Out Time',
123 'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to hide.',
124 ));
125
126 wpcf7cf_input_fields_wrapper_end();
127 submit_button();
128
129 if (!WPCF7CF_IS_PRO) {
130 ?>
131 <h3>Conditional Fields PRO</h3>
132 Get conditional Fields PRO to unlock the full potential of CF7
133 <ul class="wpcf7cf-list">
134 <li>Repeaters</li>
135 <li>Regular expressions</li>
136 <li>Togglebuttons</li>
137 <li>Additional operators <code>&lt;</code> <code>&gt;</code> <code>&le;</code> <code>&ge;</code> <code>is empty</code></li>
138 <li>Multistep (with Summary)</li>
139 <li>More comming soon (Calculated Fields, ...)</li>
140 </ul>
141 <p><a target="_blank" class="button button-primary" href="https://conditional-fields-cf7.bdwm.be/contact-form-7-conditional-fields-pro/">Get PRO</a></p>
142 <?php
143 }
144 do_action('wpcf7cf_after_animation_settings');
145
146 echo '<h3>Advanced Settings</h3>';
147 wpcf7cf_input_fields_wrapper_start();
148
149 wpcf7cf_input_select('conditions_ui', array(
150 'label' => 'Conditonal Fields UI',
151 'description' => 'If you want to add more than '.WPCF7CF_MAX_RECOMMENDED_CONDITIONS.' conditions, it\'s recommended to switch to <strong>Text mode</strong> mode for better performance.',
152 'select_options' => array('normal'=> 'Normal', 'text_only' => 'Text mode')
153 ));
154
155 wpcf7cf_input_fields_wrapper_end();
156
157 submit_button();
158
159 ?>
160
161 </form></div>
162
163 <h3>Restore Default Settings</h3>
164 <form method="post" id="reset-form" action="">
165 <p class="submit">
166 <input name="reset" class="button button-secondary" type="submit" value="Restore defaults" >
167 <input type="hidden" name="action" value="reset" />
168 </p>
169 </form>
170 <script>
171 (function($){
172 $('#reset-form').submit(function() {
173 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.');
174 });
175 }(jQuery))
176 </script>
177
178 <?php
179 }
180
181 function wpcf7cf_input_fields_wrapper_start() {
182 echo '<table class="form-table" role="presentation"><tbody>';
183 }
184 function wpcf7cf_input_fields_wrapper_end() {
185 echo '</tbody></table>';
186 }
187
188 function wpcf7cf_input_field($slug, $args) {
189 $settings = wpcf7cf_get_settings();
190
191 $defaults = array(
192 'label'=>'',
193 'desription' => '',
194 'default' => wpcf7cf_get_default_settings()[$slug],
195 'label_editable' => false
196 );
197
198 $args = wp_parse_args( $args, $defaults );
199 extract($args);
200
201 $label; $description; $default; $label_editable;
202
203 if (!key_exists($slug, $settings)) {
204 $settings[$slug] = $default;
205 $settings[$slug.'_label'] = $label;
206 }
207
208 ?>
209
210 <tr>
211 <th scope="row">
212
213 <?php if ($label_editable) { ?>
214 <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>
215 <?php } else { ?>
216 <label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label>
217 <?php } ?>
218
219 </th>
220 <td>
221 <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.']' ?>">
222 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
223 <?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$default.')' ?>
224 </p>
225 </td>
226 </tr>
227
228 <?php
229
230 }
231
232 function wpcf7cf_input_select($slug, $args) {
233 $settings = wpcf7cf_get_settings();
234
235 $defaults = array(
236 'label'=>'',
237 'desription' => '',
238 'select_options' => array(), // array($name => $value)
239 'default' => wpcf7cf_get_default_settings()[$slug],
240 );
241
242 $args = wp_parse_args( $args, $defaults );
243 extract($args);
244
245 $label; $description; $select_options; $default;
246
247 if (!key_exists($slug, $settings)) {
248 $settings[$slug] = $default;
249 }
250
251 ?>
252 <tr>
253 <th scope="row"><label for="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"><?php echo $label ?></label></th>
254 <td>
255 <select id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
256 <?php foreach($select_options as $value => $text) { ?>
257 <option value="<?php echo $value ?>" <?php echo $settings[$slug]==$value?'selected':'' ?>><?php echo $text ?></option>
258 <?php } ?>
259 </select>
260 <p class="description" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>-description">
261 <?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$select_options[$default].')' ?>
262 </p>
263 </td>
264 </tr>
265 <?php
266 }
267
268 add_action('admin_init', 'wpcf7cf_admin_init');
269 function wpcf7cf_admin_init(){
270
271 if(isset($_POST['reset']) && current_user_can( 'wpcf7_edit_contact_form' ) ) {
272 wpcf7cf_reset_options();
273 }
274
275 register_setting( WPCF7CF_OPTIONS, WPCF7CF_OPTIONS, 'wpcf7cf_options_sanitize' );
276 }
277
278 function wpcf7cf_options_sanitize($input) {
279 return $input;
280 }
281
282 add_action( 'wp_ajax_wpcf7cf_dismiss_notice', 'wpcf7cf_dismiss_notice' );
283 function wpcf7cf_dismiss_notice() {
284 $settings = wpcf7cf_get_settings();
285 $settings['notice_dismissed'] = true;
286 wpcf7cf_set_options($settings);
287 }