UserDetails.php 1.54 KB
<?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();
}
?>