Contact Form 7 Redirection - Version 1.0.0

Version Description

  • Initial release.

=

Download this release

Release Info

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

Version 1.0.0

languages/wpcf7-redirect-he_IL.mo ADDED
Binary file
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 "יובל צבר"
readme.txt ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.
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
+ }
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
+ }
wpcf7-redirect.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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' );