Contact Form 7 Redirection - Version 1.2.6

Version Description

  • Added support for browsers that don't support AJAX.
  • Minor CSS changes.
Download this release

Release Info

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

Code changes from version 1.0.1 to 1.2.6

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,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.4
6
+ Stable tag: 1.2.6
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.6 =
47
+ * Added support for browsers that don't support AJAX.
48
+ * Minor CSS changes.
49
+
50
+ = 1.2.5 =
51
+ * Added error message if Contact Form 7 version is earlier than 4.8.
52
+
53
+ = 1.2.4 =
54
+ * Fixed a bug regarding sanitizing URL, causing & to change to #038;
55
+ * Unnecessary variables removed.
56
+
57
+ = 1.2.2 =
58
+ * New feature: Pass fields from the form as URL query parameters.
59
+ * Minor CSS changes.
60
+ * Dev improvements.
61
+
62
+ = 1.2 =
63
+ * Added option to add script after the form has been sent successfully.
64
+
65
+ = 1.0.2 =
66
+ * Added full support for form duplication.
67
+ * Added option to open page in a new tab.
68
+ * Added plugin class CF7_Redirect.
69
+
70
+ = 1.0.0 =
71
+ * 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,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.6
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.6';
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 = sanitize_textarea_field( $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'] ] = sanitize_text_field( $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
+
218
+ endwhile;
219
+ wp_reset_postdata();
220
+
221
+ endif;
222
+
223
+ return $forms;
224
+ }
225
+
226
+ /**
227
+ * Copy Redirect page key and assign it to duplicate form
228
+ *
229
+ * @param object $contact_form WPCF7_ContactForm Object - All data that is related to the form.
230
+ */
231
+ public function duplicate_form_support( $contact_form ) {
232
+ $contact_form_id = $contact_form->id();
233
+
234
+ if ( ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['_wpnonce'] ) ) {
235
+ $post_id = intval( $_REQUEST['post'] );
236
+
237
+ $fields = $this->get_plugin_fields();
238
+
239
+ foreach ( $fields as $field ) {
240
+ update_post_meta( $contact_form_id, '_wpcf7_redirect_' . $field['name'], get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true ) );
241
+ }
242
+ }
243
+ }
244
+
245
+ /**
246
+ * Verify CF7 dependencies.
247
+ */
248
+ public function admin_notice() {
249
+ if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
250
+ $wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
251
+ $wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
252
+
253
+ // If CF7 version is < 4.8.
254
+ if ( $wpcf7_data['Version'] < 4.8 ) {
255
+ ?>
256
+
257
+ <div class="wpcf7-redirect-error error notice">
258
+ <h3>
259
+ <?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
260
+ </h3>
261
+ <p>
262
+ <?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' );?>
263
+ </p>
264
+ </div>
265
+
266
+ <?php
267
+ }
268
+ } else {
269
+ // If CF7 isn't installed and activated, throw an error.
270
+ ?>
271
+ <div class="wpcf7-redirect-error error notice">
272
+ <h3>
273
+ <?php esc_html_e( 'Contact Form Redirection', 'wpcf7-redirect' );?>
274
+ </h3>
275
+ <p>
276
+ <?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
277
+ </p>
278
+ </div>
279
+
280
+ <?php
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Add plugin support to browsers that don't support ajax
286
+ */
287
+ public function non_ajax_redirection( $contact_form ) {
288
+ $this->fields = $this->get_fields_values( $contact_form->id() );
289
+
290
+ if ( isset( $this->fields ) && ! WPCF7_Submission::is_restful() ) {
291
+ $submission = WPCF7_Submission::get_instance();
292
+
293
+ if ( $submission->get_status() == 'mail_sent' ) {
294
+
295
+ // Use extrnal url
296
+ if ( $this->fields['external_url'] && $this->fields['use_external_url'] == 'on' ) {
297
+ $this->redirect_url = $this->fields['external_url'];
298
+ } else {
299
+ $this->redirect_url = get_permalink( $this->fields['page_id'] );
300
+ }
301
+
302
+ // Pass fields from the form as URL query parameters
303
+ if ( isset( $this->redirect_url ) && $this->redirect_url ) {
304
+ if ( $this->fields['http_build_query'] == 'on' ) {
305
+ $posted_data = $submission->get_posted_data();
306
+ // Remove WPCF7 keys from posted data
307
+ $remove_keys = array( '_wpcf7', '_wpcf7_version', '_wpcf7_locale', '_wpcf7_unit_tag', '_wpcf7_container_post' );
308
+ $posted_data = array_diff_key( $posted_data, array_flip( $remove_keys ) );
309
+ $this->redirect_url = add_query_arg( $posted_data, $this->redirect_url );
310
+ }
311
+ }
312
+
313
+ // Open link in a new tab
314
+ if ( isset( $this->redirect_url ) && $this->redirect_url ) {
315
+ if ( $this->fields['open_in_new_tab'] == 'on' ) {
316
+ $this->enqueue_new_tab_script = true;
317
+ } else {
318
+ wp_redirect( $this->redirect_url );
319
+ exit;
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Create the panel inputs
328
+ *
329
+ * @param object $post Post object.
330
+ */
331
+ public function create_panel_inputs( $post ) {
332
+ wp_nonce_field( 'wpcf7_redirect_page_metaboxes', 'wpcf7_redirect_page_metaboxes_nonce' );
333
+
334
+ $fields = $this->get_fields_values( $post->id() );
335
+ ?>
336
+
337
+ <h2>
338
+ <?php esc_html_e( 'Redirect Settings', 'wpcf7-redirect' );?>
339
+ </h2>
340
+
341
+ <fieldset>
342
+ <legend>
343
+ <?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
344
+ </legend>
345
+
346
+ <div class="field-wrap field-wrap-page-id">
347
+ <?php
348
+ echo wp_dropdown_pages( array(
349
+ 'echo' => 0,
350
+ 'name' => 'wpcf7-redirect[page_id]',
351
+ 'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
352
+ 'option_none_value' => '0',
353
+ 'selected' => $fields['page_id'],
354
+ 'id' => 'page_id',
355
+ )
356
+ );
357
+ ?>
358
+ </div>
359
+
360
+ <div class="field-wrap field-wrap-external-url">
361
+ <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'];?>">
362
+ </div>
363
+
364
+ <div class="field-wrap field-wrap-use-external-url">
365
+ <input type="checkbox" id="wpcf7-redirect-use-external-url" name="wpcf7-redirect[use_external_url]" <?php checked( $fields['use_external_url'], 'on', true ); ?>/>
366
+ <label for="wpcf7-redirect-use-external-url">
367
+ <?php esc_html_e( 'Use external URL', 'wpcf7-redirect' );?>
368
+ </label>
369
+ </div>
370
+
371
+ <div class="field-wrap field-wrap-http-build-query">
372
+ <input type="checkbox" id="wpcf7-redirect-http-build-query" name="wpcf7-redirect[http_build_query]" <?php checked( $fields['http_build_query'], 'on', true ); ?>/>
373
+ <label for="wpcf7-redirect-http-build-query">
374
+ <?php esc_html_e( 'Pass fields from the form as URL query parameters', 'wpcf7-redirect' );?>
375
+ </label>
376
+ </div>
377
+
378
+ <div class="field-wrap field-wrap-open-in-new-tab">
379
+ <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 ); ?>/>
380
+ <label for="wpcf7-redirect-open-in-new-tab"><?php esc_html_e( 'Open page in a new tab', 'wpcf7-redirect' );?></label>
381
+ <div class="field-notice field-notice-alert field-notice-hidden">
382
+ <strong>
383
+ <?php esc_html_e( 'Notice!', 'wpcf7-redirect' );?>
384
+ </strong>
385
+ <?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' );?>
386
+ </div>
387
+ </div>
388
+
389
+ <hr />
390
+
391
+ <div class="field-wrap field-wrap-after-sent-script">
392
+ <label for="wpcf7-redirect-after-sent-script">
393
+ <?php esc_html_e( 'Here you can add scripts to run after form sent successfully.', 'wpcf7-redirect' );?>
394
+ </label>
395
+ <div class="field-message">
396
+ <?php esc_html_e( 'Do not include <script> tags.', 'wpcf7-redirect' );?>
397
+ </div>
398
+ <textarea id="wpcf7-redirect-after-sent-script" name="wpcf7-redirect[after_sent_script]" rows="8" cols="100"><?php echo $fields['after_sent_script'];?></textarea>
399
+ </div>
400
+ <div class="field-notice field-warning-alert field-notice-hidden">
401
+ <strong>
402
+ <?php esc_html_e( 'Warning!', 'wpcf7-redirect' );?>
403
+ </strong>
404
+ <?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' );?>
405
+ </div>
406
+ </fieldset>
407
+
408
+ <?php
409
+ }
410
+ }
411
+
412
+ $cf7_redirect = new WPCF7_Redirect();