Changeset 3444729
- Timestamp:
- 01/22/2026 11:05:31 AM (2 months ago)
- Location:
- cf7-coder
- Files:
-
- 15 added
- 5 edited
-
tags/1.0 (added)
-
tags/1.0/assets (added)
-
tags/1.0/assets/index.php (added)
-
tags/1.0/assets/material.css (added)
-
tags/1.0/assets/script.js (added)
-
tags/1.0/assets/style.css (added)
-
tags/1.0/cf7-coder.php (added)
-
tags/1.0/class.wpcf7coder-extension-activation.php (added)
-
tags/1.0/index.php (added)
-
tags/1.0/languages (added)
-
tags/1.0/languages/cf7-coder.pot (added)
-
tags/1.0/languages/index.php (added)
-
tags/1.0/readme.txt (added)
-
tags/1.0/screenshot-1.png (added)
-
tags/1.0/screenshot-2.png (added)
-
trunk/assets/script.js (modified) (1 diff)
-
trunk/assets/style.css (modified) (3 diffs)
-
trunk/cf7-coder.php (modified) (13 diffs)
-
trunk/class.wpcf7coder-extension-activation.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cf7-coder/trunk/assets/script.js
r3312322 r3444729 77 77 }); 78 78 }); 79 } 80 81 // Очікуємо wpcf7.taggen і перевизначаємо insert 82 function waitForWpcf7Taggen(callback, attempt = 0) { 83 if (typeof wpcf7 !== 'undefined' && wpcf7.taggen && typeof wpcf7.taggen.insert === 'function') { 84 callback(); 85 } else if (attempt < 20) { 86 setTimeout(() => waitForWpcf7Taggen(callback, attempt + 1), 100); 87 } else { 88 console.warn('wpcf7.taggen.insert не знайдено.'); 89 } 90 } 91 92 waitForWpcf7Taggen(() => { 79 80 document.addEventListener('click', function (e) { 81 const btn = e.target.closest('[data-taggen="insert-tag"], .insert-tag'); 82 if (!btn) { 83 return; 84 } 85 86 const dialog = btn.closest('dialog.tag-generator-dialog'); 87 if (!dialog) { 88 return; 89 } 90 91 if (!editorHTML || !editorHTML.codemirror) { 92 return; 93 } 94 95 // Знаходимо значення тега 96 const tagInput = dialog.querySelector('[data-tag-part="tag"], .tag'); 97 const tagValue = tagInput?.value; 98 99 if (!tagValue) { 100 return; 101 } 102 103 e.preventDefault(); 104 e.stopPropagation(); 105 106 // Вставляємо в CodeMirror 107 const cm = editorHTML.codemirror; 108 const cursor = cm.getCursor(); 109 cm.replaceRange(tagValue, cursor); 110 cm.focus(); 111 cm.setCursor({ line: cursor.line, ch: cursor.ch + tagValue.length }); 112 113 // Синхронізуємо з textarea 114 document.getElementById(textareaId).value = cm.getValue(); 115 116 // Закриваємо діалог без значення (щоб CF7 не вставив ще раз) 117 dialog.close(''); 118 }, true); // capture phase - важливо для перехоплення до CF7 119 120 // Слухаємо подію close на всіх діалогах (делегування) 121 document.addEventListener('close', function (e) { 122 if (!e.target.matches('dialog.tag-generator-dialog')) { 123 return; 124 } 125 126 if (!editorHTML || !editorHTML.codemirror) { 127 return; 128 } 129 130 // Синхронізуємо CodeMirror з textarea 131 const textareaValue = document.getElementById(textareaId).value; 132 const cmValue = editorHTML.codemirror.getValue(); 133 if (textareaValue !== cmValue) { 134 editorHTML.codemirror.setValue(textareaValue); 135 } 136 }, true); 137 } 138 139 function overrideTaggenInsert() { 140 if (typeof wpcf7 === 'undefined' || !wpcf7.taggen) { 141 return; 142 } 143 93 144 const originalInsert = wpcf7.taggen.insert; 94 145 95 wpcf7.taggen.insert = function ( content) {146 wpcf7.taggen.insert = function (tag) { 96 147 if (editorHTML && editorHTML.codemirror) { 97 const cursor = editorHTML.codemirror.getCursor(); 98 editorHTML.codemirror.replaceRange(content, cursor); 99 document.getElementById(textareaId).value = editorHTML.codemirror.getValue(); 148 const cm = editorHTML.codemirror; 149 const cursor = cm.getCursor(); 150 cm.replaceRange(tag, cursor); 151 cm.focus(); 152 cm.setCursor({ line: cursor.line, ch: cursor.ch + tag.length }); 153 document.getElementById(textareaId).value = cm.getValue(); 154 return; 100 155 } 101 156 originalInsert.apply(this, arguments); 102 157 }; 103 }); 158 } 159 160 overrideTaggenInsert(); 161 $(document).on('wpcf7Ready', overrideTaggenInsert); 162 163 // Redirect after submit toggle 164 const $redirectCheckbox = $('#wpcf7_redirect_enabled'); 165 const $redirectWrap = $('#wpcf7-redirect-url-wrap'); 166 167 // Initial state on page load 168 if ($redirectCheckbox.length && $redirectWrap.length) { 169 if (!$redirectCheckbox.is(':checked')) { 170 $redirectWrap.hide(); 171 } 172 173 $redirectCheckbox.on('change', function () { 174 if ($(this).is(':checked')) { 175 $redirectWrap.slideDown(200); 176 } else { 177 $redirectWrap.slideUp(200); 178 $('#wpcf7-redirect-url').val(''); 179 } 180 }); 181 } 182 183 // GA/GTM Event toggle 184 const $gaCheckbox = $('#wpcf7_ga_event'); 185 const $gaWrap = $('#wpcf7-ga-event-wrap'); 186 187 if ($gaCheckbox.length && $gaWrap.length) { 188 if (!$gaCheckbox.is(':checked')) { 189 $gaWrap.hide(); 190 } 191 192 $gaCheckbox.on('change', function () { 193 if ($(this).is(':checked')) { 194 $gaWrap.slideDown(200); 195 } else { 196 $gaWrap.slideUp(200); 197 $('#wpcf7-ga-event-name').val(''); 198 } 199 }); 200 } 201 202 // Auto-hide message toggle 203 const $autoHideCheckbox = $('#wpcf7_auto_hide_message'); 204 const $autoHideWrap = $('#wpcf7-auto-hide-wrap'); 205 206 if ($autoHideCheckbox.length && $autoHideWrap.length) { 207 if (!$autoHideCheckbox.is(':checked')) { 208 $autoHideWrap.hide(); 209 } 210 211 $autoHideCheckbox.on('change', function () { 212 if ($(this).is(':checked')) { 213 $autoHideWrap.slideDown(200); 214 } else { 215 $autoHideWrap.slideUp(200); 216 } 217 }); 218 } 104 219 }); 105 220 })(jQuery); -
cf7-coder/trunk/assets/style.css
r3312322 r3444729 3 3 box-shadow: 0 0 0 transparent; 4 4 resize: vertical; 5 min-height: 800px; 5 6 } 6 7 … … 46 47 line-height: 1.5; 47 48 text-align: left; 49 z-index: 9; 48 50 } 49 51 .has-tooltip::after { … … 60 62 width: 0; 61 63 transform: translateX(-50%); 64 z-index: 9; 62 65 } 63 66 .has-tooltip:focus-visible::before, .has-tooltip:focus-visible::after, .has-tooltip:focus::before, .has-tooltip:focus::after, .has-tooltip:hover::before, .has-tooltip:hover::after { -
cf7-coder/trunk/cf7-coder.php
r3312322 r3444729 4 4 * Plugin URI: https://wordpress.org/cf7-coder 5 5 * Description: Add HTML editor to Contact Form 7. 6 * Version: 0.26 * Version: 1.0 7 7 * Author: Wow-Company 8 8 * Author URI: https://wow-estore.com/ … … 12 12 * Domain Path: /languages 13 13 * 14 * PHP version 5.6.014 * PHP version 7.4 15 15 * 16 16 * @category Wordpress_Plugin … … 27 27 class CF7_Coder { 28 28 public function __construct() { 29 add_action( 'plugins_loaded', [ $this, "text_domain" ] );30 29 add_action( "admin_enqueue_scripts", [ $this, "style_script" ] ); 31 30 add_action( 'wpcf7_admin_misc_pub_section', [ $this, 'wpcf7_add_test_mode' ] ); … … 33 32 add_action( 'wpcf7_save_contact_form', [ $this, 'wpcf7_save' ] ); 34 33 add_filter( 'do_shortcode_tag', [ $this, 'wpcf7_frontend' ], 10, 4 ); 35 } 36 37 // Download the folder with languages 38 public function text_domain() { 39 $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; 40 load_plugin_textdomain( 'cf7-coder', false, $languages_folder ); 34 35 // Conditional loading of CF7 assets 36 if ( get_option( 'wpcf7_load_assets_shortcode' ) ) { 37 add_action( 'wp_enqueue_scripts', [ $this, 'dequeue_cf7_assets' ], 100 ); 38 } 41 39 } 42 40 … … 48 46 49 47 if ( $page === $hook || $page_new === $hook ) { 50 $version = ' 0.2';48 $version = '1.0'; 51 49 52 50 wp_enqueue_script( 'code-editor' ); … … 56 54 57 55 $url_style = plugin_dir_url( __FILE__ ) . 'assets/style.css'; 58 wp_enqueue_style( "coder-wpcf7", $url_style );56 wp_enqueue_style( "coder-wpcf7", $url_style, array(), $version ); 59 57 60 58 $url_matirial = plugin_dir_url( __FILE__ ) . 'assets/material.css'; 61 wp_enqueue_style( "coder-wpcf7-matirial", $url_matirial );59 wp_enqueue_style( "coder-wpcf7-matirial", $url_matirial, array(), $version ); 62 60 63 61 $url_script = plugin_dir_url( __FILE__ ) . 'assets/script.js'; … … 69 67 // Add checkbox 'Test Mode' in sidebar 70 68 public function wpcf7_add_test_mode() { 69 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified by CF7 71 70 $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : '-1'; 72 71 $checked = get_post_meta( $post_id, '_wpcf7_test_mode', true ); … … 80 79 </div> 81 80 <?php 82 $post_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : '-1';83 81 $checked = get_post_meta( $post_id, '_wpcf7_remove_auto_tags', true ); 84 82 ?> … … 98 96 <?php esc_html_e( 'Enable dark theme (Material)', 'cf7-coder' ); ?> 99 97 </label> 98 </div> 99 <div class="misc-pub-section"> 100 <label class="wpcf7-load-assets"> 101 <input value="1" type="checkbox" name="wpcf7_load_assets_shortcode" <?php checked( get_option( 'wpcf7_load_assets_shortcode' ) ); ?>> 102 <?php esc_html_e( 'Load scripts only on pages with shortcode', 'cf7-coder' ); ?> 103 <sup class="has-tooltip on-left" data-tooltip="CF7 scripts and styles will only be loaded on pages containing the contact form shortcode.">ℹ</sup> 104 </label> 105 </div> 106 <?php 107 $redirect_enabled = get_post_meta( $post_id, '_wpcf7_redirect_enabled', true ); 108 $redirect_url = get_post_meta( $post_id, '_wpcf7_redirect_url', true ); 109 $redirect_acf_field = get_post_meta( $post_id, '_wpcf7_redirect_acf_field', true ); 110 ?> 111 <div class="misc-pub-section"> 112 <label class="wpcf7-redirect"> 113 <input value="1" type="checkbox" id="wpcf7_redirect_enabled" name="wpcf7-redirect-enabled" <?php checked( $redirect_enabled ); ?>> 114 <?php esc_html_e( 'Redirect after submit', 'cf7-coder' ); ?> 115 <sup class="has-tooltip on-left" data-tooltip="Redirect to a URL after successful form submission.">ℹ</sup> 116 </label> 117 <div id="wpcf7-redirect-url-wrap" style="margin-top: 8px; <?php echo $redirect_enabled ? '' : 'display: none;'; ?>"> 118 <input type="url" name="wpcf7-redirect-url" id="wpcf7-redirect-url" 119 value="<?php echo esc_attr( $redirect_url ); ?>" 120 placeholder="https://example.com/thank-you" style="width: 100%;"> 121 <?php if ( class_exists( 'ACF' ) ) : ?> 122 <?php $acf_field = get_post_meta( $post_id, '_wpcf7_redirect_acf_field', true ); ?> 123 <input type="text" name="wpcf7-redirect-acf-field" id="wpcf7-redirect-acf-field" 124 value="<?php echo esc_attr( $acf_field ); ?>" 125 placeholder="ACF field name" style="width: 100%; margin-top: 5px;"> 126 <small style="color: #666;">ACF field from current page (overrides URL above)</small> 127 <?php endif; ?> 128 <?php $redirect_new_tab = get_post_meta( $post_id, '_wpcf7_redirect_new_tab', true ); ?> 129 <?php $redirect_download = get_post_meta( $post_id, '_wpcf7_redirect_download', true ); ?> 130 <label style="display: block; margin-top: 8px;"> 131 <input type="checkbox" name="wpcf7-redirect-new-tab" value="1" <?php checked( $redirect_new_tab ); ?>> 132 <?php esc_html_e( 'Open in new tab', 'cf7-coder' ); ?> 133 </label> 134 <label style="display: block; margin-top: 4px;"> 135 <input type="checkbox" name="wpcf7-redirect-download" value="1" <?php checked( $redirect_download ); ?>> 136 <?php esc_html_e( 'Force download', 'cf7-coder' ); ?> 137 </label> 138 </div> 139 </div> 140 <?php 141 $hide_form = get_post_meta( $post_id, '_wpcf7_hide_form', true ); 142 ?> 143 <div class="misc-pub-section"> 144 <label class="wpcf7-hide-form"> 145 <input value="1" type="checkbox" name="wpcf7-hide-form" <?php checked( $hide_form ); ?>> 146 <?php esc_html_e( 'Hide form after submit', 'cf7-coder' ); ?> 147 <sup class="has-tooltip on-left" data-tooltip="Hide the form after successful submission, show only the success message.">ℹ</sup> 148 </label> 149 </div> 150 <?php 151 $remove_refill = get_post_meta( $post_id, '_wpcf7_remove_refill', true ); 152 ?> 153 <div class="misc-pub-section"> 154 <label class="wpcf7-remove-refill"> 155 <input value="1" type="checkbox" name="wpcf7-remove-refill" <?php checked( $remove_refill ); ?>> 156 <?php esc_html_e( 'Remove refill', 'cf7-coder' ); ?> 157 <sup class="has-tooltip on-left" data-tooltip="Clear form fields after validation error instead of keeping entered values.">ℹ</sup> 158 </label> 159 </div> 160 <?php 161 $disable_submit = get_post_meta( $post_id, '_wpcf7_disable_submit', true ); 162 ?> 163 <div class="misc-pub-section"> 164 <label class="wpcf7-disable-submit"> 165 <input value="1" type="checkbox" name="wpcf7-disable-submit" <?php checked( $disable_submit ); ?>> 166 <?php esc_html_e( 'Disable submit button while sending', 'cf7-coder' ); ?> 167 <sup class="has-tooltip on-left" data-tooltip="Disable submit button during form submission to prevent double submissions.">ℹ</sup> 168 </label> 169 </div> 170 <?php 171 $prefill_url = get_post_meta( $post_id, '_wpcf7_prefill_url', true ); 172 ?> 173 <div class="misc-pub-section"> 174 <label class="wpcf7-prefill-url"> 175 <input value="1" type="checkbox" name="wpcf7-prefill-url" <?php checked( $prefill_url ); ?>> 176 <?php esc_html_e( 'Pre-fill fields from URL', 'cf7-coder' ); ?> 177 <sup class="has-tooltip on-left" data-tooltip="Fill form fields from URL parameters (e.g., ?your-email=test@example.com).">ℹ</sup> 178 </label> 179 </div> 180 <?php 181 $ga_event = get_post_meta( $post_id, '_wpcf7_ga_event', true ); 182 $ga_event_name = get_post_meta( $post_id, '_wpcf7_ga_event_name', true ); 183 ?> 184 <div class="misc-pub-section"> 185 <label class="wpcf7-ga-event"> 186 <input value="1" type="checkbox" id="wpcf7_ga_event" name="wpcf7-ga-event" <?php checked( $ga_event ); ?>> 187 <?php esc_html_e( 'GA/GTM Event on submit', 'cf7-coder' ); ?> 188 <sup class="has-tooltip on-left" data-tooltip="Send event to Google Analytics/GTM dataLayer on successful submission.">ℹ</sup> 189 </label> 190 <div id="wpcf7-ga-event-wrap" style="margin-top: 8px; <?php echo ! empty( $ga_event ) ? '' : 'display: none;'; ?>"> 191 <input type="text" name="wpcf7-ga-event-name" id="wpcf7-ga-event-name" 192 value="<?php echo esc_attr( $ga_event_name ); ?>" 193 placeholder="cf7_form_submit" style="width: 100%;"> 194 <small style="color: #666;">Event name for dataLayer</small> 195 </div> 196 </div> 197 <?php 198 $scroll_to_message = get_post_meta( $post_id, '_wpcf7_scroll_to_message', true ); 199 ?> 200 <div class="misc-pub-section"> 201 <label class="wpcf7-scroll-to-message"> 202 <input value="1" type="checkbox" name="wpcf7-scroll-to-message" <?php checked( $scroll_to_message ); ?>> 203 <?php esc_html_e( 'Scroll to message after submit', 'cf7-coder' ); ?> 204 <sup class="has-tooltip on-left" data-tooltip="Automatically scroll to success/error message after form submission.">ℹ</sup> 205 </label> 206 </div> 207 <?php 208 $auto_hide_message = get_post_meta( $post_id, '_wpcf7_auto_hide_message', true ); 209 $auto_hide_timeout = get_post_meta( $post_id, '_wpcf7_auto_hide_timeout', true ); 210 if ( empty( $auto_hide_timeout ) ) { 211 $auto_hide_timeout = 5; 212 } 213 ?> 214 <div class="misc-pub-section"> 215 <label class="wpcf7-auto-hide-message"> 216 <input value="1" type="checkbox" id="wpcf7_auto_hide_message" name="wpcf7-auto-hide-message" <?php checked( $auto_hide_message ); ?>> 217 <?php esc_html_e( 'Auto-hide success message', 'cf7-coder' ); ?> 218 <sup class="has-tooltip on-left" data-tooltip="Automatically hide success message after specified seconds.">ℹ</sup> 219 </label> 220 <div id="wpcf7-auto-hide-wrap" style="margin-top: 8px; <?php echo ! empty( $auto_hide_message ) ? '' : 'display: none;'; ?>"> 221 <input type="number" name="wpcf7-auto-hide-timeout" id="wpcf7-auto-hide-timeout" 222 value="<?php echo esc_attr( $auto_hide_timeout ); ?>" 223 min="1" max="60" style="width: 60px;"> <?php esc_html_e( 'seconds', 'cf7-coder' ); ?> 224 </div> 100 225 </div> 101 226 <div class="misc-pub-section"> … … 118 243 119 244 // Save custom properties 245 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Nonce verified by Contact Form 7 120 246 public function wpcf7_save( $contact_form ) { 247 $post_id = $contact_form->id(); 121 248 $properties = $contact_form->get_properties(); 122 249 … … 126 253 127 254 $contact_form->set_properties( $properties ); 128 } 255 256 // Save global option for conditional assets loading 257 $load_assets_shortcode = isset( $_POST['wpcf7_load_assets_shortcode'] ) ? '1' : ''; 258 update_option( 'wpcf7_load_assets_shortcode', $load_assets_shortcode ); 259 260 // Save redirect enabled checkbox 261 $redirect_enabled = isset( $_POST['wpcf7-redirect-enabled'] ) ? '1' : ''; 262 update_post_meta( $post_id, '_wpcf7_redirect_enabled', $redirect_enabled ); 263 264 // Save redirect URL 265 $redirect_url = isset( $_POST['wpcf7-redirect-url'] ) ? esc_url_raw( wp_unslash( $_POST['wpcf7-redirect-url'] ) ) : ''; 266 update_post_meta( $post_id, '_wpcf7_redirect_url', $redirect_url ); 267 268 // Save ACF field name for redirect 269 $acf_field = isset( $_POST['wpcf7-redirect-acf-field'] ) ? sanitize_text_field( wp_unslash( $_POST['wpcf7-redirect-acf-field'] ) ) : ''; 270 update_post_meta( $post_id, '_wpcf7_redirect_acf_field', $acf_field ); 271 272 // Save redirect new tab option 273 $redirect_new_tab = isset( $_POST['wpcf7-redirect-new-tab'] ) ? '1' : ''; 274 update_post_meta( $post_id, '_wpcf7_redirect_new_tab', $redirect_new_tab ); 275 276 // Save redirect download option 277 $redirect_download = isset( $_POST['wpcf7-redirect-download'] ) ? '1' : ''; 278 update_post_meta( $post_id, '_wpcf7_redirect_download', $redirect_download ); 279 280 // Save hide form option 281 $hide_form = isset( $_POST['wpcf7-hide-form'] ) ? '1' : ''; 282 update_post_meta( $post_id, '_wpcf7_hide_form', $hide_form ); 283 284 // Save remove refill option 285 $remove_refill = isset( $_POST['wpcf7-remove-refill'] ) ? '1' : ''; 286 update_post_meta( $post_id, '_wpcf7_remove_refill', $remove_refill ); 287 288 // Save disable submit button option 289 $disable_submit = isset( $_POST['wpcf7-disable-submit'] ) ? '1' : ''; 290 update_post_meta( $post_id, '_wpcf7_disable_submit', $disable_submit ); 291 292 // Save pre-fill from URL option 293 $prefill_url = isset( $_POST['wpcf7-prefill-url'] ) ? '1' : ''; 294 update_post_meta( $post_id, '_wpcf7_prefill_url', $prefill_url ); 295 296 // Save GA/GTM event options 297 $ga_event = isset( $_POST['wpcf7-ga-event'] ) ? '1' : ''; 298 update_post_meta( $post_id, '_wpcf7_ga_event', $ga_event ); 299 300 $ga_event_name = isset( $_POST['wpcf7-ga-event-name'] ) ? sanitize_text_field( wp_unslash( $_POST['wpcf7-ga-event-name'] ) ) : ''; 301 update_post_meta( $post_id, '_wpcf7_ga_event_name', $ga_event_name ); 302 303 // Save scroll to message option 304 $scroll_to_message = isset( $_POST['wpcf7-scroll-to-message'] ) ? '1' : ''; 305 update_post_meta( $post_id, '_wpcf7_scroll_to_message', $scroll_to_message ); 306 307 // Save auto-hide message options 308 $auto_hide_message = isset( $_POST['wpcf7-auto-hide-message'] ) ? '1' : ''; 309 update_post_meta( $post_id, '_wpcf7_auto_hide_message', $auto_hide_message ); 310 311 $auto_hide_timeout = isset( $_POST['wpcf7-auto-hide-timeout'] ) ? absint( $_POST['wpcf7-auto-hide-timeout'] ) : 5; 312 if ( $auto_hide_timeout < 1 ) { 313 $auto_hide_timeout = 1; 314 } 315 if ( $auto_hide_timeout > 60 ) { 316 $auto_hide_timeout = 60; 317 } 318 update_post_meta( $post_id, '_wpcf7_auto_hide_timeout', $auto_hide_timeout ); 319 } 320 // phpcs:enable WordPress.Security.NonceVerification.Missing 129 321 130 322 // Work with Frontend 131 323 public function wpcf7_frontend( $output, $tag, $atts, $m ) { 132 324 if ( $tag === 'contact-form-7' ) { 325 // Enqueue CF7 assets if conditional loading is enabled 326 if ( get_option( 'wpcf7_load_assets_shortcode' ) ) { 327 $this->enqueue_cf7_assets(); 328 } 329 133 330 if ( ! function_exists( 'wpcf7_get_contact_form_by_hash' ) ) { 134 331 return $output; … … 137 334 $form = wpcf7_get_contact_form_by_hash( $atts['id'] ); 138 335 139 $form_id = null; 140 141 if ( $form instanceof WPCF7_ContactForm ) { 142 $form_id = $form->id(); 143 } 144 145 if ( $form_id === null ) { 336 if ( ! $form instanceof WPCF7_ContactForm ) { 146 337 return $output; 147 338 } 339 340 $form_id = $form->id(); 148 341 149 342 $remove_tags = get_post_meta( $form_id, '_wpcf7_remove_auto_tags', true ); 150 343 if ( ! empty( $remove_tags ) ) { 151 $output = str_replace( array( '<p>', '</p>', '<br/>' ), '', $output ); ;344 $output = str_replace( array( '<p>', '</p>', '<br/>' ), '', $output ); 152 345 } 153 346 … … 156 349 $output = ''; 157 350 } 351 352 // Redirect after submit - check if enabled first 353 $redirect_enabled = get_post_meta( $form_id, '_wpcf7_redirect_enabled', true ); 354 if ( ! empty( $redirect_enabled ) ) { 355 $redirect_url = ''; 356 $acf_field_name = get_post_meta( $form_id, '_wpcf7_redirect_acf_field', true ); 357 358 // Check ACF field first (from current page) 359 if ( ! empty( $acf_field_name ) && function_exists( 'get_field' ) ) { 360 $current_post_id = get_the_ID(); 361 $acf_url = get_field( $acf_field_name, $current_post_id ); 362 if ( ! empty( $acf_url ) ) { 363 $redirect_url = $acf_url; 364 } 365 } 366 367 // Fallback to static URL only if ACF field name is not set 368 if ( empty( $redirect_url ) && empty( $acf_field_name ) ) { 369 $redirect_url = get_post_meta( $form_id, '_wpcf7_redirect_url', true ); 370 } 371 372 if ( ! empty( $redirect_url ) ) { 373 $redirect_new_tab = get_post_meta( $form_id, '_wpcf7_redirect_new_tab', true ); 374 $redirect_download = get_post_meta( $form_id, '_wpcf7_redirect_download', true ); 375 376 // Determine redirect action: download > new tab > same window 377 if ( ! empty( $redirect_download ) ) { 378 $redirect_action = 'var link = document.createElement("a"); link.href = "' . esc_url( $redirect_url ) . '"; link.download = ""; document.body.appendChild(link); link.click(); document.body.removeChild(link);'; 379 } elseif ( ! empty( $redirect_new_tab ) ) { 380 $redirect_action = 'window.open("' . esc_url( $redirect_url ) . '", "_blank");'; 381 } else { 382 $redirect_action = 'window.location.href = "' . esc_url( $redirect_url ) . '";'; 383 } 384 385 $output .= '<script> 386 document.addEventListener("wpcf7mailsent", function(event) { 387 if (event.detail.contactFormId == ' . (int) $form_id . ') { 388 ' . $redirect_action . ' 389 } 390 }); 391 </script>'; 392 } 393 } 394 395 // Hide form after submit 396 $hide_form = get_post_meta( $form_id, '_wpcf7_hide_form', true ); 397 if ( ! empty( $hide_form ) ) { 398 $output .= '<script> 399 document.addEventListener("wpcf7mailsent", function(event) { 400 if (event.detail.contactFormId == ' . (int) $form_id . ') { 401 var wrapper = event.target.closest(".wpcf7"); 402 if (wrapper) { 403 var form = wrapper.querySelector("form"); 404 if (form) { 405 Array.from(form.children).forEach(function(child) { 406 if (!child.classList.contains("wpcf7-response-output")) { 407 child.style.display = "none"; 408 } 409 }); 410 } 411 } 412 } 413 }); 414 </script>'; 415 } 416 417 // Remove refill - clear form fields after validation error 418 $remove_refill = get_post_meta( $form_id, '_wpcf7_remove_refill', true ); 419 if ( ! empty( $remove_refill ) ) { 420 $output .= '<script> 421 document.addEventListener("wpcf7invalid", function(event) { 422 if (event.detail.contactFormId == ' . (int) $form_id . ') { 423 var wrapper = event.target.closest(".wpcf7"); 424 if (wrapper) { 425 var form = wrapper.querySelector("form"); 426 if (form) { form.reset(); } 427 } 428 } 429 }); 430 </script>'; 431 } 432 433 // Disable submit button while sending 434 $disable_submit = get_post_meta( $form_id, '_wpcf7_disable_submit', true ); 435 if ( ! empty( $disable_submit ) ) { 436 $output .= '<script> 437 (function() { 438 var formId = ' . (int) $form_id . '; 439 document.addEventListener("wpcf7beforesubmit", function(event) { 440 if (event.detail.contactFormId == formId) { 441 var wrapper = event.target.closest(".wpcf7"); 442 if (wrapper) { 443 var btn = wrapper.querySelector("input[type=submit], button[type=submit]"); 444 if (btn) { 445 btn.disabled = true; 446 btn.dataset.originalValue = btn.value || btn.textContent; 447 if (btn.tagName === "INPUT") { 448 btn.value = "' . esc_js( __( 'Sending...', 'cf7-coder' ) ) . '"; 449 } else { 450 btn.textContent = "' . esc_js( __( 'Sending...', 'cf7-coder' ) ) . '"; 451 } 452 } 453 } 454 } 455 }); 456 document.addEventListener("wpcf7mailsent", function(event) { 457 if (event.detail.contactFormId == formId) { 458 var wrapper = event.target.closest(".wpcf7"); 459 if (wrapper) { 460 var btn = wrapper.querySelector("input[type=submit], button[type=submit]"); 461 if (btn) { 462 btn.disabled = false; 463 if (btn.tagName === "INPUT") { 464 btn.value = btn.dataset.originalValue; 465 } else { 466 btn.textContent = btn.dataset.originalValue; 467 } 468 } 469 } 470 } 471 }); 472 document.addEventListener("wpcf7mailfailed", function(event) { 473 if (event.detail.contactFormId == formId) { 474 var wrapper = event.target.closest(".wpcf7"); 475 if (wrapper) { 476 var btn = wrapper.querySelector("input[type=submit], button[type=submit]"); 477 if (btn) { 478 btn.disabled = false; 479 if (btn.tagName === "INPUT") { 480 btn.value = btn.dataset.originalValue; 481 } else { 482 btn.textContent = btn.dataset.originalValue; 483 } 484 } 485 } 486 } 487 }); 488 document.addEventListener("wpcf7invalid", function(event) { 489 if (event.detail.contactFormId == formId) { 490 var wrapper = event.target.closest(".wpcf7"); 491 if (wrapper) { 492 var btn = wrapper.querySelector("input[type=submit], button[type=submit]"); 493 if (btn) { 494 btn.disabled = false; 495 if (btn.tagName === "INPUT") { 496 btn.value = btn.dataset.originalValue; 497 } else { 498 btn.textContent = btn.dataset.originalValue; 499 } 500 } 501 } 502 } 503 }); 504 })(); 505 </script>'; 506 } 507 508 // Pre-fill fields from URL parameters 509 $prefill_url = get_post_meta( $form_id, '_wpcf7_prefill_url', true ); 510 if ( ! empty( $prefill_url ) ) { 511 $output .= '<script> 512 (function() { 513 var wrapper = document.querySelector(".wpcf7[data-wpcf7-id=\"' . (int) $form_id . '\"]"); 514 if (wrapper) { 515 var params = new URLSearchParams(window.location.search); 516 params.forEach(function(value, key) { 517 var field = wrapper.querySelector("[name=\"" + key + "\"]"); 518 if (field) { 519 if (field.type === "checkbox" || field.type === "radio") { 520 if (field.value === value || value === "1" || value === "true") { 521 field.checked = true; 522 } 523 } else if (field.tagName === "SELECT") { 524 var option = field.querySelector("option[value=\"" + value + "\"]"); 525 if (option) { field.value = value; } 526 } else { 527 field.value = value; 528 } 529 } 530 }); 531 } 532 })(); 533 </script>'; 534 } 535 536 // GA/GTM Event on successful submit 537 $ga_event = get_post_meta( $form_id, '_wpcf7_ga_event', true ); 538 if ( ! empty( $ga_event ) ) { 539 $ga_event_name = get_post_meta( $form_id, '_wpcf7_ga_event_name', true ); 540 if ( empty( $ga_event_name ) ) { 541 $ga_event_name = 'cf7_form_submit'; 542 } 543 $output .= '<script> 544 document.addEventListener("wpcf7mailsent", function(event) { 545 if (event.detail.contactFormId == ' . (int) $form_id . ') { 546 if (typeof dataLayer !== "undefined") { 547 dataLayer.push({ 548 "event": "' . esc_js( $ga_event_name ) . '", 549 "cf7FormId": ' . (int) $form_id . ', 550 "cf7FormTitle": "' . esc_js( $form->title() ) . '" 551 }); 552 } 553 } 554 }); 555 </script>'; 556 } 557 558 // Scroll to message after submit 559 $scroll_to_message = get_post_meta( $form_id, '_wpcf7_scroll_to_message', true ); 560 if ( ! empty( $scroll_to_message ) ) { 561 $output .= '<script> 562 (function() { 563 var formId = ' . (int) $form_id . '; 564 function scrollToMessage(event) { 565 if (event.detail.contactFormId == formId) { 566 var wrapper = event.target.closest(".wpcf7"); 567 if (wrapper) { 568 var message = wrapper.querySelector(".wpcf7-response-output"); 569 if (message) { 570 message.scrollIntoView({ behavior: "smooth", block: "center" }); 571 } 572 } 573 } 574 } 575 document.addEventListener("wpcf7mailsent", scrollToMessage); 576 document.addEventListener("wpcf7mailfailed", scrollToMessage); 577 document.addEventListener("wpcf7invalid", scrollToMessage); 578 })(); 579 </script>'; 580 } 581 582 // Auto-hide success message 583 $auto_hide_message = get_post_meta( $form_id, '_wpcf7_auto_hide_message', true ); 584 if ( ! empty( $auto_hide_message ) ) { 585 $auto_hide_timeout = get_post_meta( $form_id, '_wpcf7_auto_hide_timeout', true ); 586 if ( empty( $auto_hide_timeout ) ) { 587 $auto_hide_timeout = 5; 588 } 589 $output .= '<script> 590 document.addEventListener("wpcf7mailsent", function(event) { 591 if (event.detail.contactFormId == ' . (int) $form_id . ') { 592 var wrapper = event.target.closest(".wpcf7"); 593 if (wrapper) { 594 var message = wrapper.querySelector(".wpcf7-response-output"); 595 if (message) { 596 setTimeout(function() { 597 message.style.transition = "opacity 0.5s"; 598 message.style.opacity = "0"; 599 setTimeout(function() { 600 message.style.display = "none"; 601 message.style.opacity = "1"; 602 }, 500); 603 }, ' . (int) $auto_hide_timeout * 1000 . '); 604 } 605 } 606 } 607 }); 608 </script>'; 609 } 158 610 } 159 611 160 612 return $output; 613 } 614 615 // Enqueue CF7 assets when shortcode is found 616 public function enqueue_cf7_assets() { 617 if ( function_exists( 'wpcf7_enqueue_scripts' ) ) { 618 wpcf7_enqueue_scripts(); 619 } 620 if ( function_exists( 'wpcf7_enqueue_styles' ) ) { 621 wpcf7_enqueue_styles(); 622 } 623 } 624 625 // Dequeue CF7 scripts and styles 626 public function dequeue_cf7_assets() { 627 wp_dequeue_script( 'contact-form-7' ); 628 wp_dequeue_style( 'contact-form-7' ); 161 629 } 162 630 -
cf7-coder/trunk/class.wpcf7coder-extension-activation.php
r2571791 r3444729 91 91 } 92 92 93 echo '<div class="error"><p>' . esc_html( $this->plugin_name ) . sprintf( esc_html__( ' requires Contact Form 7! Please %s first and then activate this.', 'cf7-coder' ), $link ) . '</p></div>'; 93 /* translators: %s: link to install or activate Contact Form 7 plugin */ 94 $message = sprintf( esc_html__( ' requires Contact Form 7! Please %s first and then activate this.', 'cf7-coder' ), $link ); 95 echo '<div class="error"><p>' . esc_html( $this->plugin_name ) . wp_kses( $message, array( 'a' => array( 'href' => array() ) ) ) . '</p></div>'; 94 96 } 95 97 } -
cf7-coder/trunk/readme.txt
r3408131 r3444729 2 2 Contributors: Wpcalc, lobov 3 3 Donate link: https://wow-estore.com/ 4 Tags: cf7, contact form , html editor, code editor, syntax highlight4 Tags: cf7, contact form 7, html editor, code editor, redirect 5 5 Requires at least: 5.0 6 6 Tested up to: 6.9 7 Requires PHP: 5.68 Stable tag: 0.27 Requires PHP: 7.4 8 Stable tag: 1.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Add HTML editor to Contact Form 7 with code highlighter .12 Add HTML editor to Contact Form 7 with code highlighter and extended form options. 13 13 14 14 == Description == 15 Contact Form 7 plugin allows editing forms with a standard textarea. This addon adds an HTML editor with code highlighter to each contact form .15 Contact Form 7 plugin allows editing forms with a standard textarea. This addon adds an HTML editor with code highlighter to each contact form and provides many useful options to enhance your forms. 16 16 17 You can also hide the form from users using Test Mode. The form in this mode will be available only to the site administrator. 17 = Editor Features = 18 * **HTML Editor** with syntax highlighting powered by CodeMirror 19 * **Dark Theme** (Material) support for comfortable editing 20 * **Auto-close** brackets and tags 21 * **Code folding** and line numbers 22 * **Search and replace** functionality (Ctrl+F) 18 23 19 = Main features = 20 * Added HTML editor; 21 * Added Test Mode for form; 22 * Remove auto added p tags into the form. 24 = Form Behavior Options = 25 * **Test Mode** - Hide form from non-administrators for testing purposes 26 * **Remove Auto Tags** - Remove auto-added p and br tags from form output 27 * **Redirect After Submit** - Redirect users to a custom URL after successful submission 28 * Support for ACF fields to get dynamic redirect URL from current page 29 * Option to open redirect URL in new tab 30 * Option to force file download 31 * **Hide Form After Submit** - Hide the form and show only success message 32 * **Disable Submit Button** - Prevent double submissions by disabling button during form submission 33 * **Pre-fill Fields from URL** - Auto-fill form fields from URL parameters (e.g., ?your-email=test@example.com) 34 * **GA/GTM Event** - Send custom event to Google Analytics/GTM dataLayer on successful submission 35 * **Scroll to Message** - Automatically scroll to success/error message after form submission 36 * **Auto-hide Success Message** - Automatically hide success message after specified seconds 37 * **Remove Refill** - Clear form fields after validation error 23 38 24 To improve the plugin's functions and add new functions, write to us on the support [forum](https://wordpress.org/support/plugin/cf7-coder/) . 39 = Performance = 40 * **Conditional Script Loading** - Load CF7 scripts and styles only on pages with contact form shortcode 41 42 To improve the plugin's functions and add new functions, write to us on the support [forum](https://wordpress.org/support/plugin/cf7-coder/). 25 43 26 44 = Support = … … 40 58 41 59 == Changelog == 60 = 1.0 = 61 * Added: Redirect after submit with URL input 62 * Added: ACF field support for dynamic redirect URL 63 * Added: Open redirect in new tab option 64 * Added: Force download option for redirect URL 65 * Added: Hide form after submit (show only success message) 66 * Added: Disable submit button while sending to prevent double submissions 67 * Added: Pre-fill form fields from URL parameters 68 * Added: GA/GTM Event tracking on successful form submission 69 * Added: Scroll to message after form submission 70 * Added: Auto-hide success message with configurable timeout 71 * Added: Remove refill option (clear fields after validation error) 72 * Added: Conditional loading of CF7 scripts only on pages with shortcode 73 * Improved: Tag generator integration with CodeMirror editor 74 42 75 = 0.2 = 43 76 * Added: Dark theme support.
Note: See TracChangeset
for help on using the changeset viewer.