Fix on register users

This commit is contained in:
Hoang Huu 2019-10-01 13:33:57 +07:00
parent 7840e83f62
commit 225def65e2
3 changed files with 17 additions and 7 deletions

View File

@ -481,6 +481,8 @@ class Opalestate_Agency_Front {
public static function create_agency( $args = [], $user_id ) { public static function create_agency( $args = [], $user_id ) {
$data = get_user_by( 'id', $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, [ $args = wp_parse_args( $args, [
'first_name' => $data->first_name, 'first_name' => $data->first_name,
'last_name' => $data->last_name, 'last_name' => $data->last_name,
@ -499,9 +501,14 @@ class Opalestate_Agency_Front {
'instagram' => '', '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( [ $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_content' => 'empty description',
'post_excerpt' => 'empty excerpt', 'post_excerpt' => 'empty excerpt',
'post_type' => 'opalestate_agency', 'post_type' => 'opalestate_agency',

View File

@ -186,8 +186,8 @@ class Opalestate_User_Form_Handler {
if ( $password !== $password1 ) { if ( $password !== $password1 ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Re-Password is not match.', 'opalestate-pro' ) ); throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . esc_html__( 'Re-Password is not match.', 'opalestate-pro' ) );
} }
$credentials['user_pass'] = $password;
$credentials['user_pass'] = $password;
/* create new user */ /* create new user */
$user_id = opalestate_create_user( $credentials ); $user_id = opalestate_create_user( $credentials );
@ -195,8 +195,7 @@ class Opalestate_User_Form_Handler {
if ( is_wp_error( $user_id ) ) { if ( is_wp_error( $user_id ) ) {
throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $user_id->get_error_message() ); throw new Exception( '<strong>' . esc_html__( 'ERROR', 'opalestate-pro' ) . ':</strong> ' . $user_id->get_error_message() );
} else { } else {
/* After register successfully */
/* after register successfully */
do_action( 'opalestate_after_register_successfully', $user_id ); do_action( 'opalestate_after_register_successfully', $user_id );
$redirect = home_url(); $redirect = home_url();
@ -213,7 +212,7 @@ class Opalestate_User_Form_Handler {
$redirect = apply_filters( 'opalestate_register_redirect_url', $redirect ); $redirect = apply_filters( 'opalestate_register_redirect_url', $redirect );
/* is ajax request */ /* Is ajax request */
if ( opalestate_is_ajax_request() ) { if ( opalestate_is_ajax_request() ) {
wp_send_json( [ 'status' => true, 'redirect' => $redirect ] ); wp_send_json( [ 'status' => true, 'redirect' => $redirect ] );
} else { } else {

View File

@ -185,20 +185,24 @@ class OpalEstate_User {
} }
/** /**
* On Register user.
* *
* @param int $user_id User ID
*/ */
public function on_regiser_user( $user_id ) { public function on_regiser_user( $user_id ) {
if ( isset( $_POST['role'] ) ) { if ( isset( $_POST['role'] ) ) {
$roles = opalestate_user_roles_by_user_id( $user_id );
// Fetch the WP_User object of our user. // Fetch the WP_User object of our user.
$u = new WP_User( $user_id ); $u = new WP_User( $user_id );
$u->remove_role( 'subscriber' ); $u->remove_role( 'subscriber' );
// Replace the current role with 'editor' role // Replace the current role with 'editor' role
$u->set_role( sanitize_text_field( $_POST['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 ) ) { if ( $roles && in_array( $_POST['role'], $roles ) ) {
$role = str_replace( 'opalestate_', '', sanitize_text_field( $_POST['role'] ) ); $role = str_replace( 'opalestate_', '', sanitize_text_field( $_POST['role'] ) );
do_action( 'opalestate_on_set_role_' . $role, $user_id ); do_action( 'opalestate_on_set_role_' . $role, $user_id );
} }
} }