UserDetails.php
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Tz\WordPress\Tools\UserDetails;
use Tz, Tz\Common, Tz\WordPress\Tools;
const SETTING_NS = 'tz-user-details';
const CAPABILITY = 'edit_user_details';
const HTML_NS = 'tzud-';
call_user_func(function() {
$role = get_role('administrator');
$role->add_cap(CAPABILITY);
Tools\add_actions(__NAMESPACE__ . '\Actions');
// This for later if done via front end instead of backend
//Vars::$meta_fields = new Tools\WP_Option(SETTING_NS);
});
function register_field($id, $display = null) { //, Common\Callback $fn = null) {
if (is_null($display)) {
$display = ucwords(str_replace(Array('-', '_'), ' ', $id));
}
Vars::$fields[$id] = Array(
'id' => $id,
'label' => $display
);
}
function get_user_id() {
if (isset($_GET['user_id'])) {
return $_GET['user_id'];
}
if (isset($_POST['user_id'])) {
return $_POST['user_id'];
}
global $current_user;
get_currentuserinfo();
return $current_user->ID;
}
class Actions {
public static function edit_user_profile() {
require(__DIR__ . DIRECTORY_SEPARATOR . 'view-user_profile.php');
}
public static function show_user_profile() {
static::edit_user_profile();
}
public static function profile_update() {
$uid = get_user_id();
foreach ($_POST as $key => $val) {
if (substr($key, 0, strlen(HTML_NS)) == HTML_NS) {
update_user_meta($uid, substr($key, strlen(HTML_NS)), $val);
}
}
}
}
class Vars {
/**
* @private
* @deprecated
*/
public static $meta_fields;
public static $fields = Array();
}