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.2 0.2.3
cf7-conditional-fields / options.php
cf7-conditional-fields Last commit date
js 9 years ago admin-style.css 9 years ago admin.php 9 years ago cf7cf.php 9 years ago contact-form-7-conditional-fields.php 9 years ago options.php 9 years ago readme.txt 9 years ago screenshot-1.png 10 years ago screenshot-2.png 10 years ago style.css 9 years ago
options.php
308 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_NOTICE_DISMISSED', false);
11
12 $wpcf7cf_default_options = array(
13 'animation' => WPCF7CF_DEFAULT_ANIMATION,
14 'animation_intime' => WPCF7CF_DEFAULT_ANIMATION_INTIME,
15 'animation_outtime' => WPCF7CF_DEFAULT_ANIMATION_OUTTIME,
16 'notice_dismissed' => WPCF7CF_DEFAULT_NOTICE_DISMISSED
17 );
18
19 $wpcf7cf_default_options = apply_filters('wpcf7cf_default_options', $wpcf7cf_default_options);
20
21 $wpcf7cf_options = get_option(WPCF7CF_OPTIONS);
22 if (!is_array($wpcf7cf_options)) $wpcf7cf_options = array();
23
24 if(isset($_POST['reset'])) {
25 update_option(WPCF7CF_OPTIONS, $wpcf7cf_default_options);
26 $wpcf7cf_options['wpcf7cf_settings_saved'] = 0;
27 }
28
29 // this setting will only be 0 as long as the user has not saved any settings. Once the user has saved the WPCF7CF settings, this value will always remain 1.
30 if (!key_exists('wpcf7cf_settings_saved',$wpcf7cf_options)) $wpcf7cf_options['wpcf7cf_settings_saved'] = 0;
31
32 if ($wpcf7cf_options['wpcf7cf_settings_saved'] == 0) {
33 $wpcf7cf_options = $wpcf7cf_default_options;
34 }
35
36
37 add_action('ninja_forms_display_before_field_function','wpcf7cf_wrap_input_field_before');
38 add_action('ninja_forms_display_after_field_function','wpcf7cf_wrap_input_field_after');
39
40 function wpcf7cf_wrap_input_field_before() { echo '<div class="resizable_input_wrapper">'; }
41 function wpcf7cf_wrap_input_field_after() { echo '</div>'; }
42
43 add_action( 'admin_enqueue_scripts', 'wpcf7cf_load_page_options_wp_admin_style' );
44 function wpcf7cf_load_page_options_wp_admin_style() {
45 wp_register_style( 'page_options_wp_admin_css', plugins_url('css/admin-style.css',__FILE__), false, WPCF7CF_VERSION );
46 wp_enqueue_style( 'page_options_wp_admin_css' );
47 }
48
49
50 add_action('admin_menu', 'wpcf7cf_admin_add_page');
51 function wpcf7cf_admin_add_page() {
52 add_submenu_page('wpcf7', 'Conditional Fields', 'Conditional Fields', WPCF7_ADMIN_READ_WRITE_CAPABILITY, 'wpcf7cf', 'wpcf7cf_options_page' );
53 }
54
55 function wpcf7cf_options_page() {
56 global $wpcf7cf_options;
57
58 // Include in admin_enqueue_scripts action hook
59 wp_enqueue_media();
60 //wp_enqueue_script( 'custom-background' );
61 wp_enqueue_script( 'wpcf7cf-image-upload', plugins_url('framework/js/bdwm-image-upload.js',__FILE__), array('jquery'), '1.0.0', true );
62
63 if (isset($_POST['reset'])) {
64 echo '<div id="message" class="updated fade"><p><strong>Settings restored to defaults</strong></p></div>';
65 } else if ($_REQUEST['settings-updated']) {
66 echo '<div id="message" class="updated fade"><p><strong>Settings updated</strong></p></div>';
67 }
68
69 ?>
70
71 <div class="wrap wpcf7cf-admin-wrap">
72 <?php screen_icon(); ?>
73 <h2>Conditional Fields for Contact Form 7 Settings</h2>
74 <?php if (!$wpcf7cf_options['notice_dismissed']) { ?>
75 <div class="wpcf7cf-options-notice notice notice-warning is-dismissible"><div style="padding: 10px 0;"><strong>Notice</strong>: These are global settings for Conditional Fields for Contact Form 7. <br><br><strong>How to create/edit conditional fields?</strong>
76 <ol>
77 <li>Create a new Contact Form or edit an existing one</li>
78 <li>Create at least one [group] inside the form</li>
79 <li>Save the Contact Form</li>
80 <li>go to the <strong><em>Conditional Fields</em></strong> Tab</li>
81 </ol>
82 <a href="#">Show me an example</a> | <a class="notice-dismiss-2" href="#">Dismiss notice</a>
83 </div></div>
84 <?php } ?>
85 <form action="options.php" method="post">
86 <?php settings_fields(WPCF7CF_OPTIONS); ?>
87
88 <input type="hidden" value="1" id="wpcf7cf_settings_saved" name="<?php echo WPCF7CF_OPTIONS.'[wpcf7cf_settings_saved]' ?>">
89
90 <h3>Default animation Settings</h3>
91
92 <?php
93
94 wpcf7cf_input_select('animation', array(
95 'label' => 'Animation',
96 'description' => 'Use animations while showing/hiding groups',
97 'options' => array('no'=> 'Disabled', 'yes' => 'Enabled')
98 ));
99
100 wpcf7cf_input_field('animation_intime', array(
101 'label' => 'Animation In time',
102 'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to show.',
103 ));
104
105 wpcf7cf_input_field('animation_outtime', array(
106 'label' => 'Animation Out Time',
107 'description' => 'A positive integer value indicating the time, in milliseconds, it will take for each group to hide.',
108 ));
109
110 submit_button();
111
112 do_action('wpcf7cf_after_animation_settings');
113
114 ?>
115
116 </form></div>
117
118 <h3>Restore Default Settings</h3>
119 <form method="post" id="reset-form" action="">
120 <p class="submit">
121 <input name="reset" class="button button-secondary" type="submit" value="Restore defaults" >
122 <input type="hidden" name="action" value="reset" />
123 </p>
124 </form>
125 <script>
126 (function($){
127 $('#reset-form').submit(function() {
128 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.');
129 });
130 }(jQuery))
131 </script>
132
133 <?php
134 }
135
136
137 function wpcf7cf_image_field($slug, $args) {
138
139 global $wpcf7cf_options, $wpcf7cf_default_options;
140
141 $defaults = array(
142 'title'=>'Image',
143 'description' => '',
144 'choose_text' => 'Choose an image',
145 'update_text' => 'Use image',
146 'default' => $wpcf7cf_default_options[$slug]
147 );
148
149 $args = wp_parse_args( $args, $defaults );
150 extract($args);
151 $label; $description; $choose_text; $update_text; $default;
152
153 if (!key_exists($slug, $wpcf7cf_options)) {
154 $wpcf7cf_options[$slug] = $default;
155 }
156
157 ?>
158 <div class="option-line">
159 <span class="label"><?php echo $label; ?></span>
160 <?php
161 if ($description) {
162 ?>
163 <p><?php echo $description; ?></p>
164 <?php
165 }
166 ?>
167 <div>
168 <div class="image-container" id="default-thumbnail-preview_<?php echo $slug ?>">
169 <?php
170 if ($wpcf7cf_options[$slug] != '') {
171 $img_info = wp_get_attachment_image_src($wpcf7cf_options[$slug], 'full');
172 $img_src = $img_info[0];
173 ?>
174 <img src="<?php echo $img_src ?>" height="100">
175 <?php
176 }
177 ?>
178 </div>
179 <a class="choose-from-library-link" href="#"
180 data-field="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>"
181 data-image_container="default-thumbnail-preview_<?php echo $slug ?>"
182 data-choose="<?php echo $choose_text; ?>"
183 data-update="<?php echo $update_text; ?>"><?php _e( 'Choose image' ); ?>
184 </a>
185 <input type="hidden" value="<?php echo $wpcf7cf_options[$slug] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
186 </div>
187 </div>
188 <?php
189
190 }
191
192 function wpcf7cf_input_field($slug, $args) {
193 global $wpcf7cf_options, $wpcf7cf_default_options;
194
195 $defaults = array(
196 'label'=>'',
197 'desription' => '',
198 'default' => $wpcf7cf_default_options[$slug]
199 );
200
201 $args = wp_parse_args( $args, $defaults );
202 extract($args);
203
204 $label; $description; $default;
205
206 if (!key_exists($slug, $wpcf7cf_options)) {
207 $wpcf7cf_options[$slug] = $default;
208 }
209
210 ?>
211 <div class="option-line">
212 <span class="label"><?php echo $label ?></span>
213 <span class="field"><input type="text" data-default-value="<?php echo $default ?>" value="<?php echo $wpcf7cf_options[$slug] ?>" id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>"></span>
214 <span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$default.')' ?></span>
215 </div>
216 <?php
217
218 }
219
220 function wpcf7cf_input_select($slug, $args) {
221 global $wpcf7cf_options, $wpcf7cf_default_options;
222
223 $defaults = array(
224 'label'=>'',
225 'desription' => '',
226 'options' => array(), // array($name => $value)
227 'default' => $wpcf7cf_default_options[$slug],
228 );
229
230 $args = wp_parse_args( $args, $defaults );
231 extract($args);
232
233 $label; $description; $options; $default;
234
235 if (!key_exists($slug, $wpcf7cf_options)) {
236 $wpcf7cf_options[$slug] = $default;
237 }
238
239 // $first_element = array('-1' => '-- Select --');
240 // $options = array_merge($first_element, $options);
241
242 ?>
243 <div class="option-line">
244 <span class="label"><?php echo $label ?></span>
245 <span class="field">
246 <select id="<?php echo WPCF7CF_OPTIONS.'_'.$slug ?>" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>">
247 <?php
248 foreach($options as $value => $text) {
249 ?>
250 <option value="<?php echo $value ?>" <?php echo $wpcf7cf_options[$slug]==$value?'selected':'' ?>><?php echo $text ?></option>
251 <?php
252 }
253 ?>
254 </select>
255 </span>
256 <span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$options[$default].')' ?></span>
257 </div>
258 <?php
259
260 }
261
262 function wpcf7cf_checkbox($slug, $args) {
263 global $wpcf7cf_options, $wpcf7cf_default_options;
264
265 $defaults = array(
266 'label'=>'',
267 'desription' => '',
268 'default' => $wpcf7cf_default_options[$slug],
269 );
270
271 $args = wp_parse_args( $args, $defaults );
272 extract($args);
273
274 $label; $description; $default;
275
276 ?>
277 <div class="option-line">
278 <span class="label"><?php echo $label ?></span>
279 <span class="field">
280
281 <input type="checkbox" data-default-value="<?php echo $default ?>" name="<?php echo WPCF7CF_OPTIONS.'['.$slug.']' ?>" value="1" <?php checked('1', $wpcf7cf_options[$slug]) ?>>
282 </span>
283 <span class="description"><?php echo $description ?><?php if (!empty($default)) echo ' (Default: '.$default.')' ?></span>
284 </div>
285 <?php
286 }
287
288 function wpcf7cf_regex_collection() {
289 global $wpcf7cf_options, $wpcf7cf_default_options;
290
291 }
292
293 add_action('admin_init', 'wpcf7cf_admin_init');
294 function wpcf7cf_admin_init(){
295 register_setting( WPCF7CF_OPTIONS, WPCF7CF_OPTIONS, 'wpcf7cf_options_sanitize' );
296 }
297
298 function wpcf7cf_options_sanitize($input) {
299 return $input;
300 }
301
302 add_action( 'wp_ajax_wpcf7cf_dismiss_notice', 'wpcf7cf_dismiss_notice' );
303 function wpcf7cf_dismiss_notice() {
304 global $wpcf7cf_options;
305 $wpcf7cf_options['notice_dismissed'] = true;
306 $wpcf7cf_options['wpcf7cf_settings_saved'] = 1;
307 update_option(WPCF7CF_OPTIONS,$wpcf7cf_options);
308 }