Last active
April 20, 2019 04:46
-
-
Save Tmeister/0410af037fef6caf27ea21e05e74b2c8 to your computer and use it in GitHub Desktop.
Contact Form 7 - User Profile
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
<label> Your Name (required) | |
[text* your-name] </label> | |
<label> Your Email (required) | |
[email* your-email] </label> | |
<label> Your Phone (required) | |
[tel* your-phone] </label> | |
<label> Subject | |
[text your-subject] </label> | |
<label> Your Message | |
[textarea your-message] </label> | |
[hidden current-user-id default:user_id] | |
[submit "Send"] |
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
<?php | |
/* | |
Plugin Name: CF7 User Profile integration | |
Description: Add a new field in the user profile. | |
Plugin URI: https://enriquechavez.co | |
Author: Enrique Chavez | |
Author URI: https://enriquechavez.co | |
Version: 1.0 | |
License: GPL2 | |
Text Domain: ec | |
*/ | |
function tm_add_user_phone_number( $profile_fields ) { | |
$profile_fields['tm_cf7_phone'] = __( 'Phone Number', 'tm_cf7' ); | |
return $profile_fields; | |
} | |
add_action( 'user_contactmethods', 'tm_add_user_phone_number' ); | |
function tm_cf7_on_posted_data( $posted_data ) { | |
$user_id = (int) $posted_data['current-user-id']; | |
$user_phone = sanitize_text_field( $posted_data['your-phone'] ); | |
if ( $user_id ) { | |
update_user_meta( $user_id, 'tm_cf7_phone', $user_phone ); | |
} | |
} | |
add_action( 'wpcf7_posted_data', 'tm_cf7_on_posted_data' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment