UserDetails working
Showing
2 changed files
with
86 additions
and
0 deletions
com/UserDetails/UserDetails.php
0 → 100644
| 1 | <?php | ||
| 2 | namespace Tz\WordPress\Tools\UserDetails; | ||
| 3 | use Tz, Tz\Common, Tz\WordPress\Tools; | ||
| 4 | |||
| 5 | const SETTING_NS = 'tz-user-details'; | ||
| 6 | const CAPABILITY = 'edit_user_details'; | ||
| 7 | |||
| 8 | call_user_func(function() { | ||
| 9 | Tz\import('Tz', 'trunk'); | ||
| 10 | |||
| 11 | $role = get_role('administrator'); | ||
| 12 | $role->add_cap(CAPABILITY); | ||
| 13 | |||
| 14 | Tools\add_actions(__NAMESPACE__ . '\Actions'); | ||
| 15 | |||
| 16 | // This for later if done via front end instead of backend | ||
| 17 | //Vars::$meta_fields = new Tools\WP_Option(SETTING_NS); | ||
| 18 | }); | ||
| 19 | |||
| 20 | function register_field($id, $display = null) { //, Common\Callback $fn = null) { | ||
| 21 | if (is_null($display)) { | ||
| 22 | $display = ucwords(str_replace(Array('-', '_'), ' ', $id)); | ||
| 23 | } | ||
| 24 | |||
| 25 | Vars::$fields[$id] = Array( | ||
| 26 | 'id' => $id | ||
| 27 | , 'label' => $display | ||
| 28 | // , 'callback' => $fn | ||
| 29 | ); | ||
| 30 | } | ||
| 31 | |||
| 32 | /** | ||
| 33 | * @returns Array | ||
| 34 | */ | ||
| 35 | function get_registered_fields() { | ||
| 36 | // return assosative array('id' => 'val'); | ||
| 37 | } | ||
| 38 | |||
| 39 | function get_user_id() { | ||
| 40 | if (isset($_GET['user_id'])) { | ||
| 41 | return $_GET['user_id']; | ||
| 42 | } | ||
| 43 | |||
| 44 | if (isset($_POST['user_id'])) { | ||
| 45 | return $_POST['user_id']; | ||
| 46 | } | ||
| 47 | |||
| 48 | global $current_user; | ||
| 49 | get_currentuserinfo(); | ||
| 50 | return $current_user->ID; | ||
| 51 | } | ||
| 52 | |||
| 53 | class Actions { | ||
| 54 | public static function edit_user_profile() { | ||
| 55 | require(__DIR__ . DIRECTORY_SEPARATOR . 'view-user_profile.php'); | ||
| 56 | } | ||
| 57 | |||
| 58 | public static function show_user_profile() { | ||
| 59 | static::edit_user_profile(); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | class Vars { | ||
| 64 | /** | ||
| 65 | * @private | ||
| 66 | * @deprecated | ||
| 67 | */ | ||
| 68 | public static $meta_fields; | ||
| 69 | |||
| 70 | public static $fields = Array(); | ||
| 71 | } | ||
| 72 | ?> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
com/UserDetails/view-user_profile.php
0 → 100644
| 1 | <?php | ||
| 2 | namespace Tz\WordPress\Tools\UserDetails; | ||
| 3 | ?> | ||
| 4 | |||
| 5 | <h3>Additional Info</h3> | ||
| 6 | |||
| 7 | <table class="form-table"><tbody> | ||
| 8 | <?php foreach (Vars::$fields as $id => $info): ?> | ||
| 9 | <tr> | ||
| 10 | <th><label for="<?php echo $id; ?>"><?php echo $info['label']; ?></label></th> | ||
| 11 | <td><input type="text" class="regular-text" name="<?php echo $id; ?>" id="<?php echo $id; ?>" value="<?php echo esc_attr(get_user_meta(get_user_id(), $id, true )); ?>" /></td> | ||
| 12 | </tr> | ||
| 13 | <?php endforeach; ?> | ||
| 14 | </tbody></table> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment