tried to add to the reg form, but doesnt work
This commit is contained in:
@@ -2,20 +2,22 @@
|
||||
|
||||
/**
|
||||
* Used to register custom user fields.
|
||||
*
|
||||
* @link https://github.com/Duskell
|
||||
* @since 1.1.0
|
||||
* @package Partnerexpo_Core
|
||||
* @subpackage Partnerexpo_Core/includes
|
||||
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
|
||||
*/
|
||||
class Partnerexpo_Core_User_Fields {
|
||||
*
|
||||
* @link https://github.com/Duskell
|
||||
* @since 1.1.0
|
||||
* @package Partnerexpo_Core
|
||||
* @subpackage Partnerexpo_Core/includes
|
||||
* @author Juhász Levente <juhasz.levente@rendszerepito.hu>
|
||||
*/
|
||||
class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
public function activate_fields() {
|
||||
add_action( 'show_user_profile', [$this, 'add_custom_user_fields'] );
|
||||
add_action( 'edit_user_profile', [$this, 'add_custom_user_fields'] );
|
||||
add_action( 'personal_options_update', [$this, 'save_custom_user_fields'] );
|
||||
add_action( 'edit_user_profile_update', [$this, 'save_custom_user_fields'] );
|
||||
add_action( 'user_register', [$this, 'add_value_after_reg'] );
|
||||
$this->loader->add_action( 'show_user_profile', [$this, 'add_custom_user_fields'] );
|
||||
$this->loader->add_action( 'edit_user_profile', [$this, 'add_custom_user_fields'] );
|
||||
$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 );
|
||||
}
|
||||
|
||||
public function add_custom_user_fields( $user ) {
|
||||
@@ -46,6 +48,25 @@ class Partnerexpo_Core_User_Fields {
|
||||
}
|
||||
|
||||
public function add_value_after_reg( $user_id ) {
|
||||
update_user_meta( $user_id, 'company', sanitize_text_field( $_POST[ 'company' ] ?? '' ) );
|
||||
if ( ! empty( $_POST['company'] ) ) {
|
||||
update_user_meta( $user_id, 'company', sanitize_text_field( $_POST[ 'company' ] ?? '' ) );
|
||||
}
|
||||
}
|
||||
|
||||
function registration_form() {
|
||||
$your_content = ob_get_contents();
|
||||
$your_content = preg_replace( '/\<label for="user_login"\>(.*?)\<br/', 'Usernumia: ', $content );
|
||||
$your_content = preg_replace( '/\<label for="user_email"\>(.*?)\<br/', 'Email Sior:', $content );
|
||||
|
||||
ob_get_clean();
|
||||
echo $your_content;
|
||||
}
|
||||
|
||||
function registration_errors( $errors, $sanitized_user_login, $user_email ) {
|
||||
if ( empty( $_POST['company'] ) || ! empty( $_POST['company'] ) && trim( $_POST['company'] ) == '' ) {
|
||||
$errors->add( 'company_error', sprintf('<strong>%s</strong>: %s',__( 'ERROR', 'partnerexpo-core' ),__( 'You must include a company name.', 'partnerexpo-core' ) ) );
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user