Warning: Please upgrade Contact Form 7 to at least version 4.9 to enable custom redirects.
';
}
} else {
echo 'Warning: Your version of Contact Form 7 could not be determined and may have been corrupted. Please update or reinstall Contact Form 7.
';
}
} else {
echo 'Warning: To use custom Contact Form 7 redirects, the base Contact Form 7 plugin must be installed and active.
';
}
}
public function fx_cf7_add_meta_box( $panels ) {
$panels['custom-redirects'] = array(
'title' => 'Custom Redirects',
'callback' => array( $this, 'fx_cf7_redirect_fields' )
);
return $panels;
}
/**
* Add our special fields
*/
public function fx_cf7_redirect_fields( $post ) {
// Display values if already set
$redirect_url = get_post_meta( $post->id(), '_redirect_url', true );
$extra_js = get_post_meta( $post->id(), '_extra_js', true );
$class = '';
// Validate our Redirect URL
if ( ! empty( $redirect_url ) && ! filter_var( $redirect_url, FILTER_VALIDATE_URL ) ) {
$class = ' url-invalid';
}
?>
Custom Redirect URL
Custom JS
id();
$redirect_url = isset( $_POST['redirect_url'] ) ? $_POST['redirect_url'] : '';
$extra_js = isset( $_POST['extra_js'] ) ? $_POST['extra_js'] : '';
// Update each time (in case user uses blank value)
update_post_meta( $contact_form_id, '_redirect_url', $redirect_url );
update_post_meta( $contact_form_id, '_extra_js', $extra_js );
}
public function fx_cf7_js_addon( $content ) {
$args = array(
'post_type' => 'wpcf7_contact_form',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$all_forms = get_posts( $args );
// Check if forms exist
if ( ! empty( $all_forms ) ) {
// Build array from entered values
$form_data = array();
foreach ( $all_forms as $form ) {
$form_id = $form->ID;
$redirect_url = get_post_meta( $form_id, '_redirect_url', true );
$extra_js = get_post_meta( $form_id, '_extra_js', true );
if ( ! empty( $redirect_url ) || ! empty( $extra_js ) ) {
$form_data[ $form_id ] = array(
'redirect_url' => $redirect_url,
'extra_js' => $extra_js
);
}
}
?>