| 1 |
<?php |
| 2 |
namespace WeDevs\ERP\Admin; |
| 3 |
|
| 4 |
/** |
| 5 |
* Loads HR users admin area |
| 6 |
* |
| 7 |
* @package WP-ERP\HR |
| 8 |
* @subpackage Administration |
| 9 |
*/ |
| 10 |
class User_Profile { |
| 11 |
|
| 12 |
/** |
| 13 |
* The HR users admin loader |
| 14 |
* |
| 15 |
* @package WP-ERP\HR |
| 16 |
* @subpackage Administration |
| 17 |
*/ |
| 18 |
public function __construct() { |
| 19 |
$this->setup_actions(); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Setup the admin hooks, actions and filters |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
function setup_actions() { |
| 28 |
|
| 29 |
// Bail if in network admin |
| 30 |
if ( is_network_admin() ) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
// User profile edit/display actions |
| 35 |
add_action( 'edit_user_profile', [ $this, 'role_display' ] ); |
| 36 |
add_action( 'show_user_profile', [ $this, 'role_display' ] ); |
| 37 |
add_action( 'profile_update', [ $this, 'profile_update_role' ] ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Default interface for setting a HR role |
| 42 |
* |
| 43 |
* @param WP_User $profileuser User data |
| 44 |
* |
| 45 |
* @return bool Always false |
| 46 |
*/ |
| 47 |
public static function role_display( $profileuser ) { |
| 48 |
|
| 49 |
// Bail if current user cannot edit users |
| 50 |
if ( ! current_user_can( 'edit_user', $profileuser->ID ) || !current_user_can( 'manage_options') ) { |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
?> |
| 55 |
|
| 56 |
<h3><?php esc_html_e( 'WP ERP Role', 'erp' ); ?></h3> |
| 57 |
|
| 58 |
<table class="form-table"> |
| 59 |
<tbody> |
| 60 |
<tr> |
| 61 |
<th><label for="erp-hr-role"><?php esc_html_e( 'Role', 'erp' ); ?></label></th> |
| 62 |
<td> |
| 63 |
<?php do_action( 'erp_user_profile_role', $profileuser ); ?> |
| 64 |
</td> |
| 65 |
</tr> |
| 66 |
|
| 67 |
</tbody> |
| 68 |
</table> |
| 69 |
|
| 70 |
<?php |
| 71 |
} |
| 72 |
|
| 73 |
public static function profile_update_role( $user_id = 0 ) { |
| 74 |
// Bail if no user ID was passed |
| 75 |
if ( empty( $user_id ) ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
do_action( 'erp_update_user', $user_id, $_POST ); |
| 80 |
} |
| 81 |
} |
| 82 |
|