PluginProbe
WP Directory Kit / trunk
WP Directory Kit vtrunk
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / custom_user_fields.php

custom_user_fields.php in WP Directory Kit trunk, at custom_user_fields.php

55 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 $wdk_user_fields_list = array(
8 'wdk_phone' => 'Phone',
9 );
10
11 add_action( 'show_user_profile', function($user) use ($wdk_user_fields_list) {wdk_extra_user_profile_fields($user,$wdk_user_fields_list);} );
12 add_action( 'edit_user_profile', function($user) use ($wdk_user_fields_list) {wdk_extra_user_profile_fields($user,$wdk_user_fields_list);} );
13
14 function wdk_extra_user_profile_fields( $user,$wdk_user_fields_list ) {
15 ?>
16 <div class="wdk_postbox" style="display: block;">
17 <div class="wdk_postbox-header">
18 <h3><?php _e("Directory Profile Info", "wpdirectorykit"); ?></h3>
19 </div>
20 <div class="wdk_inside">
21 <table class="form-table">
22 <?php foreach($wdk_user_fields_list as $field_id => $field_name):?>
23 <tr>
24 <th><label for="user_field_<?php echo esc_html($field_id);?>"><?php echo esc_html__($field_name, 'wpdirectorykit'); ?></label></th>
25 <td>
26 <input type="text" name="<?php echo esc_attr($field_id);?>" id="user_field_<?php echo esc_html($field_id);?>" value="<?php echo esc_attr( get_the_author_meta( $field_id, $user->ID ) ); ?>" class="regular-text" /><br />
27 <span class="description"><?php _e("Please enter your",'wpdirectorykit'); ?> <?php echo esc_html__($field_name, 'wpdirectorykit'); ?>.</span>
28 </td>
29 </tr>
30 <?php endforeach;?>
31 </table>
32 </div>
33 </div>
34 <?php
35 }
36
37 add_action( 'personal_options_update', function($user) use ($wdk_user_fields_list) {wdk_save_extra_user_profile_fields($user,$wdk_user_fields_list);} );
38 add_action( 'edit_user_profile_update', function($user) use ($wdk_user_fields_list) {wdk_save_extra_user_profile_fields($user,$wdk_user_fields_list);} );
39
40 function wdk_save_extra_user_profile_fields( $user,$wdk_user_fields_list ) {
41 $user_id = wmvc_show_data('ID', $user);
42 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-user_' . $user_id ) ) {
43 return;
44 }
45
46 if ( !current_user_can( 'edit_user', $user_id ) ) {
47 return false;
48 }
49
50 foreach ($wdk_user_fields_list as $field_id => $field_name) {
51
52 if(isset($_POST[$field_id]))
53 update_user_meta( $user_id, $field_id, sanitize_text_field($_POST[$field_id]) );
54 }
55 }