Contact Form 7 Redirection - Version 1.2.7

Version Description

  • Script field now accepts special characters, such as < and >.
Download this release

Release Info

Developer yuvalsabar
Plugin Icon 128x128 Contact Form 7 Redirection
Version 1.2.7
Comparing to
See all releases

Code changes from version 1.0.1 to 1.2.7

admin/wpcf7-redirect-admin-script.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+ jQuery( '#wpcf7-redirect-open-in-new-tab' ).change(function() {
3
+ if ( jQuery( this ).is( ":checked" ) ) {
4
+ jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
5
+ } else {
6
+ jQuery( '.field-notice-alert' ).addClass( 'field-notice-hidden' );
7
+ }
8
+ });
9
+
10
+ if ( jQuery( '[name="wpcf7-redirect-open-in-new-tab"]' ).is( ":checked" ) ) {
11
+ jQuery( '.field-notice-alert' ).removeClass( 'field-notice-hidden' );
12
+ }
13
+
14
+ jQuery( '#wpcf7-redirect-after-sent-script' ).keyup(function(event) {
15
+ if ( ! jQuery(this).val().length == 0 ) {
16
+ jQuery( '.field-warning-alert' ).removeClass( 'field-notice-hidden' );
17
+ } else {
18
+ jQuery( '.field-warning-alert' ).addClass( 'field-notice-hidden' );
19
+ }
20
+ });
21
+ });
admin/wpcf7-redirect-admin-style.css ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #redirect-panel .field-wrap {
2
+ margin-bottom: 10px;
3
+ }
4
+ #redirect-panel .field-wrap [type='url'],
5
+ #redirect-panel .field-wrap [type='select'] {
6
+ height: 28px;
7
+ }
8
+ #redirect-panel .field-wrap [type='url'] {
9
+ width: 100%;
10
+ }
11
+ #redirect-panel .field-wrap [type='checkbox'] {
12
+ margin-top: 1px;
13
+ }
14
+ #redirect-panel .field-wrap textarea {
15
+ direction: ltr;
16
+ width: 100%;
17
+ }
18
+ #redirect-panel .field-wrap-after-sent-script {
19
+ margin-top: 10px;
20
+ }
21
+ #redirect-panel .field-wrap-after-sent-script label {
22
+ display: block;
23
+ }
24
+ #redirect-panel .field-wrap-after-sent-script .field-message {
25
+ margin-bottom: 10px;
26
+ }
27
+ #redirect-panel .field-notice {
28
+ margin-top: 10px;
29
+ margin-bottom: 20px;
30
+ padding: 15px;
31
+ border: 1px solid;
32
+ border-radius: 4px;
33
+ background: #fff;
34
+ }
35
+ #redirect-panel .field-notice-alert {
36
+ color: #8a6d3b;
37
+ border: 1px solid #faebcc;
38
+ background-color: #fcf8e3;
39
+ }
40
+ #redirect-panel .field-notice-hidden {
41
+ display: none;
42
+ }
43
+ #redirect-panel .field-warning-alert {
44
+ color: #a94442;
45
+ border-color: #ebccd1;
46
+ background-color: #f2dede;
47
+ }
js/wpcf7-redirect-script.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ wpcf7_redirect_mailsent_handler();
3
+ });
4
+
5
+ function wpcf7_redirect_mailsent_handler() {
6
+ document.addEventListener( 'wpcf7mailsent', function( event ) {
7
+ form = wpcf7_redirect_forms [ event.detail.contactFormId ];
8
+
9
+ // Script to run after sent.
10
+ if ( form.after_sent_script ) {
11
+ eval( form.after_sent_script );
12
+ }
13
+
14
+ // Redirect to external URL.
15
+ if ( form.use_external_url && form.external_url ) {
16
+ if ( form.http_build_query ) {
17
+ // Build http query
18
+ http_query = jQuery.param( event.detail.inputs, true );
19
+ form.external_url = form.external_url + '?' + http_query;
20
+ }
21
+
22
+ if ( ! form.open_in_new_tab ) {
23
+ // Open in current tab
24
+ location.href = form.external_url;
25
+ } else {
26
+ // Open in external tab
27
+ window.open( form.external_url );
28
+ }
29
+ }
30
+
31
+ // Redirect to a page in this site.
32
+ else if ( form.thankyou_page_url ) {
33
+ if ( form.http_build_query ) {
34
+ // Build http query
35
+ http_query = jQuery.param( event.detail.inputs, true );
36
+ form.thankyou_page_url = form.thankyou_page_url + '?' + http_query;
37
+ }
38
+
39
+ if ( ! form.open_in_new_tab ) {
40
+ // Open in current tab
41
+ location.href = form.thankyou_page_url;
42
+ } else {
43
+ // Open in new tab
44
+ window.open( form.thankyou_page_url );
45
+ }
46
+ }
47
+
48
+ }, false );
49
+ }
lang/readme.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ Translations have moved to https://translate.wordpress.org/projects/wp-plugins/wpcf7-redirect
2
+
3
+ Your are more than welcome contribute :)
readme.txt ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Contact Form 7 Redirection ===
2
+ Tags: contact form 7 redirect, contact form 7 thank you page, redirect cf7, redirect contact form 7, contact form 7 success page, cf7 redirect
3
+ Contributors: yuvalsabar
4
+ Requires at least: 4.7.0
5
+ Tested up to: 4.9.7
6
+ Stable tag: 1.2.7
7
+ License: GPLv3 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
+
10
+ A simple add-on for Contact Form 7 that adds a redirect option after form sent successfully.
11
+
12
+ == Description ==
13
+
14
+ A straightforward add-on plugin for Contact Form 7 - adds the option to redirect to any page you choose after mail sent successfully, with DOM Events and without AJAX being disabled.
15
+ NOTE: This plugin requires Contact Form 7 version 4.8 or later.
16
+
17
+ == Usage ==
18
+
19
+ Simply go to your form settings, choose the "Redirect Settings" tab and set the page you want to be redirected to.
20
+
21
+ == Installation ==
22
+
23
+ Installing Contact Form 7 Redirection can be done either by searching for "Contact Form 7 Redirection" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
24
+
25
+ 1. Download the plugin via WordPress.org.
26
+ 2. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
27
+ 3. Activate the plugin through the 'Plugins' menu in WordPress
28
+ 4. Visit the settings screen and configure, as desired.
29
+
30
+ == Frequently Asked Questions ==
31
+
32
+ = Does the plugin disables Contact Form 7 Ajax? =
33
+
34
+ No, it doesn't. The plugin does not disables any of Contact Form 7 normal behavior, unlike all other plugins that do the same.
35
+
36
+ = Does this plugin uses "on_sent_ok" additional setting? =
37
+
38
+ No. One of the reasons we developed this plugin, is because on_send_ok is now deprecated, and is going to be abolished by the end of 2017. This plugin is the only redirect plugin for Contact Form 7 that has been updated to use [DOM events](https://contactform7.com/dom-events/) to perform redirect, as Contact Form 7 developer Takayuki Miyoshi recommends.
39
+
40
+ == Screenshots ==
41
+
42
+ 1. Redirect Settings tab
43
+
44
+ == Changelog ==
45
+
46
+ = 1.2.7 =
47
+ * Script field now accepts special characters, such as < and >.
48
+
49
+ = 1.2.6 =
50
+ * Added support for browsers that don't support AJAX.
51
+ * Minor CSS changes.
52
+
53
+ = 1.2.5 =
54
+ * Added error message if Contact Form 7 version is earlier than 4.8.
55
+
56
+ = 1.2.4 =
57
+ * Fixed a bug regarding sanitizing URL, causing & to change to #038;
58
+ * Unnecessary variables removed.
59
+
60
+ = 1.2.2 =
61
+ * New feature: Pass fields from the form as URL query parameters.
62
+ * Minor CSS changes.
63
+ * Dev improvements.
64
+
65
+ = 1.2 =
66
+ * Added option to add script after the form has been sent successfully.
67
+
68
+ = 1.0.2 =
69
+ * Added full support for form duplication.
70
+ * Added option to open page in a new tab.
71
+ * Added plugin class CF7_Redirect.
72
+
73
+ = 1.0.0 =
74
+ * Initial release.
tags/1.0.0/languages/wpcf7-redirect-he_IL.mo DELETED
Binary file
tags/1.0.0/languages/wpcf7-redirect-he_IL.po DELETED
@@ -1,54 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: \n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2017-08-10 22:50+0000\n"
6
- "PO-Revision-Date: 2017-08-10 22:51+0000\n"
7
- "Last-Translator: superuser <yuvalsabar@gmail.com>\n"
8
- "Language-Team: Hebrew\n"
9
- "Language: he-IL\n"
10
- "Plural-Forms: nplurals=2; plural=n != 1\n"
11
- "MIME-Version: 1.0\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
- "Content-Transfer-Encoding: 8bit\n"
14
- "X-Generator: Loco - https://localise.biz/"
15
-
16
- #: wpcf7-redirect.php:146
17
- msgid "Choose Page"
18
- msgstr "בחר דף"
19
-
20
- #: wpcf7-redirect.php:165
21
- msgid "External URL"
22
- msgstr "כתובת URL חיצונית"
23
-
24
- #: wpcf7-redirect.php:170
25
- msgid "Use external URL"
26
- msgstr "השתמש בכתובת URL חיצונית"
27
-
28
- #. Name of the plugin
29
- msgid "WPCF7 Redirect"
30
- msgstr "טפסי צרו קשר 7 - דפי תודה"
31
-
32
- #: wpcf7-redirect.php:99
33
- msgid "Error: Please update Contact Form 7."
34
- msgstr "שגיאה: בבקשה עדכן את Contact Form 7"
35
-
36
- #: wpcf7-redirect.php:112
37
- msgid "Error: Please install and activate Contact Form 7."
38
- msgstr "שגיאה: בבקשה התקן והפעל את Contact Form 7"
39
-
40
- #: wpcf7-redirect.php:126 wpcf7-redirect.php:153
41
- msgid "Redirect Settings"
42
- msgstr "הגדרות הפנייה"
43
-
44
- #: wpcf7-redirect.php:157
45
- msgid "Select a page to redirect to on successful form submission."
46
- msgstr "בחר דף לביצוע הפנייה לאחר שהטופס נשלח בהצלחה."
47
-
48
- #. Description of the plugin
49
- msgid "WPCF7 Add-on (CF7 >= 4.2) - Redirect after mail sent"
50
- msgstr "טופס ל-Contact Form - הפנייה לאחר שהטופס נשלח בהצלחה"
51
-
52
- #. Author of the plugin
53
- msgid "Yuval Tsabar"
54
- msgstr "יובל צבר"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tags/1.0.0/readme.txt DELETED
@@ -1,48 +0,0 @@
1
- === WPCF7 Redirect ===
2
- Tags: WPCF7, Contact Form 7 Redirect
3
- Requires at least: 4.0.0
4
- Tested up to: 4.8.1
5
- Stable tag: 1.0.0
6
- License: GPLv3 or later
7
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
8
-
9
- WPCF7 Redirect Plugin
10
-
11
- == Description ==
12
-
13
- WPCF7 Add-on (CF7 >= 4.2) - Redirect to any page you choose after mail sent successfully, with DOM Events and without AJAX being disabled.
14
- NOTE: This plugin requires Contact Form 7 version 4.2 or later.
15
-
16
- == Usage ==
17
-
18
- Place some text here, explaining how to use this plugin. Keep it clear and easy to read (short sentences).
19
-
20
- == Installation ==
21
-
22
- Installing "Starter Plugin" can be done either by searching for "Starter Plugin" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
23
-
24
- 1. Download the plugin via WordPress.org.
25
- 1. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
26
- 1. Activate the plugin through the 'Plugins' menu in WordPress
27
- 1. Visit the settings screen and configure, as desired.
28
-
29
- == Frequently Asked Questions ==
30
-
31
- = How do I contribute? =
32
-
33
- We encourage everyone to contribute their ideas, thoughts and code snippets. This can be done by forking the [repository over at GitHub](http://github.com/mattyza/starter-plugin/).
34
-
35
- == Screenshots ==
36
-
37
- 1. The settings screen.
38
-
39
-
40
- == Upgrade Notice ==
41
-
42
- = 1.0.0 =
43
- * Initial release.
44
-
45
- == Changelog ==
46
-
47
- = 1.0.0 =
48
- * Initial release.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tags/1.0.0/wpcf7-redirect-script.js DELETED
@@ -1,15 +0,0 @@
1
- jQuery(document).ready(function() {
2
- wpcf7_redirect_mailsent_handler();
3
- });
4
-
5
- function wpcf7_redirect_mailsent_handler() {
6
- document.addEventListener( 'wpcf7mailsent', function( event ) {
7
- form = wpcf7_redirect_forms [ event.detail.contactFormId ];
8
- if ( form.use_external_url && form.external_url ) {
9
- location = form.external_url;
10
- }
11
- else if ( form.thankyou_page_url ) {
12
- location = form.thankyou_page_url;
13
- }
14
- }, false );
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tags/1.0.0/wpcf7-redirect-style.css DELETED
@@ -1,14 +0,0 @@
1
- #redirect-panel .field-wrap {
2
- margin-bottom: 10px;
3
- }
4
- #redirect-panel .field-wrap [type='url'],
5
- #redirect-panel .field-wrap [type='select'] {
6
- height: 28px;
7
- }
8
- #redirect-panel .field-wrap [type='url'] {
9
- width: 350px;
10
- max-width: 100%;
11
- }
12
- .rtl #redirect-panel [type=url] {
13
- direction: rtl;
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tags/1.0.0/wpcf7-redirect.php DELETED
@@ -1,220 +0,0 @@
1
- <?php
2
- /**
3
- * Plugin Name: WPCF7 Redirect
4
- * Description: WPCF7 Add-on (CF7 >= 4.2) - Redirect after mail sent
5
- * Version: 1.0.0
6
- * Author: Yuval Tsabar
7
- * Requires at least: 4.0.0
8
- * Tested up to: 4.0.0
9
- *
10
- * Text Domain: wpcf7-redirect
11
- * Domain Path: /languages/
12
- *
13
- * @package WPCF7 Redirect
14
- * @category WPCF7 Add-Ons
15
- * @author Yuval Sabar
16
- */
17
-
18
- /**
19
- * Load plugin textdomain.
20
- */
21
- function wpcf7_redirect_load_textdomain() {
22
- load_plugin_textdomain( 'wpcf7-redirect', false, basename( dirname( __FILE__ ) ) . '/languages' );
23
- }
24
- add_action( 'plugins_loaded', 'wpcf7_redirect_load_textdomain' );
25
-
26
- /**
27
- * Enqueue theme styles and scripts - Back-End
28
- */
29
- function wpcf7_redirect_scripts_backend() {
30
- $plugin_dir = plugin_dir_url( __FILE__ );
31
- wp_enqueue_style( 'wpcf7-redirect-style', $plugin_dir . 'wpcf7-redirect-style.css' );
32
- }
33
- add_action( 'admin_enqueue_scripts', 'wpcf7_redirect_scripts_backend' );
34
-
35
- /**
36
- * Enqueue theme styles and scripts - Front-End
37
- */
38
- function wpcf7_redirect_scripts_frontend() {
39
- $plugin_dir = plugin_dir_url( __FILE__ );
40
-
41
- wp_enqueue_script( 'wpcf7-redirect-script', $plugin_dir . 'wpcf7-redirect-script.js', array(), null, true );
42
- wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', wpcf7_redirect_get_forms() );
43
- }
44
- add_action( 'wp_enqueue_scripts', 'wpcf7_redirect_scripts_frontend' );
45
-
46
- /**
47
- * Get WPCF7 Forms ID's and it's Thank You Page.
48
- * @return array
49
- */
50
- function wpcf7_redirect_get_forms() {
51
- $args = array(
52
- 'post_type' => 'wpcf7_contact_form',
53
- 'posts_per_page' => -1,
54
- );
55
- $query = new WP_Query( $args );
56
-
57
- if ( $query->have_posts() ) :
58
-
59
- while ( $query->have_posts() ) : $query->the_post();
60
-
61
- $page_id = get_post_meta( get_the_ID(), '_wpcf7_redirect_page_id', true );
62
- $thankyou_page = $page_id ? get_permalink( $page_id ) : '';
63
- $external_url = get_post_meta( get_the_ID(), '_wpcf7_redirect_external_url', true );
64
- $use_external_url = get_post_meta( get_the_ID(), '_wpcf7_redirect_use_external_url', true );
65
-
66
- $forms[ get_the_ID() ] = array(
67
- 'thankyou_page_url' => $thankyou_page,
68
- 'external_url' => $external_url,
69
- 'use_external_url' => $use_external_url
70
- );
71
-
72
- endwhile; wp_reset_query();
73
-
74
- endif;
75
-
76
- return $forms;
77
- }
78
-
79
- /**
80
- * Verify CF7 dependencies.
81
- */
82
- function wpcf7_redirect_page_admin_notice() {
83
- // Verify that CF7 is active and updated to the required version (4.2.0).
84
- if ( is_plugin_active('contact-form-7/wp-contact-form-7.php') ) {
85
- $wpcf7_path = plugin_dir_path( dirname(__FILE__) ) . 'contact-form-7/wp-contact-form-7.php';
86
- $wpcf7_plugin_data = get_plugin_data( $wpcf7_path, false, false);
87
- $wpcf7_version = (int)preg_replace( '/[.]/', '', $wpcf7_plugin_data['Version'] );
88
- // CF7 drops the ending ".0" for new major releases (e.g. Version 4.0 instead of 4.0.0...which would make the above version "40")
89
- // We need to make sure this value has a digit in the 100s place.
90
- if ( $wpcf7_version < 100 ) {
91
- $wpcf7_version = $wpcf7_version * 10;
92
- }
93
- // If CF7 version is < 4.2.0.
94
- if ( $wpcf7_version < 420 ) {
95
- ?>
96
-
97
- <div class="error">
98
- <p>
99
- <?php esc_html_e( 'Error: Please update Contact Form 7.', 'wpcf7-redirect' );?>
100
- </p>
101
- </div>
102
-
103
- <?php
104
- }
105
- }
106
- // If it's not installed and activated, throw an error
107
- else {
108
- ?>
109
-
110
- <div class="error">
111
- <p>
112
- <?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
113
- </p>
114
- </div>
115
-
116
- <?php
117
- }
118
- }
119
- add_action( 'admin_notices', 'wpcf7_redirect_page_admin_notice' );
120
-
121
- /**
122
- * Adds a tab to the editor on the form edit page (CF7 >= 4.2)
123
- */
124
- function wpcf7_redirect_add_page_panels( $panels ) {
125
- $panels['redirect-panel'] = array(
126
- 'title' => __( 'Redirect Settings', 'wpcf7-redirect' ),
127
- 'callback' => 'wpcf7_redirect_page_panel_meta'
128
- );
129
- return $panels;
130
- }
131
- add_action( 'wpcf7_editor_panels', 'wpcf7_redirect_add_page_panels' );
132
-
133
- /**
134
- * Create the panel inputs (CF7 >= 4.2)
135
- */
136
- function wpcf7_redirect_page_panel_meta( $post ) {
137
- wp_nonce_field( 'wpcf7_redirect_page_metaboxes', 'wpcf7_redirect_page_metaboxes_nonce' );
138
- $wpcf7_redirect_page = get_post_meta( $post->id(), '_wpcf7_redirect_page_id', true );
139
- $wpcf7_redirect_external_url = get_post_meta( $post->id(), '_wpcf7_redirect_external_url', true );
140
- $wpcf7_redirect_use_external_url = get_post_meta( $post->id(), '_wpcf7_redirect_use_external_url', true );
141
-
142
- // The meta box content
143
- $dropdown_options = array (
144
- 'echo' => 0,
145
- 'name' => 'wpcf7-redirect-page-id',
146
- 'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
147
- 'option_none_value' => '0',
148
- 'selected' => $wpcf7_redirect_page
149
- );
150
- ?>
151
-
152
- <h3>
153
- <?php esc_html_e( 'Redirect Settings', 'wpcf7-redirect' );?>
154
- </h3>
155
- <fieldset>
156
- <legend>
157
- <?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
158
- </legend>
159
-
160
- <div class="field-wrap">
161
- <?php echo wp_dropdown_pages( $dropdown_options );?>
162
- </div>
163
-
164
- <div class="field-wrap">
165
- <input type="url" placeholder="<?php esc_html_e( 'External URL', 'wpcf7-redirect' );?>" name="wpcf7-redirect-external-url" value="<?php echo $wpcf7_redirect_external_url;?>">
166
- </div>
167
-
168
- <div class="field-wrap">
169
- <input type="checkbox" name="wpcf7-redirect-use-external-url" <?php checked( $wpcf7_redirect_use_external_url, 'on', true ); ?>/>
170
- <label for="wpcf7-redirect-use-external-url"><?php esc_html_e( 'Use external URL', 'wpcf7-redirect' );?></label>
171
- </div>
172
- </fieldset>
173
-
174
- <?php
175
- }
176
-
177
- /**
178
- * Store Form Data
179
- */
180
- function wpcf7_redirect_page_save_contact_form( $contact_form ) {
181
- $contact_form_id = $contact_form->id();
182
-
183
- if ( ! isset( $_POST ) || empty( $_POST ) ) {
184
- return;
185
- }
186
- else {
187
- // Verify that the nonce is valid.
188
- if ( ! wp_verify_nonce( $_POST['wpcf7_redirect_page_metaboxes_nonce'], 'wpcf7_redirect_page_metaboxes' ) ) {
189
- return;
190
- }
191
-
192
- // Validation and sanitize
193
- $page_id = isset( $_POST['wpcf7-redirect-page-id'] ) ? intval( $_POST['wpcf7-redirect-page-id'] ) : '';
194
- $external_url = isset( $_POST['wpcf7-redirect-external-url'] ) ? esc_url( filter_var( $_POST['wpcf7-redirect-external-url'], FILTER_SANITIZE_URL ) ) : '';
195
- $use_external_url = isset( $_POST['wpcf7-redirect-use-external-url'] ) ? sanitize_text_field( $_POST['wpcf7-redirect-use-external-url'] ) : '';
196
- $use_external_url = ( $external_url && $use_external_url ) ? 'on' : '';
197
-
198
- // Update the stored value
199
- update_post_meta( $contact_form_id, '_wpcf7_redirect_page_id', $page_id );
200
- update_post_meta( $contact_form_id, '_wpcf7_redirect_external_url', $external_url );
201
- update_post_meta( $contact_form_id, '_wpcf7_redirect_use_external_url', $use_external_url );
202
- }
203
- }
204
- add_action( 'wpcf7_after_save', 'wpcf7_redirect_page_save_contact_form' );
205
-
206
- /**
207
- * Copy Redirect page key and assign it to duplicate form
208
- */
209
- function wpcf7_redirect_page_after_form_create( $contact_form ) {
210
- $contact_form_id = $contact_form->id();
211
-
212
- // Get the old form ID
213
- if ( ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['_wpnonce'] ) ) {
214
- $post = intval( $_REQUEST['post'] );
215
- $old_form_id = get_post_meta( $post, '_wpcf7_redirect_page_id', true );
216
- }
217
- // Update the duplicated form
218
- update_post_meta( $contact_form_id, '_wpcf7_redirect_page_id', $old_form_id );
219
- }
220
- add_action( 'wpcf7_after_create', 'wpcf7_redirect_page_after_form_create' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/languages/wpcf7-redirect-he_IL.mo DELETED
Binary file
trunk/languages/wpcf7-redirect-he_IL.po DELETED
@@ -1,54 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: \n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2017-08-10 22:50+0000\n"
6
- "PO-Revision-Date: 2017-08-10 22:51+0000\n"
7
- "Last-Translator: superuser <yuvalsabar@gmail.com>\n"
8
- "Language-Team: Hebrew\n"
9
- "Language: he-IL\n"
10
- "Plural-Forms: nplurals=2; plural=n != 1\n"
11
- "MIME-Version: 1.0\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
- "Content-Transfer-Encoding: 8bit\n"
14
- "X-Generator: Loco - https://localise.biz/"
15
-
16
- #: wpcf7-redirect.php:146
17
- msgid "Choose Page"
18
- msgstr "בחר דף"
19
-
20
- #: wpcf7-redirect.php:165
21
- msgid "External URL"
22
- msgstr "כתובת URL חיצונית"
23
-
24
- #: wpcf7-redirect.php:170
25
- msgid "Use external URL"
26
- msgstr "השתמש בכתובת URL חיצונית"
27
-
28
- #. Name of the plugin
29
- msgid "WPCF7 Redirect"
30
- msgstr "טפסי צרו קשר 7 - דפי תודה"
31
-
32
- #: wpcf7-redirect.php:99
33
- msgid "Error: Please update Contact Form 7."
34
- msgstr "שגיאה: בבקשה עדכן את Contact Form 7"
35
-
36
- #: wpcf7-redirect.php:112
37
- msgid "Error: Please install and activate Contact Form 7."
38
- msgstr "שגיאה: בבקשה התקן והפעל את Contact Form 7"
39
-
40
- #: wpcf7-redirect.php:126 wpcf7-redirect.php:153
41
- msgid "Redirect Settings"
42
- msgstr "הגדרות הפנייה"
43
-
44
- #: wpcf7-redirect.php:157
45
- msgid "Select a page to redirect to on successful form submission."
46
- msgstr "בחר דף לביצוע הפנייה לאחר שהטופס נשלח בהצלחה."
47
-
48
- #. Description of the plugin
49
- msgid "WPCF7 Add-on (CF7 >= 4.2) - Redirect after mail sent"
50
- msgstr "טופס ל-Contact Form - הפנייה לאחר שהטופס נשלח בהצלחה"
51
-
52
- #. Author of the plugin
53
- msgid "Yuval Tsabar"
54
- msgstr "יובל צבר"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/readme.txt DELETED
@@ -1,42 +0,0 @@
1
- === CF7 Redirect ===
2
- Tags: contact form 7, cf7, contact forms 7, contact form, redirect, redirect for contact form 7, forms, form redirect, form, success pages, thank you pages, contact form 7 add-on, cf7 redirect, contact form 7 redirect, contact form 7 success
3
- Contributors: yuvalsabar
4
- Requires at least: 4.0.0
5
- Tested up to: 4.8.1
6
- Stable tag: 1.0.1
7
- License: GPLv3 or later
8
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
-
10
- A simple add-on for Contact Form 7 that adds a redirect option after form sent successfully.
11
-
12
- == Description ==
13
-
14
- A straightforward add-on plugin to Contact Form 7 - adds the option to redirect to any page you choose after mail sent successfully, with DOM Events and without AJAX being disabled.
15
- NOTE: This plugin requires Contact Form 7 version 4.2 or later.
16
-
17
- == Usage ==
18
-
19
- Simply go to your form settings, choose the "Redirect Settings" tab and set the page you want to be redirected to.
20
-
21
- == Installation ==
22
-
23
- Installing WCPF7 Redirect can be done either by searching for "WCPF7 Redirect" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
24
-
25
- 1. Download the plugin via WordPress.org.
26
- 1. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
27
- 1. Activate the plugin through the 'Plugins' menu in WordPress
28
- 1. Visit the settings screen and configure, as desired.
29
-
30
- == Screenshots ==
31
-
32
- 1. Redirect Settings tab
33
-
34
- == Upgrade Notice ==
35
-
36
- = 1.0.0 =
37
- * Initial release.
38
-
39
- == Changelog ==
40
-
41
- = 1.0.0 =
42
- * Initial release.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/screenshot-1.png DELETED
Binary file
trunk/wpcf7-redirect-script.js DELETED
@@ -1,15 +0,0 @@
1
- jQuery(document).ready(function() {
2
- wpcf7_redirect_mailsent_handler();
3
- });
4
-
5
- function wpcf7_redirect_mailsent_handler() {
6
- document.addEventListener( 'wpcf7mailsent', function( event ) {
7
- form = wpcf7_redirect_forms [ event.detail.contactFormId ];
8
- if ( form.use_external_url && form.external_url ) {
9
- location = form.external_url;
10
- }
11
- else if ( form.thankyou_page_url ) {
12
- location = form.thankyou_page_url;
13
- }
14
- }, false );
15
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/wpcf7-redirect-style.css DELETED
@@ -1,14 +0,0 @@
1
- #redirect-panel .field-wrap {
2
- margin-bottom: 10px;
3
- }
4
- #redirect-panel .field-wrap [type='url'],
5
- #redirect-panel .field-wrap [type='select'] {
6
- height: 28px;
7
- }
8
- #redirect-panel .field-wrap [type='url'] {
9
- width: 350px;
10
- max-width: 100%;
11
- }
12
- .rtl #redirect-panel [type=url] {
13
- direction: rtl;
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/wpcf7-redirect.php DELETED
@@ -1,221 +0,0 @@
1
- <?php
2
- /**
3
- * Plugin Name: CF7 Redirect
4
- * Description: Contact Form 7 Add-on - Redirect after mail sent
5
- * Version: 1.0.1
6
- * Author: Yuval Tsabar
7
- * Contributors: yuvalsabas
8
- * Requires at least: 4.0.0
9
- * Tested up to: 4.8.1
10
- *
11
- * Text Domain: wpcf7-redirect
12
- * Domain Path: /languages/
13
- *
14
- * @package CF7 Redirect
15
- * @category Contact Form 7 Add-Ons
16
- * @author Yuval Sabar
17
- */
18
-
19
- /**
20
- * Load plugin textdomain.
21
- */
22
- function wpcf7_redirect_load_textdomain() {
23
- load_plugin_textdomain( 'wpcf7-redirect', false, basename( dirname( __FILE__ ) ) . '/languages' );
24
- }
25
- add_action( 'plugins_loaded', 'wpcf7_redirect_load_textdomain' );
26
-
27
- /**
28
- * Enqueue theme styles and scripts - Back-End
29
- */
30
- function wpcf7_redirect_scripts_backend() {
31
- $plugin_dir = plugin_dir_url( __FILE__ );
32
- wp_enqueue_style( 'wpcf7-redirect-style', $plugin_dir . 'wpcf7-redirect-style.css' );
33
- }
34
- add_action( 'admin_enqueue_scripts', 'wpcf7_redirect_scripts_backend' );
35
-
36
- /**
37
- * Enqueue theme styles and scripts - Front-End
38
- */
39
- function wpcf7_redirect_scripts_frontend() {
40
- $plugin_dir = plugin_dir_url( __FILE__ );
41
-
42
- wp_enqueue_script( 'wpcf7-redirect-script', $plugin_dir . 'wpcf7-redirect-script.js', array(), null, true );
43
- wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', wpcf7_redirect_get_forms() );
44
- }
45
- add_action( 'wp_enqueue_scripts', 'wpcf7_redirect_scripts_frontend' );
46
-
47
- /**
48
- * Get WPCF7 Forms ID's and it's Thank You Page.
49
- * @return array
50
- */
51
- function wpcf7_redirect_get_forms() {
52
- $args = array(
53
- 'post_type' => 'wpcf7_contact_form',
54
- 'posts_per_page' => -1,
55
- );
56
- $query = new WP_Query( $args );
57
-
58
- if ( $query->have_posts() ) :
59
-
60
- while ( $query->have_posts() ) : $query->the_post();
61
-
62
- $page_id = get_post_meta( get_the_ID(), '_wpcf7_redirect_page_id', true );
63
- $thankyou_page = $page_id ? get_permalink( $page_id ) : '';
64
- $external_url = get_post_meta( get_the_ID(), '_wpcf7_redirect_external_url', true );
65
- $use_external_url = get_post_meta( get_the_ID(), '_wpcf7_redirect_use_external_url', true );
66
-
67
- $forms[ get_the_ID() ] = array(
68
- 'thankyou_page_url' => $thankyou_page,
69
- 'external_url' => $external_url,
70
- 'use_external_url' => $use_external_url
71
- );
72
-
73
- endwhile; wp_reset_query();
74
-
75
- endif;
76
-
77
- return $forms;
78
- }
79
-
80
- /**
81
- * Verify CF7 dependencies.
82
- */
83
- function wpcf7_redirect_page_admin_notice() {
84
- // Verify that CF7 is active and updated to the required version (4.2.0).
85
- if ( is_plugin_active('contact-form-7/wp-contact-form-7.php') ) {
86
- $wpcf7_path = plugin_dir_path( dirname(__FILE__) ) . 'contact-form-7/wp-contact-form-7.php';
87
- $wpcf7_plugin_data = get_plugin_data( $wpcf7_path, false, false);
88
- $wpcf7_version = (int)preg_replace( '/[.]/', '', $wpcf7_plugin_data['Version'] );
89
- // CF7 drops the ending ".0" for new major releases (e.g. Version 4.0 instead of 4.0.0...which would make the above version "40")
90
- // We need to make sure this value has a digit in the 100s place.
91
- if ( $wpcf7_version < 100 ) {
92
- $wpcf7_version = $wpcf7_version * 10;
93
- }
94
- // If CF7 version is < 4.2.0.
95
- if ( $wpcf7_version < 420 ) {
96
- ?>
97
-
98
- <div class="error">
99
- <p>
100
- <?php esc_html_e( 'Error: Please update Contact Form 7.', 'wpcf7-redirect' );?>
101
- </p>
102
- </div>
103
-
104
- <?php
105
- }
106
- }
107
- // If it's not installed and activated, throw an error
108
- else {
109
- ?>
110
-
111
- <div class="error">
112
- <p>
113
- <?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
114
- </p>
115
- </div>
116
-
117
- <?php
118
- }
119
- }
120
- add_action( 'admin_notices', 'wpcf7_redirect_page_admin_notice' );
121
-
122
- /**
123
- * Adds a tab to the editor on the form edit page (CF7 >= 4.2)
124
- */
125
- function wpcf7_redirect_add_page_panels( $panels ) {
126
- $panels['redirect-panel'] = array(
127
- 'title' => __( 'Redirect Settings', 'wpcf7-redirect' ),
128
- 'callback' => 'wpcf7_redirect_page_panel_meta'
129
- );
130
- return $panels;
131
- }
132
- add_action( 'wpcf7_editor_panels', 'wpcf7_redirect_add_page_panels' );
133
-
134
- /**
135
- * Create the panel inputs (CF7 >= 4.2)
136
- */
137
- function wpcf7_redirect_page_panel_meta( $post ) {
138
- wp_nonce_field( 'wpcf7_redirect_page_metaboxes', 'wpcf7_redirect_page_metaboxes_nonce' );
139
- $wpcf7_redirect_page = get_post_meta( $post->id(), '_wpcf7_redirect_page_id', true );
140
- $wpcf7_redirect_external_url = get_post_meta( $post->id(), '_wpcf7_redirect_external_url', true );
141
- $wpcf7_redirect_use_external_url = get_post_meta( $post->id(), '_wpcf7_redirect_use_external_url', true );
142
-
143
- // The meta box content
144
- $dropdown_options = array (
145
- 'echo' => 0,
146
- 'name' => 'wpcf7-redirect-page-id',
147
- 'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
148
- 'option_none_value' => '0',
149
- 'selected' => $wpcf7_redirect_page
150
- );
151
- ?>
152
-
153
- <h3>
154
- <?php esc_html_e( 'Redirect Settings', 'wpcf7-redirect' );?>
155
- </h3>
156
- <fieldset>
157
- <legend>
158
- <?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
159
- </legend>
160
-
161
- <div class="field-wrap">
162
- <?php echo wp_dropdown_pages( $dropdown_options );?>
163
- </div>
164
-
165
- <div class="field-wrap">
166
- <input type="url" placeholder="<?php esc_html_e( 'External URL', 'wpcf7-redirect' );?>" name="wpcf7-redirect-external-url" value="<?php echo $wpcf7_redirect_external_url;?>">
167
- </div>
168
-
169
- <div class="field-wrap">
170
- <input type="checkbox" name="wpcf7-redirect-use-external-url" <?php checked( $wpcf7_redirect_use_external_url, 'on', true ); ?>/>
171
- <label for="wpcf7-redirect-use-external-url"><?php esc_html_e( 'Use external URL', 'wpcf7-redirect' );?></label>
172
- </div>
173
- </fieldset>
174
-
175
- <?php
176
- }
177
-
178
- /**
179
- * Store Form Data
180
- */
181
- function wpcf7_redirect_page_save_contact_form( $contact_form ) {
182
- $contact_form_id = $contact_form->id();
183
-
184
- if ( ! isset( $_POST ) || empty( $_POST ) ) {
185
- return;
186
- }
187
- else {
188
- // Verify that the nonce is valid.
189
- if ( ! wp_verify_nonce( $_POST['wpcf7_redirect_page_metaboxes_nonce'], 'wpcf7_redirect_page_metaboxes' ) ) {
190
- return;
191
- }
192
-
193
- // Validation and sanitize
194
- $page_id = isset( $_POST['wpcf7-redirect-page-id'] ) ? intval( $_POST['wpcf7-redirect-page-id'] ) : '';
195
- $external_url = isset( $_POST['wpcf7-redirect-external-url'] ) ? esc_url( filter_var( $_POST['wpcf7-redirect-external-url'], FILTER_SANITIZE_URL ) ) : '';
196
- $use_external_url = isset( $_POST['wpcf7-redirect-use-external-url'] ) ? sanitize_text_field( $_POST['wpcf7-redirect-use-external-url'] ) : '';
197
- $use_external_url = ( $external_url && $use_external_url ) ? 'on' : '';
198
-
199
- // Update the stored value
200
- update_post_meta( $contact_form_id, '_wpcf7_redirect_page_id', $page_id );
201
- update_post_meta( $contact_form_id, '_wpcf7_redirect_external_url', $external_url );
202
- update_post_meta( $contact_form_id, '_wpcf7_redirect_use_external_url', $use_external_url );
203
- }
204
- }
205
- add_action( 'wpcf7_after_save', 'wpcf7_redirect_page_save_contact_form' );
206
-
207
- /**
208
- * Copy Redirect page key and assign it to duplicate form
209
- */
210
- function wpcf7_redirect_page_after_form_create( $contact_form ) {
211
- $contact_form_id = $contact_form->id();
212
-
213
- // Get the old form ID
214
- if ( ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['_wpnonce'] ) ) {
215
- $post = intval( $_REQUEST['post'] );
216
- $old_form_id = get_post_meta( $post, '_wpcf7_redirect_page_id', true );
217
- }
218
- // Update the duplicated form
219
- update_post_meta( $contact_form_id, '_wpcf7_redirect_page_id', $old_form_id );
220
- }
221
- add_action( 'wpcf7_after_create', 'wpcf7_redirect_page_after_form_create' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wpcf7-redirect.php ADDED
@@ -0,0 +1,410 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Contact Form 7 Redirection
4
+ * Plugin URI: http://querysol.com/blog/product/contact-form-7-redirection/
5
+ * Description: Contact Form 7 Add-on - Redirect after mail sent.
6
+ * Version: 1.2.7
7
+ * Author: Query Solutions
8
+ * Author URI: http://querysol.com
9
+ * Contributors: querysolutions, yuvalsabar
10
+ * Requires at least: 4.7.0
11
+ *
12
+ * Text Domain: wpcf7-redirect
13
+ * Domain Path: /lang
14
+ *
15
+ * @package Contact Form 7 Redirection
16
+ * @category Contact Form 7 Addon
17
+ * @author Query Solutions
18
+ */
19
+
20
+ if ( ! defined( 'ABSPATH' ) ) {
21
+ exit;
22
+ }
23
+
24
+ /**
25
+ * Main WPCF7_Redirect Class
26
+ */
27
+ class WPCF7_Redirect {
28
+ /**
29
+ * Construct class
30
+ */
31
+ public function __construct() {
32
+ $this->plugin_url = plugin_dir_url( __FILE__ );
33
+ $this->plugin_path = plugin_dir_path( __FILE__ );
34
+ $this->version = '1.2.7';
35
+ $this->add_actions();
36
+ }
37
+
38
+ /**
39
+ * Add Actions
40
+ */
41
+ private function add_actions() {
42
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
43
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_backend' ) );
44
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend' ) );
45
+ add_action( 'wpcf7_editor_panels', array( $this, 'add_panel' ) );
46
+ add_action( 'wpcf7_after_save', array( $this, 'store_meta' ) );
47
+ add_action( 'wpcf7_after_create', array( $this, 'duplicate_form_support' ) );
48
+ add_action( 'wpcf7_submit', array( $this, 'non_ajax_redirection' ) );
49
+ add_action( 'admin_notices', array( $this, 'admin_notice' ) );
50
+ }
51
+
52
+ /**
53
+ * Load plugin textdomain.
54
+ */
55
+ public function load_textdomain() {
56
+ load_plugin_textdomain( 'wpcf7-redirect', false, basename( dirname( __FILE__ ) ) . '/lang' );
57
+ }
58
+
59
+ /**
60
+ * Enqueue theme styles and scripts - back-end
61
+ */
62
+ public function enqueue_backend() {
63
+ wp_enqueue_style( 'wpcf7-redirect-admin-style', $this->plugin_url . 'admin/wpcf7-redirect-admin-style.css' );
64
+ wp_enqueue_script( 'wpcf7-redirect-admin-script', $this->plugin_url . 'admin/wpcf7-redirect-admin-script.js', array(), null, true );
65
+ }
66
+
67
+ /**
68
+ * Enqueue theme styles and scripts - front-end
69
+ */
70
+ public function enqueue_frontend() {
71
+ wp_enqueue_script( 'wpcf7-redirect-script', $this->plugin_url . 'js/wpcf7-redirect-script.js', array(), null, true );
72
+ wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', $this->get_forms() );
73
+
74
+ if ( isset( $this->enqueue_new_tab_script ) && $this->enqueue_new_tab_script ){
75
+ wp_add_inline_script( 'wpcf7-redirect-script', 'window.open("'. $this->redirect_url .'");' );
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Adds a tab to the editor on the form edit page
81
+ *
82
+ * @param array $panels An array of panels. Each panel has a callback function.
83
+ */
84
+ public function add_panel( $panels ) {
85
+ $panels['redirect-panel'] = array(
86
+ 'title' => __( 'Redirect Settings', 'wpcf7-redirect' ),
87
+ 'callback' => array( $this, 'create_panel_inputs' ),
88
+ );
89
+ return $panels;
90
+ }
91
+
92
+ /**
93
+ * Create plugin fields
94
+ *
95
+ * @return array of plugin fields: name and type (type is for validation)
96
+ */
97
+ public function get_plugin_fields() {
98
+ $fields = array(
99
+ array(
100
+ 'name' => 'page_id',
101
+ 'type' => 'number',
102
+ ),
103
+ array(
104
+ 'name' => 'external_url',
105
+ 'type' => 'url',
106
+ ),
107
+ array(
108
+ 'name' => 'use_external_url',
109
+ 'type' => 'checkbox',
110
+ ),
111
+ array(
112
+ 'name' => 'http_build_query',
113
+ 'type' => 'checkbox',
114
+ ),
115
+ array(
116
+ 'name' => 'open_in_new_tab',
117
+ 'type' => 'checkbox',
118
+ ),
119
+ array(
120
+ 'name' => 'after_sent_script',
121
+ 'type' => 'textarea',
122
+ ),
123
+ );
124
+
125
+ return $fields;
126
+ }
127
+
128
+ /**
129
+ * Get all fields values
130
+ *
131
+ * @param integer $post_id Form ID.
132
+ * @return array of fields values keyed by fields name
133
+ */
134
+ public function get_fields_values( $post_id ) {
135
+ $fields = $this->get_plugin_fields();
136
+
137
+ foreach ( $fields as $field ) {
138
+ $values[ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'] , true );
139
+ }
140
+
141
+ return $values;
142
+ }
143
+
144
+ /**
145
+ * Validate and store meta data
146
+ *
147
+ * @param object $contact_form WPCF7_ContactForm Object - All data that is related to the form.
148
+ */
149
+ public function store_meta( $contact_form ) {
150
+ if ( ! isset( $_POST ) || empty( $_POST ) ) {
151
+ return;
152
+ } else {
153
+ if ( ! wp_verify_nonce( $_POST['wpcf7_redirect_page_metaboxes_nonce'], 'wpcf7_redirect_page_metaboxes' ) ) {
154
+ return;
155
+ }
156
+
157
+ $form_id = $contact_form->id();
158
+ $fields = $this->get_plugin_fields( $form_id );
159
+ $data = $_POST['wpcf7-redirect'];
160
+
161
+ foreach ( $fields as $field ) {
162
+ $value = isset( $data[ $field['name'] ] ) ? $data[ $field['name'] ] : '';
163
+
164
+ switch ( $field['type'] ) {
165
+ case 'text':
166
+ case 'checkbox':
167
+ $value = sanitize_text_field( $value );
168
+ break;
169
+
170
+ case 'textarea':
171
+ $value = $value;
172
+ break;
173
+
174
+ case 'number':
175
+ $value = intval( $value );
176
+ break;
177
+
178
+ case 'url':
179
+ $value = esc_url_raw( $value );
180
+ break;
181
+ }
182
+
183
+ update_post_meta( $form_id, '_wpcf7_redirect_' . $field['name'], $value );
184
+ }
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Push all forms redirect settings data into an array.
190
+ * @return array Form redirect settings data
191
+ */
192
+ public function get_forms() {
193
+ $args = array(
194
+ 'post_type' => 'wpcf7_contact_form',
195
+ 'posts_per_page' => -1,
196
+ );
197
+ $query = new WP_Query( $args );
198
+
199
+ if ( $query->have_posts() ) :
200
+
201
+ $fields = $this->get_plugin_fields();
202
+
203
+ while ( $query->have_posts() ) : $query->the_post();
204
+
205
+ $post_id = get_the_ID();
206
+
207
+ foreach ( $fields as $field ) {
208
+ $forms[ $post_id ][ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true );
209
+
210
+ if ( $field['type'] == 'textarea' ) {
211
+ $forms[ $post_id ][ $field['name'] ] = $forms[ $post_id ][ $field['name'] ];
212
+ }
213
+ }
214
+
215
+ // Thank you page URL is a little bit different...
216
+ $forms[ $post_id ]['thankyou_page_url'] = $forms[ $post_id ]['page_id'] ? get_permalink( $forms[ $post_id ]['page_id'] ) : '';
217
+ endwhile;
218
+ wp_reset_postdata();
219
+ endif;
220
+
221
+ return $forms;
222
+ }
223
+
224
+ /**
225
+ * Copy Redirect page key and assign it to duplicate form
226
+ *
227
+ * @param object $contact_form WPCF7_ContactForm Object - All data that is related to the form.
228
+ */
229
+ public function duplicate_form_support( $contact_form ) {
230
+ $contact_form_id = $contact_form->id();
231
+
232
+ if ( ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['_wpnonce'] ) ) {
233
+ $post_id = intval( $_REQUEST['post'] );
234
+
235
+ $fields = $this->get_plugin_fields();
236
+
237
+ foreach ( $fields as $field ) {
238
+ update_post_meta( $contact_form_id, '_wpcf7_redirect_' . $field['name'], get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true ) );
239
+ }
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Verify CF7 dependencies.
245
+ */
246
+ public function admin_notice() {
247
+ if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
248
+ $wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
249
+ $wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
250
+
251
+ // If CF7 version is < 4.8.
252
+ if ( $wpcf7_data['Version'] < 4.8 ) {
253
+ ?>
254
+
255
+ <div class="wpcf7-redirect-error error notice">
256
+ <h3>
257
+ <?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
258
+ </h3>
259
+ <p>
260
+ <?php esc_html_e( 'Error: Contact Form 7 version is too old. Contact Form Redirection is compatible from version 4.8 and above. Please update Contact Form 7.', 'wpcf7-redirect' );?>
261
+ </p>
262
+ </div>
263
+
264
+ <?php
265
+ }
266
+ } else {
267
+ // If CF7 isn't installed and activated, throw an error.
268
+ ?>
269
+ <div class="wpcf7-redirect-error error notice">
270
+ <h3>
271
+ <?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
272
+ </h3>
273
+ <p>
274
+ <?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
275
+ </p>
276
+ </div>
277
+
278
+ <?php
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Add plugin support to browsers that don't support ajax
284
+ */
285
+ public function non_ajax_redirection( $contact_form ) {
286
+ $this->fields = $this->get_fields_values( $contact_form->id() );
287
+
288
+ if ( isset( $this->fields ) && ! WPCF7_Submission::is_restful() ) {
289
+ $submission = WPCF7_Submission::get_instance();
290
+
291
+ if ( $submission->get_status() == 'mail_sent' ) {
292
+
293
+ // Use extrnal url
294
+ if ( $this->fields['external_url'] && $this->fields['use_external_url'] == 'on' ) {
295
+ $this->redirect_url = $this->fields['external_url'];
296
+ } else {
297
+ $this->redirect_url = get_permalink( $this->fields['page_id'] );
298
+ }
299
+
300
+ // Pass fields from the form as URL query parameters
301
+ if ( isset( $this->redirect_url ) && $this->redirect_url ) {
302
+ if ( $this->fields['http_build_query'] == 'on' ) {
303
+ $posted_data = $submission->get_posted_data();
304
+ // Remove WPCF7 keys from posted data
305
+ $remove_keys = array( '_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_container_post' );
306
+ $posted_data = array_diff_key( $posted_data, array_flip( $remove_keys ) );
307
+ $this->redirect_url = add_query_arg( $posted_data, $this->redirect_url );
308
+ }
309
+ }
310
+
311
+ // Open link in a new tab
312
+ if ( isset( $this->redirect_url ) && $this->redirect_url ) {
313
+ if ( $this->fields['open_in_new_tab'] == 'on' ) {
314
+ $this->enqueue_new_tab_script = true;
315
+ } else {
316
+ wp_redirect( $this->redirect_url );
317
+ exit;
318
+ }
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Create the panel inputs
326
+ *
327
+ * @param object $post Post object.
328
+ */
329
+ public function create_panel_inputs( $post ) {
330
+ wp_nonce_field( 'wpcf7_redirect_page_metaboxes', 'wpcf7_redirect_page_metaboxes_nonce' );
331
+
332
+ $fields = $this->get_fields_values( $post->id() );
333
+ ?>
334
+
335
+ <h2>
336
+ <?php esc_html_e( 'Redirect Settings', 'wpcf7-redirect' );?>
337
+ </h2>
338
+
339
+ <fieldset>
340
+ <legend>
341
+ <?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
342
+ </legend>
343
+
344
+ <div class="field-wrap field-wrap-page-id">
345
+ <?php
346
+ echo wp_dropdown_pages( array(
347
+ 'echo' => 0,
348
+ 'name' => 'wpcf7-redirect[page_id]',
349
+ 'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
350
+ 'option_none_value' => '0',
351
+ 'selected' => $fields['page_id'],
352
+ 'id' => 'page_id',
353
+ )
354
+ );
355
+ ?>
356
+ </div>
357
+
358
+ <div class="field-wrap field-wrap-external-url">
359
+ <input type="url" id="wpcf7-redirect-external-url" placeholder="<?php esc_html_e( 'External URL', 'wpcf7-redirect' );?>" name="wpcf7-redirect[external_url]" value="<?php echo $fields['external_url'];?>">
360
+ </div>
361
+
362
+ <div class="field-wrap field-wrap-use-external-url">
363
+ <input type="checkbox" id="wpcf7-redirect-use-external-url" name="wpcf7-redirect[use_external_url]" <?php checked( $fields['use_external_url'], 'on', true ); ?>/>
364
+ <label for="wpcf7-redirect-use-external-url">
365
+ <?php esc_html_e( 'Use external URL', 'wpcf7-redirect' );?>
366
+ </label>
367
+ </div>
368
+
369
+ <div class="field-wrap field-wrap-http-build-query">
370
+ <input type="checkbox" id="wpcf7-redirect-http-build-query" name="wpcf7-redirect[http_build_query]" <?php checked( $fields['http_build_query'], 'on', true ); ?>/>
371
+ <label for="wpcf7-redirect-http-build-query">
372
+ <?php esc_html_e( 'Pass fields from the form as URL query parameters', 'wpcf7-redirect' );?>
373
+ </label>
374
+ </div>
375
+
376
+ <div class="field-wrap field-wrap-open-in-new-tab">
377
+ <input type="checkbox" id="wpcf7-redirect-open-in-new-tab" name="wpcf7-redirect[open_in_new_tab]" <?php checked( $fields['open_in_new_tab'], 'on', true ); ?>/>
378
+ <label for="wpcf7-redirect-open-in-new-tab"><?php esc_html_e( 'Open page in a new tab', 'wpcf7-redirect' );?></label>
379
+ <div class="field-notice field-notice-alert field-notice-hidden">
380
+ <strong>
381
+ <?php esc_html_e( 'Notice!', 'wpcf7-redirect' );?>
382
+ </strong>
383
+ <?php esc_html_e( 'This option might not work as expected, since browsers often block popup windows. This option depends on the browser settings.', 'wpcf7-redirect' );?>
384
+ </div>
385
+ </div>
386
+
387
+ <hr />
388
+
389
+ <div class="field-wrap field-wrap-after-sent-script">
390
+ <label for="wpcf7-redirect-after-sent-script">
391
+ <?php esc_html_e( 'Here you can add scripts to run after form sent successfully.', 'wpcf7-redirect' );?>
392
+ </label>
393
+ <div class="field-message">
394
+ <?php esc_html_e( 'Do not include <script> tags.', 'wpcf7-redirect' );?>
395
+ </div>
396
+ <textarea id="wpcf7-redirect-after-sent-script" name="wpcf7-redirect[after_sent_script]" rows="8" cols="100"><?php echo $fields['after_sent_script'];?></textarea>
397
+ </div>
398
+ <div class="field-notice field-warning-alert field-notice-hidden">
399
+ <strong>
400
+ <?php esc_html_e( 'Warning!', 'wpcf7-redirect' );?>
401
+ </strong>
402
+ <?php esc_html_e( 'This option is for developers only - use with caution. If the plugin does not redirect after you have added scripts, it means you have a problem with your script. Either fix the script, or remove it.', 'wpcf7-redirect' );?>
403
+ </div>
404
+ </fieldset>
405
+
406
+ <?php
407
+ }
408
+ }
409
+
410
+ $cf7_redirect = new WPCF7_Redirect();