Exemplo n.º 1
0
    /**
     * Default interface for setting a HR role
     *
     * @param WP_User $profileuser User data
     *
     * @return bool Always false
     */
    public static function role_display($profileuser)
    {
        // Bail if current user cannot edit users
        if (!current_user_can('edit_user', $profileuser->ID)) {
            return;
        }
        $hr_roles = erp_hr_get_roles();
        ?>

        <h3><?php 
        esc_html_e('WP-ERP HR Role', 'wp-erp');
        ?>
</h3>

        <table class="form-table">
            <tbody>
                <tr>
                    <th><label for="erp-hr-role"><?php 
        esc_html_e('HR Role', 'wp-erp');
        ?>
</label></th>
                    <td>

                        <?php 
        $user_role = erp_hr_get_user_role($profileuser->ID);
        ?>

                        <select name="erp-hr-role" id="erp-hr-role">

                            <?php 
        if (!empty($user_role)) {
            ?>

                                <option value=""><?php 
            esc_html_e('&mdash; No role for HR &mdash;', 'wp-erp');
            ?>
</option>

                            <?php 
        } else {
            ?>

                                <option value="" selected="selected"><?php 
            esc_html_e('&mdash; No role for HR &mdash;', 'wp-erp');
            ?>
</option>

                            <?php 
        }
        ?>

                            <?php 
        foreach ($hr_roles as $role => $details) {
            ?>
                                <?php 
            if ($details['public'] == true) {
                continue;
            }
            ?>

                                <option <?php 
            selected($user_role, $role);
            ?>
 value="<?php 
            echo esc_attr($role);
            ?>
"><?php 
            echo translate_user_role($details['name']);
            ?>
</option>

                            <?php 
        }
        ?>

                        </select>
                    </td>
                </tr>

            </tbody>
        </table>

        <?php 
    }
Exemplo n.º 2
0
 /**
  * Create user roles and capabilities
  *
  * @since 0.1
  *
  * @return void
  */
 public function create_roles()
 {
     $roles = erp_hr_get_roles();
     if ($roles) {
         foreach ($roles as $key => $role) {
             add_role($key, $role['name'], $role['capabilities']);
         }
     }
 }
Exemplo n.º 3
0
/**
 * Return a user's HR role
 *
 * @param int $user_id
 *
 * @return string
 */
function erp_hr_get_user_role($user_id = 0)
{
    // Validate user id
    $user = get_userdata($user_id);
    $role = false;
    // User has roles so look for a HR one
    if (!empty($user->roles)) {
        // Look for a HR role
        $roles = array_intersect(array_values($user->roles), array_keys(erp_hr_get_roles()));
        // If there's a role in the array, use the first one. This isn't very
        // smart, but since roles aren't exactly hierarchical, and HR
        // does not yet have a UI for multiple user roles, it's fine for now.
        if (!empty($roles)) {
            $role = array_shift($roles);
        }
    }
    return apply_filters('erp_hr_get_user_role', $role, $user_id, $user);
}