diff --git a/inc/agency/class-opalestate-agency-front.php b/inc/agency/class-opalestate-agency-front.php index df9583b1..6138ce11 100755 --- a/inc/agency/class-opalestate-agency-front.php +++ b/inc/agency/class-opalestate-agency-front.php @@ -481,6 +481,8 @@ class Opalestate_Agency_Front { public static function create_agency( $args = [], $user_id ) { $data = get_user_by( 'id', $user_id ); + $post_title = sprintf( esc_html__( 'User ID: %s', 'opalestate-pro' ), $user_id ); + $args = wp_parse_args( $args, [ 'first_name' => $data->first_name, 'last_name' => $data->last_name, @@ -499,9 +501,14 @@ class Opalestate_Agency_Front { 'instagram' => '', ] ); + if ( $args['first_name'] && $args['last_name'] ) { + $post_title = $args['first_name'] . ' ' . $args['last_name']; + } elseif ( isset( $data->display_name ) && $data->display_name ) { + $post_title = esc_html( $data->display_name ); + } $agency_id = wp_insert_post( [ - 'post_title' => $args['first_name'] && $args['last_name'] ? $args['first_name'] . ' ' . $args['last_name'] : esc_html__( 'User ID', 'opalestate-pro' ) . ': ' . $user_id, + 'post_title' => $post_title, 'post_content' => 'empty description', 'post_excerpt' => 'empty excerpt', 'post_type' => 'opalestate_agency', diff --git a/inc/user/class-opalestate-user-form-handler.php b/inc/user/class-opalestate-user-form-handler.php index 03f3c033..ba2940c6 100755 --- a/inc/user/class-opalestate-user-form-handler.php +++ b/inc/user/class-opalestate-user-form-handler.php @@ -186,8 +186,8 @@ class Opalestate_User_Form_Handler { if ( $password !== $password1 ) { throw new Exception( '' . esc_html__( 'ERROR', 'opalestate-pro' ) . ': ' . esc_html__( 'Re-Password is not match.', 'opalestate-pro' ) ); } - $credentials['user_pass'] = $password; + $credentials['user_pass'] = $password; /* create new user */ $user_id = opalestate_create_user( $credentials ); @@ -195,8 +195,7 @@ class Opalestate_User_Form_Handler { if ( is_wp_error( $user_id ) ) { throw new Exception( '' . esc_html__( 'ERROR', 'opalestate-pro' ) . ': ' . $user_id->get_error_message() ); } else { - - /* after register successfully */ + /* After register successfully */ do_action( 'opalestate_after_register_successfully', $user_id ); $redirect = home_url(); @@ -213,7 +212,7 @@ class Opalestate_User_Form_Handler { $redirect = apply_filters( 'opalestate_register_redirect_url', $redirect ); - /* is ajax request */ + /* Is ajax request */ if ( opalestate_is_ajax_request() ) { wp_send_json( [ 'status' => true, 'redirect' => $redirect ] ); } else { diff --git a/inc/user/class-opalestate-user.php b/inc/user/class-opalestate-user.php index eb6ce761..c2492586 100755 --- a/inc/user/class-opalestate-user.php +++ b/inc/user/class-opalestate-user.php @@ -185,20 +185,24 @@ class OpalEstate_User { } /** + * On Register user. * + * @param int $user_id User ID */ public function on_regiser_user( $user_id ) { if ( isset( $_POST['role'] ) ) { - $roles = opalestate_user_roles_by_user_id( $user_id ); - // Fetch the WP_User object of our user. $u = new WP_User( $user_id ); $u->remove_role( 'subscriber' ); + // Replace the current role with 'editor' role $u->set_role( sanitize_text_field( $_POST['role'] ) ); + $roles = opalestate_user_roles_by_user_id( $user_id ); + if ( $roles && in_array( $_POST['role'], $roles ) ) { $role = str_replace( 'opalestate_', '', sanitize_text_field( $_POST['role'] ) ); + do_action( 'opalestate_on_set_role_' . $role, $user_id ); } }