Last active
August 29, 2015 14:23
-
-
Save johnnypea/8c5e13f5ddf7910e4c38 to your computer and use it in GitHub Desktop.
Presmerovanie s parametrom v Contact Form 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wpcf7_load_js', '__return_false' ); | |
class WPCF7_Submit_Redirect { | |
var $field; //nazov pola, napr. 'your-name' | |
var $url; //adresa, na ktoru sa presmeruje | |
var $form_id; //ID formularu | |
function __construct( $field, $url, $form_id = 0 ) { | |
$this->field = $field; | |
$this->url = $url; | |
$this->form_id = $form_id; | |
add_action( 'wpcf7_submit', array( $this, 'redirect' ), 10, 2 ); | |
add_shortcode( 'contact-form-7-field', array( $this, 'shortcode' ) ); | |
} | |
public function redirect( $contact_form, $result ) { | |
if( $this->form_id && $this->form_id != $contact_form->id() ) | |
return; | |
if ( $result['status'] == 'mail_sent' && isset( $_POST[$this->field] ) ) { | |
wp_redirect( add_query_arg( $this->field, $_POST[$this->field], $this->url ) ); | |
exit; | |
} | |
} | |
public function shortcode() { | |
if ( ! empty( $_GET[$this->field] ) ) | |
return $_GET[$this->field]; | |
} | |
} | |
new WPCF7_Submit_Redirect( 'nazov-pola', 'http://example.com/dakujem', 11378 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment