2020-02-29 07:30:32 +01:00
< ? php
2019-09-10 06:27:33 +02:00
/**
* $Desc $
*
* @ version $Id $
* @ package opalestate
* @ author Opal Team < info @ wpopal . com >
* @ copyright Copyright ( C ) 2019 wpopal . com . All Rights Reserved .
* @ license GNU / GPL v2 or later http :// www . gnu . org / licenses / gpl - 2.0 . html
*
* @ website http :// www . wpopal . com
* @ support http :// www . wpopal . com / support / forum . html
*/
2020-02-29 07:30:32 +01:00
2019-09-10 06:27:33 +02:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2020-02-29 07:30:32 +01:00
class OpalEstate_Admin_User {
2019-09-10 06:27:33 +02:00
/**
2020-02-29 07:30:32 +01:00
* OpalEstate_Admin_User constructor .
2019-09-10 06:27:33 +02:00
*/
2020-02-29 07:30:32 +01:00
public function __construct () {
add_action ( 'cmb2_admin_init' , [ $this , 'register_user_profile_metabox' ] );
add_action ( 'personal_options' , [ $this , 'show_message_user_profile' ] );
2019-09-10 06:27:33 +02:00
}
2020-02-29 07:30:32 +01:00
2019-09-10 06:27:33 +02:00
/**
*
*/
2020-02-29 07:30:32 +01:00
public function show_message_user_profile () {
$user_id = isset ( $_GET [ 'user_id' ] ) ? intval ( $_GET [ 'user_id' ] ) : 0 ;
$roles = opalestate_user_roles_by_user_id ( $user_id );
if ( $roles ) :
if ( in_array ( 'opalestate_agency' , $roles ) ) :
$agency_id = get_user_meta ( $user_id , OPALESTATE_USER_PROFILE_PREFIX . 'related_id' , true );
if ( ! $agency_id ) {
return ;
}
$link = get_edit_post_link ( $agency_id );
?>
< div id = " message " class = " updated fade " >
< p >< ? php echo sprintf ( __ ( 'This user has role <strong>Opal Estate Agency</strong> and click here to <a href="%s">update Agency profile</a>' , 'opalestate-pro' ), $link ); ?> </p>
</ div >
< ? php elseif ( in_array ( 'opalestate_agent' , $roles ) ) :
$agent_id = get_user_meta ( $user_id , OPALESTATE_USER_PROFILE_PREFIX . 'related_id' , true );
if ( ! $agent_id ) {
return ;
}
$link = get_edit_post_link ( $agent_id );
?>
< div id = " message " class = " updated fade " >
< p >< ? php echo sprintf ( __ ( 'This user has role <strong>Opal Estate Agent</strong> and click here to <a href="%s">update Agent profile</a>' , 'opalestate-pro' ), $link ); ?> </p>
</ div >
< ? php endif ; ?>
< ? php
endif ;
2019-09-10 06:27:33 +02:00
}
2020-02-29 07:30:32 +01:00
/**
2019-09-10 06:27:33 +02:00
*
*/
2020-02-29 07:30:32 +01:00
public function shortcode_button () {
2019-09-10 06:27:33 +02:00
}
2020-02-29 07:30:32 +01:00
2019-09-10 06:27:33 +02:00
/**
* Hook in and add a metabox to add fields to the user profile pages
*/
public function register_user_profile_metabox () {
global $pagenow ;
2020-02-29 07:30:32 +01:00
if ( $pagenow == 'profile.php' || $pagenow == 'user-new.php' || $pagenow == 'user-edit.php' ) {
if ( $pagenow == 'profile.php' && ! opalestate_current_user_can_access_dashboard_page () ) {
return ;
}
if ( $pagenow == 'user-edit.php' ) {
$user_id = isset ( $_GET [ 'user_id' ] ) ? absint ( $_GET [ 'user_id' ] ) : 0 ;
if ( ! $user_id ) {
return ;
}
if ( ! opalestate_user_has_estate_roles ( $user_id ) ) {
return ;
}
}
2019-09-10 06:27:33 +02:00
$prefix = OPALESTATE_USER_PROFILE_PREFIX ;
2020-02-29 07:30:32 +01:00
$metabox = new Opalestate_User_MetaBox ();
2019-09-10 06:27:33 +02:00
2020-02-29 07:30:32 +01:00
$box_options = [
2019-09-10 06:27:33 +02:00
'id' => $prefix . 'edit' ,
'title' => esc_html__ ( 'Metabox' , 'opalestate-pro' ),
2020-02-29 07:30:32 +01:00
'object_types' => [ 'user' ],
2019-09-10 06:27:33 +02:00
'show_names' => true ,
2020-02-29 07:30:32 +01:00
];
2019-09-10 06:27:33 +02:00
$cmb = new_cmb2_box ( $box_options );
// Setting tabs
2020-02-29 07:30:32 +01:00
$tabs_setting = [
2019-09-10 06:27:33 +02:00
'config' => $box_options ,
'layout' => 'vertical' , // Default : horizontal
2020-02-29 07:30:32 +01:00
'tabs' => [],
];
2019-09-10 06:27:33 +02:00
2020-02-29 07:30:32 +01:00
$tabs_setting [ 'tabs' ][] = [
2019-09-10 06:27:33 +02:00
'id' => 'p-general' ,
2020-02-29 07:30:32 +01:00
'icon' => 'dashicons-admin-home' ,
2019-09-10 06:27:33 +02:00
'title' => esc_html__ ( 'General' , 'opalestate-pro' ),
2020-02-29 07:30:32 +01:00
'fields' => $this -> get_base_fields (),
];
2019-09-10 06:27:33 +02:00
2020-02-29 07:30:32 +01:00
$tabs_setting [ 'tabs' ][] = [
2019-09-10 06:27:33 +02:00
'id' => 'p-socials' ,
2020-02-29 07:30:32 +01:00
'icon' => 'dashicons-share' ,
2019-09-10 06:27:33 +02:00
'title' => esc_html__ ( 'Socials' , 'opalestate-pro' ),
'fields' => $metabox -> get_social_fields ( $prefix ),
2020-02-29 07:30:32 +01:00
];
2019-09-10 06:27:33 +02:00
// Set tabs
2020-02-29 07:30:32 +01:00
$cmb -> add_field ( [
2019-09-10 06:27:33 +02:00
'id' => '__tabs' ,
'type' => 'tabs' ,
2020-02-29 07:30:32 +01:00
'tabs' => $tabs_setting ,
] );
2019-09-10 06:27:33 +02:00
/**
* Metabox for the user profile screen
*/
2020-02-29 07:30:32 +01:00
$cmb_user = new_cmb2_box ( [
2019-09-10 06:27:33 +02:00
'id' => $prefix . 'edit' ,
2020-08-20 12:31:10 +02:00
'title' => esc_html__ ( 'User Profile Metabox' , 'opalestate-pro' ), // Doesn't output for user boxes
2020-02-29 07:30:32 +01:00
'object_types' => [ 'user' ], // Tells CMB2 to use user_meta vs post_meta
2019-09-10 06:27:33 +02:00
'show_names' => true ,
'new_user_section' => 'add-new-user' , // where form will show on new user page. 'add-existing-user' is only other valid option.
2020-02-29 07:30:32 +01:00
] );
2019-09-10 06:27:33 +02:00
$fields = $this -> extra_info_fields ();
2020-02-29 07:30:32 +01:00
foreach ( $fields as $field ) {
$cmb_user -> add_field ( $field );
}
2019-09-10 06:27:33 +02:00
}
}
2020-02-29 07:30:32 +01:00
public function get_base_fields () {
2019-09-10 06:27:33 +02:00
$prefix = OPALESTATE_USER_PROFILE_PREFIX ;
2020-02-29 07:30:32 +01:00
$metabox = new Opalestate_User_MetaBox ();
$fields = array_merge_recursive (
2019-09-10 06:27:33 +02:00
$metabox -> get_base_fields ( $prefix ),
2020-02-29 07:30:32 +01:00
$metabox -> get_job_fields ( $prefix ),
2019-09-10 06:27:33 +02:00
$metabox -> get_address_fields ( $prefix )
);
return $fields ;
}
2020-02-29 07:30:32 +01:00
2019-09-10 06:27:33 +02:00
/**
*
*/
2020-02-29 07:30:32 +01:00
public function extra_info_fields () {
2019-09-10 06:27:33 +02:00
$prefix = OPALESTATE_USER_PROFILE_PREFIX ;
2020-02-29 07:30:32 +01:00
$management = [];
2019-09-10 06:27:33 +02:00
2020-02-29 07:30:32 +01:00
$admin_fields = [];
$admin_fields [] = [
'id' => " { $prefix } block_submission " ,
'name' => esc_html__ ( 'Block Submssion' , 'opalestate-pro' ),
'type' => 'checkbox' ,
'description' => esc_html__ ( 'Disable Submssion Functions to not allow submit property' , 'opalestate-pro' ),
'before_row' => '<hr>' ,
];
$admin_fields [] = [
'id' => " { $prefix } block_submission_msg " ,
'name' => esc_html__ ( 'Block Submssion Message' , 'opalestate-pro' ),
'type' => 'textarea' ,
'description' => esc_html__ ( 'Show message for disabled user' , 'opalestate-pro' ),
];
$management = array_merge_recursive ( $admin_fields , $management );
return $management ;
}
2019-09-10 06:27:33 +02:00
}
new OpalEstate_Admin_User ();