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