Contact Form 7 Redirection - Version 1.0.1

Version Description

Download this release

Release Info

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

Code changes from version 1.0.0 to 1.0.1

{languages → tags/1.0.0/languages}/wpcf7-redirect-he_IL.mo RENAMED
File without changes
{languages → tags/1.0.0/languages}/wpcf7-redirect-he_IL.po RENAMED
File without changes
readme.txt → tags/1.0.0/readme.txt RENAMED
File without changes
wpcf7-redirect-script.js → tags/1.0.0/wpcf7-redirect-script.js RENAMED
File without changes
wpcf7-redirect-style.css → tags/1.0.0/wpcf7-redirect-style.css RENAMED
File without changes
wpcf7-redirect.php → tags/1.0.0/wpcf7-redirect.php RENAMED
File without changes
trunk/languages/wpcf7-redirect-he_IL.mo ADDED
Binary file
trunk/languages/wpcf7-redirect-he_IL.po ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
Binary file
trunk/wpcf7-redirect-script.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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' );