Contact Form 7 Redirection - Version 1.2.2

Version Description

Download this release

Release Info

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

Code changes from version 1.0.1 to 1.2.2

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,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 textarea {
12
+ direction: ltr;
13
+ width: 100%;
14
+ }
15
+ #redirect-panel .field-wrap-after-sent-script {
16
+ margin-top: 10px;
17
+ }
18
+ #redirect-panel .field-wrap-after-sent-script label {
19
+ display: block;
20
+ }
21
+ #redirect-panel .field-wrap-after-sent-script .field-message {
22
+ margin-bottom: 10px;
23
+ }
24
+ #redirect-panel .field-notice {
25
+ margin-top: 10px;
26
+ margin-bottom: 20px;
27
+ padding: 15px;
28
+ border: 1px solid;
29
+ border-radius: 4px;
30
+ background: #fff;
31
+ }
32
+ #redirect-panel .field-notice-alert {
33
+ color: #8a6d3b;
34
+ border: 1px solid #faebcc;
35
+ background-color: #fcf8e3;
36
+ }
37
+ #redirect-panel .field-notice-hidden {
38
+ display: none;
39
+ }
40
+ #redirect-panel .field-warning-alert {
41
+ color: #a94442;
42
+ border-color: #ebccd1;
43
+ background-color: #f2dede;
44
+ }
js/wpcf7-redirect-script.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
15
+ // Redirect to external URL.
16
+ if ( form.use_external_url && form.external_url ) {
17
+ if ( form.http_build_query ) {
18
+ // Build http query
19
+ http_query = jQuery.param( event.detail.inputs, true );
20
+ form.external_url = form.external_url + '?' + http_query;
21
+ }
22
+
23
+ if ( ! form.open_in_new_tab ) {
24
+ // Open in current tab
25
+ location.href = form.external_url;
26
+ } else {
27
+ // Open in external tab
28
+ window.open( form.external_url );
29
+ }
30
+ }
31
+
32
+ // Redirect to a page in this site.
33
+ else if ( form.thankyou_page_url ) {
34
+ if ( form.http_build_query ) {
35
+ // Build http query
36
+ http_query = jQuery.param( event.detail.inputs, true );
37
+ form.thankyou_page_url = form.thankyou_page_url + '?' + http_query;
38
+ }
39
+
40
+ if ( ! form.open_in_new_tab ) {
41
+ // Open in current tab
42
+ location.href = form.thankyou_page_url;
43
+ } else {
44
+ // Open in new tab
45
+ window.open( form.thankyou_page_url );
46
+ }
47
+ }
48
+
49
+ }, false );
50
+ }
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,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.0.0
5
+ Tested up to: 4.9.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 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.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 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.1 =
47
+ * Fixed: redirection not working in old iOS versions.
48
+
49
+ = 1.2 =
50
+ * Added option to add script after the form has been sent successfully.
51
+
52
+ = 1.0.2 =
53
+ * Added full support for form duplication.
54
+ * Added option to open page in a new tab.
55
+ * Added plugin class CF7_Redirect.
56
+
57
+ = 1.0.0 =
58
+ * 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,361 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.2
7
+ * Author: Query Solutions
8
+ * Author URI: http://querysol.com
9
+ * Contributors: querysolutions, yuvalsabar
10
+ * Requires at least: 4.0
11
+ *
12
+ * Text Domain: wpcf7-redirect
13
+ * Domain Path: /languages
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.2';
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( 'admin_notices', array( $this, 'admin_notice' ) );
49
+ }
50
+
51
+ /**
52
+ * Load plugin textdomain.
53
+ */
54
+ public function load_textdomain() {
55
+ load_plugin_textdomain( 'wpcf7-redirect', false, basename( dirname( __FILE__ ) ) . '/lang' );
56
+ }
57
+
58
+ /**
59
+ * Enqueue theme styles and scripts - back-end
60
+ */
61
+ public function enqueue_backend() {
62
+ wp_enqueue_style( 'wpcf7-redirect-admin-style', $this->plugin_url . 'admin/wpcf7-redirect-admin-style.css' );
63
+ wp_enqueue_script( 'wpcf7-redirect-admin-script', $this->plugin_url . 'admin/wpcf7-redirect-admin-script.js', array(), null, true );
64
+ }
65
+
66
+ /**
67
+ * Enqueue theme styles and scripts - front-end
68
+ */
69
+ public function enqueue_frontend() {
70
+ wp_enqueue_script( 'wpcf7-redirect-script', $this->plugin_url . 'js/wpcf7-redirect-script.js', array(), null, true );
71
+ wp_localize_script( 'wpcf7-redirect-script', 'wpcf7_redirect_forms', $this->get_forms() );
72
+ }
73
+
74
+ /**
75
+ * Adds a tab to the editor on the form edit page
76
+ *
77
+ * @param array $panels An array of panels. Each panel has a callback function.
78
+ */
79
+ public function add_panel( $panels ) {
80
+ $panels['redirect-panel'] = array(
81
+ 'title' => __( 'Redirect Settings', 'wpcf7-redirect' ),
82
+ 'callback' => array( $this, 'create_panel_inputs' ),
83
+ );
84
+ return $panels;
85
+ }
86
+
87
+ /**
88
+ * Create plugin fields
89
+ *
90
+ * @return array of plugin fields: name and type (type is for validation)
91
+ */
92
+ public function get_plugin_fields() {
93
+ $fields = array(
94
+ array(
95
+ 'name' => 'page_id',
96
+ 'type' => 'number',
97
+ ),
98
+ array(
99
+ 'name' => 'external_url',
100
+ 'type' => 'url',
101
+ ),
102
+ array(
103
+ 'name' => 'use_external_url',
104
+ 'type' => 'checkbox',
105
+ ),
106
+ array(
107
+ 'name' => 'http_build_query',
108
+ 'type' => 'checkbox',
109
+ ),
110
+ array(
111
+ 'name' => 'open_in_new_tab',
112
+ 'type' => 'checkbox',
113
+ ),
114
+ array(
115
+ 'name' => 'after_sent_script',
116
+ 'type' => 'textarea',
117
+ ),
118
+ );
119
+
120
+ return $fields;
121
+ }
122
+
123
+ /**
124
+ * Get all fields values
125
+ *
126
+ * @param integer $post_id Form ID.
127
+ * @return array of fields values keyed by fields name
128
+ */
129
+ public function get_fields_values( $post_id ) {
130
+ $fields = $this->get_plugin_fields();
131
+
132
+ foreach ( $fields as $field ) {
133
+ $values[ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'] , true );
134
+ }
135
+
136
+ return $values;
137
+ }
138
+
139
+ /**
140
+ * Validate and store meta data
141
+ *
142
+ * @param object $contact_form WPCF7_ContactForm Object - All data that is related to the form.
143
+ */
144
+ public function store_meta( $contact_form ) {
145
+ if ( ! isset( $_POST ) || empty( $_POST ) ) {
146
+ return;
147
+ } else {
148
+ if ( ! wp_verify_nonce( $_POST['wpcf7_redirect_page_metaboxes_nonce'], 'wpcf7_redirect_page_metaboxes' ) ) {
149
+ return;
150
+ }
151
+
152
+ $form_id = $contact_form->id();
153
+ $fields = $this->get_plugin_fields( $form_id );
154
+ $data = $_POST['wpcf7-redirect'];
155
+
156
+ foreach ( $fields as $field ) {
157
+ $value = isset( $data[ $field['name'] ] ) ? $data[ $field['name'] ] : '';
158
+
159
+ switch ( $field['type'] ) {
160
+ case 'text':
161
+ case 'checkbox':
162
+ $value = sanitize_text_field( $value );
163
+ break;
164
+
165
+ case 'textarea':
166
+ $value = sanitize_textarea_field( $value );
167
+ break;
168
+
169
+ case 'number':
170
+ $value = intval( $value );
171
+ break;
172
+
173
+ case 'url':
174
+ $value = esc_url( filter_var( $value, FILTER_SANITIZE_URL ) );
175
+ break;
176
+ }
177
+
178
+ update_post_meta( $form_id, '_wpcf7_redirect_' . $field['name'], $value );
179
+ }
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Get CF7 Forms ID's and it's Thank You Page.
185
+ */
186
+ public function get_forms() {
187
+ $args = array(
188
+ 'post_type' => 'wpcf7_contact_form',
189
+ 'posts_per_page' => -1,
190
+ );
191
+ $query = new WP_Query( $args );
192
+
193
+ if ( $query->have_posts() ) :
194
+
195
+ $fields = $this->get_plugin_fields();
196
+
197
+ while ( $query->have_posts() ) : $query->the_post();
198
+
199
+ $post_id = get_the_ID();
200
+
201
+ foreach ( $fields as $field ) {
202
+ $forms[ $post_id ][ $field['name'] ] = get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true );
203
+
204
+ if ( $field['type'] == 'textarea' ) {
205
+ $forms[ $post_id ][ $field['name'] ] = sanitize_text_field( $forms[ $post_id ][ $field['name'] ] );
206
+ }
207
+ }
208
+
209
+ // Thank you page URL is a little bit different...
210
+ $forms[ $post_id ]['thankyou_page_url'] = $forms[ $post_id ]['page_id'] ? get_permalink( $forms[ $post_id ]['page_id'] ) : '';
211
+
212
+ endwhile;
213
+ wp_reset_postdata();
214
+
215
+ endif;
216
+
217
+ return $forms;
218
+ }
219
+
220
+ /**
221
+ * Copy Redirect page key and assign it to duplicate form
222
+ *
223
+ * @param object $contact_form WPCF7_ContactForm Object - All data that is related to the form.
224
+ */
225
+ public function duplicate_form_support( $contact_form ) {
226
+ $contact_form_id = $contact_form->id();
227
+
228
+ if ( ! empty( $_REQUEST['post'] ) && ! empty( $_REQUEST['_wpnonce'] ) ) {
229
+ $post_id = intval( $_REQUEST['post'] );
230
+
231
+ $fields = $this->get_plugin_fields();
232
+
233
+ foreach ( $fields as $field ) {
234
+ update_post_meta( $contact_form_id, '_wpcf7_redirect_' . $field['name'], get_post_meta( $post_id, '_wpcf7_redirect_' . $field['name'], true ) );
235
+ }
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Verify CF7 dependencies.
241
+ */
242
+ public function admin_notice() {
243
+ if ( is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) {
244
+ $wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
245
+ $wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
246
+
247
+ // If CF7 version is < 4.2.0.
248
+ if ( $wpcf7_data['Version'] < 4.2 ) {
249
+ ?>
250
+
251
+ <div class="error notice">
252
+ <p>
253
+ <?php esc_html_e( 'Error: Please update Contact Form 7.', 'wpcf7-redirect' );?>
254
+ </p>
255
+ </div>
256
+
257
+ <?php
258
+ }
259
+ } else {
260
+ // If CF7 isn't installed and activated, throw an error.
261
+ $wpcf7_path = plugin_dir_path( dirname( __FILE__ ) ) . 'contact-form-7/wp-contact-form-7.php';
262
+ $wpcf7_data = get_plugin_data( $wpcf7_path, false, false );
263
+ ?>
264
+
265
+ <div class="error notice">
266
+ <p>
267
+ <?php esc_html_e( 'Error: Please install and activate Contact Form 7.', 'wpcf7-redirect' );?>
268
+ </p>
269
+ </div>
270
+
271
+ <?php
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Create the panel inputs
277
+ *
278
+ * @param object $post Post object.
279
+ */
280
+ public function create_panel_inputs( $post ) {
281
+ wp_nonce_field( 'wpcf7_redirect_page_metaboxes', 'wpcf7_redirect_page_metaboxes_nonce' );
282
+
283
+ $fields = $this->get_fields_values( $post->id() );
284
+ ?>
285
+
286
+ <h2>
287
+ <?php esc_html_e( 'Redirect Settings', 'wpcf7-redirect' );?>
288
+ </h2>
289
+
290
+ <fieldset>
291
+ <legend>
292
+ <?php esc_html_e( 'Select a page to redirect to on successful form submission.', 'wpcf7-redirect' );?>
293
+ </legend>
294
+
295
+ <div class="field-wrap field-wrap-page-id">
296
+ <?php
297
+ echo wp_dropdown_pages( array(
298
+ 'echo' => 0,
299
+ 'name' => 'wpcf7-redirect[page_id]',
300
+ 'show_option_none' => __( 'Choose Page', 'wpcf7-redirect' ),
301
+ 'option_none_value' => '0',
302
+ 'selected' => $fields['page_id'],
303
+ 'id' => 'page_id',
304
+ )
305
+ );
306
+ ?>
307
+ </div>
308
+
309
+ <div class="field-wrap field-wrap-external-url">
310
+ <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'];?>">
311
+ </div>
312
+
313
+ <div class="field-wrap field-wrap-use-external-url">
314
+ <input type="checkbox" id="wpcf7-redirect-use-external-url" name="wpcf7-redirect[use_external_url]" <?php checked( $fields['use_external_url'], 'on', true ); ?>/>
315
+ <label for="wpcf7-redirect-use-external-url">
316
+ <?php esc_html_e( 'Use external URL', 'wpcf7-redirect' );?>
317
+ </label>
318
+ </div>
319
+
320
+ <div class="field-wrap field-wrap-http-build-query">
321
+ <input type="checkbox" id="wpcf7-redirect-http-build-query" name="wpcf7-redirect[http_build_query]" <?php checked( $fields['http_build_query'], 'on', true ); ?>/>
322
+ <label for="wpcf7-redirect-http-build-query">
323
+ <?php esc_html_e( 'Pass fields from the form as URL query parameters', 'wpcf7-redirect' );?>
324
+ </label>
325
+ </div>
326
+
327
+ <div class="field-wrap field-wrap-open-in-new-tab">
328
+ <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 ); ?>/>
329
+ <label for="wpcf7-redirect-open-in-new-tab"><?php esc_html_e( 'Open page in a new tab', 'wpcf7-redirect' );?></label>
330
+ <div class="field-notice field-notice-alert field-notice-hidden">
331
+ <strong>
332
+ <?php esc_html_e( 'Notice!', 'wpcf7-redirect' );?>
333
+ </strong>
334
+ <?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' );?>
335
+ </div>
336
+ </div>
337
+
338
+ <hr />
339
+
340
+ <div class="field-wrap field-wrap-after-sent-script">
341
+ <label for="wpcf7-redirect-after-sent-script">
342
+ <?php esc_html_e( 'Here you can add scripts to run after form sent successfully.', 'wpcf7-redirect' );?>
343
+ </label>
344
+ <div class="field-message">
345
+ <?php esc_html_e( 'Do not include <script> tags.', 'wpcf7-redirect' );?>
346
+ </div>
347
+ <textarea id="wpcf7-redirect-after-sent-script" name="wpcf7-redirect[after_sent_script]" rows="8" cols="100"><?php echo $fields['after_sent_script'];?></textarea>
348
+ </div>
349
+ <div class="field-notice field-warning-alert field-notice-hidden">
350
+ <strong>
351
+ <?php esc_html_e( 'Warning!', 'wpcf7-redirect' );?>
352
+ </strong>
353
+ <?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' );?>
354
+ </div>
355
+ </fieldset>
356
+
357
+ <?php
358
+ }
359
+ }
360
+
361
+ $cf7_redirect = new WPCF7_Redirect();