Contact Form 7 – Success Page Redirects - Version 1.1.6

Version Description

  • Fixes a bug where duplicating a contact form from the form list view wouldn't copy over the redirect field.
Download this release

Release Info

Developer rnevius
Plugin Icon 128x128 Contact Form 7 – Success Page Redirects
Version 1.1.6
Comparing to
See all releases

Code changes from version 1.1.5 to 1.1.6

Files changed (2) hide show
  1. cf7-success-page-redirects.php +64 -48
  2. readme.txt +4 -1
cf7-success-page-redirects.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Contact Form 7 - Success Page Redirects
4
  * Description: An add-on for Contact Form 7 that provides a straightforward method to redirect visitors to success pages or thank you pages.
5
- * Version: 1.1.5
6
  * Author: Ryan Nevius
7
  * Author URI: http://www.ryannevius.com
8
  * License: GPLv3
@@ -12,25 +12,25 @@
12
  * Verify CF7 dependencies.
13
  */
14
  function cf7_success_page_admin_notice() {
15
- // Verify that CF7 is active and updated to the required version (currently 3.9.0)
16
- if ( is_plugin_active('contact-form-7/wp-contact-form-7.php') ) {
17
- $wpcf7_path = plugin_dir_path( dirname(__FILE__) ) . 'contact-form-7/wp-contact-form-7.php';
18
- $wpcf7_plugin_data = get_plugin_data( $wpcf7_path, false, false);
19
- $wpcf7_version = (int)preg_replace('/[.]/', '', $wpcf7_plugin_data['Version']);
20
- // 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")
21
- // We need to make sure this value has a digit in the 100s place.
22
- if ( $wpcf7_version < 100 ) {
23
- $wpcf7_version = $wpcf7_version * 10;
24
- }
25
- // If CF7 version is < 3.9.0
26
- if ( $wpcf7_version < 390 ) {
27
- echo '<div class="error"><p><strong>Warning: </strong>Contact Form 7 - Success Page Redirects requires that you have the latest version of Contact Form 7 installed. Please upgrade now.</p></div>';
28
- }
29
- }
30
- // If it's not installed and activated, throw an error
31
  else {
32
- echo '<div class="error"><p>Contact Form 7 is not activated. The Contact Form 7 Plugin must be installed and activated before you can use Success Page Redirects.</p></div>';
33
- }
34
  }
35
  add_action( 'admin_notices', 'cf7_success_page_admin_notice' );
36
 
@@ -46,56 +46,72 @@ add_filter( 'wpcf7_load_js', '__return_false' );
46
  */
47
  // Register the meta boxes
48
  function cf7_success_page_settings() {
49
- add_meta_box( 'cf7-redirect-settings', 'Success Page Redirect', 'cf7_success_page_metaboxes', '', 'form', 'low');
50
  }
51
  add_action( 'wpcf7_add_meta_boxes', 'cf7_success_page_settings' );
52
 
53
  // Create the meta boxes
54
  function cf7_success_page_metaboxes( $post ) {
55
- wp_nonce_field( 'cf7_success_page_metaboxes', 'cf7_success_page_metaboxes_nonce' );
56
- $cf7_success_page = get_post_meta( $post->id(), '_cf7_success_page_key', true );
57
 
58
- // The meta box content
59
- echo '<label for="cf7-redirect-page-id"><strong>Redirect to: </strong></label><br> ';
60
- $dropdown_options = array (
61
- 'name' => 'cf7-redirect-page-id',
62
- 'show_option_none' => '--',
63
- 'option_none_value' => '0',
64
- 'selected' => $cf7_success_page
65
- );
66
- wp_dropdown_pages( $dropdown_options );
67
  }
68
 
69
  // Store Success Page Info
70
  function cf7_success_page_save_contact_form( $contact_form ) {
71
- $contact_form_id = $contact_form->id();
72
 
73
- if ( !isset( $_POST ) || empty( $_POST ) || !isset( $_POST['cf7-redirect-page-id'] ) ) {
74
- return;
75
- }
76
- else {
77
- // Verify that the nonce is valid.
78
- if ( ! wp_verify_nonce( $_POST['cf7_success_page_metaboxes_nonce'], 'cf7_success_page_metaboxes' ) ) {
79
- return;
80
- }
81
- // Update the stored value
82
  update_post_meta( $contact_form_id, '_cf7_success_page_key', $_POST['cf7-redirect-page-id'] );
83
  }
84
  }
85
  add_action( 'wpcf7_after_save', 'cf7_success_page_save_contact_form' );
86
 
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  /**
89
  * Redirect the user, after a successful email is sent
90
  */
91
  function cf7_success_page_form_submitted( $contact_form ) {
92
- $contact_form_id = $contact_form->id();
93
 
94
- // Send us to a success page, if there is one
95
- $success_page = get_post_meta( $contact_form_id, '_cf7_success_page_key', true );
96
- if ( !empty($success_page) ) {
97
- wp_redirect( get_permalink( $success_page ) );
98
- die();
99
- }
100
  }
101
  add_action( 'wpcf7_mail_sent', 'cf7_success_page_form_submitted' );
2
  /**
3
  * Plugin Name: Contact Form 7 - Success Page Redirects
4
  * Description: An add-on for Contact Form 7 that provides a straightforward method to redirect visitors to success pages or thank you pages.
5
+ * Version: 1.1.6
6
  * Author: Ryan Nevius
7
  * Author URI: http://www.ryannevius.com
8
  * License: GPLv3
12
  * Verify CF7 dependencies.
13
  */
14
  function cf7_success_page_admin_notice() {
15
+ // Verify that CF7 is active and updated to the required version (currently 3.9.0)
16
+ if ( is_plugin_active('contact-form-7/wp-contact-form-7.php') ) {
17
+ $wpcf7_path = plugin_dir_path( dirname(__FILE__) ) . 'contact-form-7/wp-contact-form-7.php';
18
+ $wpcf7_plugin_data = get_plugin_data( $wpcf7_path, false, false);
19
+ $wpcf7_version = (int)preg_replace('/[.]/', '', $wpcf7_plugin_data['Version']);
20
+ // 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")
21
+ // We need to make sure this value has a digit in the 100s place.
22
+ if ( $wpcf7_version < 100 ) {
23
+ $wpcf7_version = $wpcf7_version * 10;
24
+ }
25
+ // If CF7 version is < 3.9.0
26
+ if ( $wpcf7_version < 390 ) {
27
+ echo '<div class="error"><p><strong>Warning: </strong>Contact Form 7 - Success Page Redirects requires that you have the latest version of Contact Form 7 installed. Please upgrade now.</p></div>';
28
+ }
29
+ }
30
+ // If it's not installed and activated, throw an error
31
  else {
32
+ echo '<div class="error"><p>Contact Form 7 is not activated. The Contact Form 7 Plugin must be installed and activated before you can use Success Page Redirects.</p></div>';
33
+ }
34
  }
35
  add_action( 'admin_notices', 'cf7_success_page_admin_notice' );
36
 
46
  */
47
  // Register the meta boxes
48
  function cf7_success_page_settings() {
49
+ add_meta_box( 'cf7-redirect-settings', 'Success Page Redirect', 'cf7_success_page_metaboxes', '', 'form', 'low');
50
  }
51
  add_action( 'wpcf7_add_meta_boxes', 'cf7_success_page_settings' );
52
 
53
  // Create the meta boxes
54
  function cf7_success_page_metaboxes( $post ) {
55
+ wp_nonce_field( 'cf7_success_page_metaboxes', 'cf7_success_page_metaboxes_nonce' );
56
+ $cf7_success_page = get_post_meta( $post->id(), '_cf7_success_page_key', true );
57
 
58
+ // The meta box content
59
+ echo '<label for="cf7-redirect-page-id"><strong>Redirect to: </strong></label><br> ';
60
+ $dropdown_options = array (
61
+ 'name' => 'cf7-redirect-page-id',
62
+ 'show_option_none' => '--',
63
+ 'option_none_value' => '0',
64
+ 'selected' => $cf7_success_page
65
+ );
66
+ wp_dropdown_pages( $dropdown_options );
67
  }
68
 
69
  // Store Success Page Info
70
  function cf7_success_page_save_contact_form( $contact_form ) {
71
+ $contact_form_id = $contact_form->id();
72
 
73
+ if ( !isset( $_POST ) || empty( $_POST ) || !isset( $_POST['cf7-redirect-page-id'] ) ) {
74
+ return;
75
+ }
76
+ else {
77
+ // Verify that the nonce is valid.
78
+ if ( ! wp_verify_nonce( $_POST['cf7_success_page_metaboxes_nonce'], 'cf7_success_page_metaboxes' ) ) {
79
+ return;
80
+ }
81
+ // Update the stored value
82
  update_post_meta( $contact_form_id, '_cf7_success_page_key', $_POST['cf7-redirect-page-id'] );
83
  }
84
  }
85
  add_action( 'wpcf7_after_save', 'cf7_success_page_save_contact_form' );
86
 
87
 
88
+ /**
89
+ * Copy Redirect page key and assign it to duplicate form
90
+ */
91
+ function cf7_success_page_after_form_create( $contact_form ){
92
+ $contact_form_id = $contact_form->id();
93
+
94
+ // Get the old form ID
95
+ if ( !empty( $_REQUEST['post'] ) && !empty( $_REQUEST['_wpnonce'] ) ) {
96
+ $old_form_id = get_post_meta( $_REQUEST['post'], '_cf7_success_page_key', true );
97
+ }
98
+ // Update the duplicated form
99
+ update_post_meta( $contact_form_id, '_cf7_success_page_key', $old_form_id );
100
+ }
101
+ add_action( 'wpcf7_after_create', 'cf7_success_page_after_form_create' );
102
+
103
+
104
  /**
105
  * Redirect the user, after a successful email is sent
106
  */
107
  function cf7_success_page_form_submitted( $contact_form ) {
108
+ $contact_form_id = $contact_form->id();
109
 
110
+ // Send us to a success page, if there is one
111
+ $success_page = get_post_meta( $contact_form_id, '_cf7_success_page_key', true );
112
+ if ( !empty($success_page) ) {
113
+ wp_redirect( get_permalink( $success_page ) );
114
+ die();
115
+ }
116
  }
117
  add_action( 'wpcf7_mail_sent', 'cf7_success_page_form_submitted' );
readme.txt CHANGED
@@ -48,8 +48,11 @@ In order to ensure that all forms are submitted properly, and that users can be
48
 
49
  == Changelog ==
50
 
 
 
 
51
  = 1.1.5 =
52
- * Fixes a bug where duplicating a contact form wouldn't copy over the redirect field from the original form.
53
 
54
  = 1.1.4 =
55
  * Upgrade process for verifying that Contact Form 7 is installed and up to date.
48
 
49
  == Changelog ==
50
 
51
+ = 1.1.6 =
52
+ * Fixes a bug where duplicating a contact form from the form list view wouldn't copy over the redirect field.
53
+
54
  = 1.1.5 =
55
+ * Fixes a bug where duplicating a contact form wouldn't copy over the redirect field from the original form edit page.
56
 
57
  = 1.1.4 =
58
  * Upgrade process for verifying that Contact Form 7 is installed and up to date.