PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
1.5.9 1.5.7 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 All 37 releases
wpdirectorykit / custom_user_fields.php

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

56 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 esc_html_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
25 <th><label for="user_field_<?php echo esc_html($field_id);?>"><?php echo esc_html($field_name); ?></label></th>
26 <td>
27 <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 />
28 <span class="description"><?php esc_html_e("Please enter your",'wpdirectorykit'); ?> <?php echo esc_html($field_name); ?>.</span>
29 </td>
30 </tr>
31 <?php endforeach;?>
32 </table>
33 </div>
34 </div>
35 <?php
36 }
37
38 add_action( 'personal_options_update', function($user) use ($wdk_user_fields_list) {wdk_save_extra_user_profile_fields($user,$wdk_user_fields_list);} );
39 add_action( 'edit_user_profile_update', function($user) use ($wdk_user_fields_list) {wdk_save_extra_user_profile_fields($user,$wdk_user_fields_list);} );
40
41 function wdk_save_extra_user_profile_fields( $user,$wdk_user_fields_list ) {
42 $user_id = wmvc_show_data('ID', $user);
43 if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-user_' . $user_id ) ) {
44 return;
45 }
46
47 if ( !current_user_can( 'edit_user', $user_id ) ) {
48 return false;
49 }
50
51 foreach ($wdk_user_fields_list as $field_id => $field_name) {
52
53 if(isset($_POST[$field_id]))
54 update_user_meta( $user_id, $field_id, sanitize_text_field($_POST[$field_id]) );
55 }
56 }