Updated registration form and login stuff
This commit is contained in:
@@ -24,9 +24,9 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
$this->loader->add_action( 'personal_options_update', $this, 'save_custom_user_fields' );
|
||||
$this->loader->add_action( 'edit_user_profile_update', $this, 'save_custom_user_fields' );
|
||||
$this->loader->add_action( 'user_register', $this, 'add_value_after_reg' );
|
||||
$this->loader->add_action( 'register_form', $this, 'registration_form' );
|
||||
$this->loader->add_filter( 'registration_errors', $this, 'registration_errors', 10, 3 );
|
||||
$this->loader->add_filter( 'comment_post', $this, 'validate_comment' );
|
||||
$this->loader->add_filter( 'wp_authenticate_user', $this, 'check_status', 30, 3 );
|
||||
|
||||
$this->loader->add_action( 'init', $this, 'remove_filters' );
|
||||
|
||||
@@ -79,7 +79,12 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
|
||||
|
||||
public function add_custom_user_fields( $user ) {
|
||||
if( ! current_user_can( 'pexpo_manage_users' ) ) { // Custom capability, added with external plugin
|
||||
return;
|
||||
}
|
||||
|
||||
$company = get_user_meta( $user->ID, 'company', true );
|
||||
$user_status = get_user_meta( $user->ID, 'user_status', true );
|
||||
$logo_id = get_user_meta( $user->ID, 'company_logo_attachment_id', true );
|
||||
$logo_url = $logo_id ? wp_get_attachment_url( $logo_id ) : '';
|
||||
wp_enqueue_media();
|
||||
@@ -102,6 +107,15 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
<input type="text" name="company" id="company" value="<?php echo esc_attr( $company ) ?>" class="regular-text" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="user_status"><?php _e( 'Státusz', 'partnerexpo-core' ) ?></label></th>
|
||||
<td>
|
||||
<select name="user_status" id="user_status" class="regular-text">
|
||||
<option value="active" <?php selected( $user_status, 'active' ); ?>><?php _e( 'Aktív', 'partnerexpo-core' ); ?></option>
|
||||
<option value="inactive" <?php selected( $user_status, 'inactive' ); ?>><?php _e( 'Inaktív', 'partnerexpo-core' ); ?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
@@ -115,13 +129,18 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset($_POST['company']) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company',
|
||||
sanitize_text_field($_POST['company'])
|
||||
);
|
||||
$expected_fields = [
|
||||
'company',
|
||||
'user_status',
|
||||
];
|
||||
|
||||
foreach ( $expected_fields as $field ) {
|
||||
if ( ! empty( $_POST[ $field ] ) ) {
|
||||
$sanitized_value = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
|
||||
update_user_meta( $user_id, $field, $sanitized_value );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset($_POST['image_attachment_id']) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
@@ -132,72 +151,51 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
}
|
||||
|
||||
public function add_value_after_reg( $user_id ) {
|
||||
$expected_fields = [
|
||||
'last_name',
|
||||
'first_name',
|
||||
'phone',
|
||||
'company',
|
||||
'recommended',
|
||||
'newsletter',
|
||||
'gdpr',
|
||||
];
|
||||
|
||||
if ( ! empty( $_POST['first_name'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'first_name',
|
||||
sanitize_text_field( $_POST['first_name'] )
|
||||
);
|
||||
foreach ( $expected_fields as $field ) {
|
||||
if ( ! empty( $_POST[ $field ] ) ) {
|
||||
$sanitized_value = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );
|
||||
update_user_meta( $user_id, $field, $sanitized_value );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['last_name'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'last_name',
|
||||
sanitize_text_field( $_POST['last_name'] )
|
||||
);
|
||||
if ( ! empty( $_FILES['business_logo']['name'] ) ) {
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
||||
require_once( ABSPATH . 'wp-admin/includes/file.php' );
|
||||
require_once( ABSPATH . 'wp-admin/includes/media.php' );
|
||||
|
||||
$attachment_id = media_handle_upload( 'business_logo', 0 );
|
||||
|
||||
if ( ! is_wp_error( $attachment_id ) ) {
|
||||
update_user_meta( $user_id, 'company_logo_attachment_id', $attachment_id );
|
||||
} else {
|
||||
Logger::log( sprintf( __( 'Kép feltöltése sikertelen: %s', 'partnerexpo-core' ), $attachment_id->get_error_message() ), ['user_id' => $user_id] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['phone'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'phone',
|
||||
sanitize_text_field( $_POST['phone'] )
|
||||
);
|
||||
// 3. Set the default user status
|
||||
update_user_meta( $user_id, 'user_status', 'inactive' );
|
||||
}
|
||||
|
||||
function check_status( WP_User $user ) {
|
||||
|
||||
$status = get_user_meta( $user->ID, 'user_status' );
|
||||
|
||||
if ($status && is_array($status) && isset($status[0]) && $status[0] === 'inactive') {
|
||||
return new WP_Error( 'authentication_failed', __( 'A fiókod még nem aktív. Kérlek, várj türelemmel, amíg ellenőrizzük a regisztrációdat.', 'partnerexpo-core' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['phone'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'phone',
|
||||
sanitize_text_field( $_POST['phone'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['gdpr'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'gdpr',
|
||||
sanitize_text_field( $_POST['gdpr'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['newsletter'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'newsletter',
|
||||
sanitize_text_field( $_POST['newsletter'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['company'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company',
|
||||
sanitize_text_field( $_POST['company'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['image_attachment_id'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company_logo_attachment_id',
|
||||
absint( $_POST['image_attachment_id'] )
|
||||
);
|
||||
}
|
||||
|
||||
update_user_meta($user_id, 'user_status', 'inactive');
|
||||
return $user;
|
||||
}
|
||||
|
||||
function registration_errors( $errors, $sanitized_user_login, $user_email ) {
|
||||
|
||||
@@ -68,7 +68,7 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_exists = $this->client->get('Contact', ['Email' => $data['email']]);
|
||||
$user_exists = $this->client->get('Contact', ['Email' => $data['email'], 'Deleted' => 0]);
|
||||
if ( ! is_array($user_exists) ) {
|
||||
Logger::log(__("Kontakt létezésének lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
@@ -76,6 +76,7 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
|
||||
$user_id = 0;
|
||||
$has_company = true;
|
||||
$comp_id = 0;
|
||||
|
||||
if ($user_exists['Count'] == 0) {
|
||||
$new_contact = $this->client->put('Contact', [
|
||||
@@ -94,14 +95,16 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
} else {
|
||||
$user_id = array_key_first($user_exists['Results']);
|
||||
$existing_contact = $this->client->get('Contact/'.$user_id);
|
||||
if ( ! is_array($existing_contact) || ! isset($existing_contact['id']) ) {
|
||||
if ( ! is_array($existing_contact) || ! isset($existing_contact['Id']) ) {
|
||||
Logger::log(__("Kontakt adatok lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'contact_id' => $user_id, $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($existing_contact['BusinessId']) || empty($existing_contact['BusinessId'])) {
|
||||
$has_company = false;
|
||||
} else {
|
||||
$comp_id = $existing_contact['BusinessId'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! $user_id ) {
|
||||
@@ -110,14 +113,12 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
}
|
||||
|
||||
if ( ! $has_company ) {
|
||||
$comp_exists = $this->client->get('Contact', ['Name' => $data['company'], 'Type' => 'Business']);
|
||||
if ( ! is_array($user_exists) ) {
|
||||
$comp_exists = $this->client->get('Contact', ['Name' => $data['company'], 'Type' => 'Business', 'Deleted' => 0]);
|
||||
if ( ! is_array($comp_exists.,.) ) {
|
||||
Logger::log(__("Kontakt létezésének lekérése sikertelen!", "partnerexpo-core"), [$com_id_text => $comment_id, 'email' => $data['email'], $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
}
|
||||
|
||||
$comp_id = 0;
|
||||
|
||||
if ($comp_exists['Count'] == 0) {
|
||||
$new_comp = $this->client->put('Contact', [
|
||||
'Name' => $data['company'],
|
||||
@@ -143,7 +144,8 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
return;
|
||||
}
|
||||
|
||||
$card_exists = $this->client->get('Project', ['CategoryId' => $category_id, 'ContactId' => $user_id]);
|
||||
|
||||
$card_exists = $this->client->get('Project', ['CategoryId' => $category_id, 'ContactId' => $user_id, 'Deleted' => 0]);
|
||||
if ( ! is_array($card_exists) ) {
|
||||
Logger::log(__("Adatlap adatok lekérése sikertelen:", "partnerexpo-core"), [$com_id_text => $comment_id, 'contact_id' => $user_id, $error_text => $this->client->getLastError()]);
|
||||
return;
|
||||
@@ -193,6 +195,7 @@ class Partnerexpo_Core_Integration_Comment_Form {
|
||||
Logger::log(__("Teendő létrehozása sikertelen létező adatlap esetén!", "partnerexpo-core"), [$com_id_text => $comment_id, 'project_id' => $card_id, $error_text => $this->client->getLastError()]);
|
||||
}
|
||||
}
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
Logger::log(__("Ismeretlen hiba történt a szinkronizálás során!", "partnerexpo-core"), [$com_id_text => $comment_id, 'exception' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user