Beta UserDetails done. String fields work
Showing
2 changed files
with
12 additions
and
9 deletions
| ... | @@ -4,6 +4,7 @@ use Tz, Tz\Common, Tz\WordPress\Tools; | ... | @@ -4,6 +4,7 @@ use Tz, Tz\Common, Tz\WordPress\Tools; |
| 4 | 4 | ||
| 5 | const SETTING_NS = 'tz-user-details'; | 5 | const SETTING_NS = 'tz-user-details'; |
| 6 | const CAPABILITY = 'edit_user_details'; | 6 | const CAPABILITY = 'edit_user_details'; |
| 7 | const HTML_NS = 'tzud-'; | ||
| 7 | 8 | ||
| 8 | call_user_func(function() { | 9 | call_user_func(function() { |
| 9 | Tz\import('Tz', 'trunk'); | 10 | Tz\import('Tz', 'trunk'); |
| ... | @@ -25,17 +26,9 @@ function register_field($id, $display = null) { //, Common\Callback $fn = null) | ... | @@ -25,17 +26,9 @@ function register_field($id, $display = null) { //, Common\Callback $fn = null) |
| 25 | Vars::$fields[$id] = Array( | 26 | Vars::$fields[$id] = Array( |
| 26 | 'id' => $id | 27 | 'id' => $id |
| 27 | , 'label' => $display | 28 | , 'label' => $display |
| 28 | // , 'callback' => $fn | ||
| 29 | ); | 29 | ); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | /** | ||
| 33 | * @returns Array | ||
| 34 | */ | ||
| 35 | function get_registered_fields() { | ||
| 36 | // return assosative array('id' => 'val'); | ||
| 37 | } | ||
| 38 | |||
| 39 | function get_user_id() { | 32 | function get_user_id() { |
| 40 | if (isset($_GET['user_id'])) { | 33 | if (isset($_GET['user_id'])) { |
| 41 | return $_GET['user_id']; | 34 | return $_GET['user_id']; |
| ... | @@ -58,6 +51,16 @@ class Actions { | ... | @@ -58,6 +51,16 @@ class Actions { |
| 58 | public static function show_user_profile() { | 51 | public static function show_user_profile() { |
| 59 | static::edit_user_profile(); | 52 | static::edit_user_profile(); |
| 60 | } | 53 | } |
| 54 | |||
| 55 | public static function profile_update() { | ||
| 56 | $uid = get_user_id(); | ||
| 57 | |||
| 58 | foreach ($_POST as $key => $val) { | ||
| 59 | if (substr($key, 0, strlen(HTML_NS)) == HTML_NS) { | ||
| 60 | update_user_meta($uid, substr($key, strlen(HTML_NS)), $val); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | } | ||
| 61 | } | 64 | } |
| 62 | 65 | ||
| 63 | class Vars { | 66 | class Vars { | ... | ... |
| ... | @@ -8,7 +8,7 @@ namespace Tz\WordPress\Tools\UserDetails; | ... | @@ -8,7 +8,7 @@ namespace Tz\WordPress\Tools\UserDetails; |
| 8 | <?php foreach (Vars::$fields as $id => $info): ?> | 8 | <?php foreach (Vars::$fields as $id => $info): ?> |
| 9 | <tr> | 9 | <tr> |
| 10 | <th><label for="<?php echo $id; ?>"><?php echo $info['label']; ?></label></th> | 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> | 11 | <td><input type="text" class="regular-text" name="<?php echo HTML_NS . $id; ?>" id="<?php echo $id; ?>" value="<?php echo esc_attr(get_user_meta(get_user_id(), $id, true )); ?>" /></td> |
| 12 | </tr> | 12 | </tr> |
| 13 | <?php endforeach; ?> | 13 | <?php endforeach; ?> |
| 14 | </tbody></table> | 14 | </tbody></table> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment