532e7442 by Chris Boden

UserDetails working

1 parent 6ad8bd9e
<?php
namespace Tz\WordPress\Tools\UserDetails;
use Tz, Tz\Common, Tz\WordPress\Tools;
const SETTING_NS = 'tz-user-details';
const CAPABILITY = 'edit_user_details';
call_user_func(function() {
Tz\import('Tz', 'trunk');
$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
// , 'callback' => $fn
);
}
/**
* @returns Array
*/
function get_registered_fields() {
// return assosative array('id' => 'val');
}
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();
}
}
class Vars {
/**
* @private
* @deprecated
*/
public static $meta_fields;
public static $fields = Array();
}
?>
\ No newline at end of file
<?php
namespace Tz\WordPress\Tools\UserDetails;
?>
<h3>Additional Info</h3>
<table class="form-table"><tbody>
<?php foreach (Vars::$fields as $id => $info): ?>
<tr>
<th><label for="<?php echo $id; ?>"><?php echo $info['label']; ?></label></th>
<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>
</tr>
<?php endforeach; ?>
</tbody></table>
\ No newline at end of file