added back the fields to the user edit site and added to add user
This commit is contained in:
@@ -18,9 +18,9 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
}
|
||||
|
||||
private function activate_fields() {
|
||||
$this->loader->add_action( 'load-profile.php', $this, 'remove_custom_user_fields' );
|
||||
$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( 'user_new_form', $this, 'add_user_new_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' );
|
||||
@@ -30,16 +30,63 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
|
||||
}
|
||||
|
||||
public function remove_custom_user_fields() {
|
||||
remove_all_actions('show_user_profile');
|
||||
remove_all_actions('edit_user_profile');
|
||||
public function add_user_new_fields() {
|
||||
wp_enqueue_media();
|
||||
?>
|
||||
<h3>Additional Information</h3>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="company-logo"><?php _e( 'Céges logó', 'partnerexpo-core' ); ?></label></th>
|
||||
<td>
|
||||
<div class='pexpo-core-business-logo-preview-wrapper'>
|
||||
<img id='pexpo-core-business-logo-preview' src='' height='100'>
|
||||
</div>
|
||||
|
||||
<input id="pexpo-core-upload-image-button"
|
||||
type="button"
|
||||
class="button"
|
||||
value="<?php _e( 'Kép feltöltése', 'partnerexpo-core' ); ?>" />
|
||||
|
||||
<input type='hidden'
|
||||
name='image_attachment_id'
|
||||
id='pexpo-core-business-logo-attachment-id'
|
||||
value='' />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><label for="company"><?php _e( 'Cég neve', 'partnerexpo-core' ); ?></label></th>
|
||||
<td>
|
||||
<input type="text"
|
||||
name="company"
|
||||
id="company"
|
||||
value=""
|
||||
class="regular-text" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
public function add_custom_user_fields( $user ) {
|
||||
$company = get_user_meta( $user->ID, 'company', 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();
|
||||
?>
|
||||
<h3>Additional Information</h3>
|
||||
<table class="form-table">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="company-logo"><?php _e( 'Céges logó', 'partnerexpo-core' ) ?></label></th>
|
||||
<td>
|
||||
<div class='pexpo-core-business-logo-preview-wrapper'>
|
||||
<img id='pexpo-core-business-logo-preview' src='<?php echo esc_url( $logo_url ); ?>' height='100'>
|
||||
</div>
|
||||
<input id="pexpo-core-upload-image-button" type="button" class="button" value="<?php _e( 'Kép feltöltése', 'partnerexpo-core' ) ?>" />
|
||||
<input type='hidden' name='image_attachment_id' id='pexpo-core-business-logo-attachment-id' value='<?php echo esc_attr( $logo_id ); ?>'>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="company"><?php _e( 'Cég neve', 'partnerexpo-core' ) ?></label></th>
|
||||
<td>
|
||||
@@ -58,13 +105,39 @@ class Partnerexpo_Core_User_Fields extends Partnerexpo_Core {
|
||||
if( ! current_user_can( 'edit_user', $user_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_user_meta( $user_id, 'company', sanitize_text_field( $_POST[ 'company' ] ) );
|
||||
|
||||
if ( isset($_POST['company']) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company',
|
||||
sanitize_text_field($_POST['company'])
|
||||
);
|
||||
}
|
||||
if ( isset($_POST['image_attachment_id']) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company_logo_attachment_id',
|
||||
absint($_POST['image_attachment_id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_value_after_reg( $user_id ) {
|
||||
if ( ! empty( $_POST['company'] ) ) {
|
||||
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'] )
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $_POST['image_attachment_id'] ) ) {
|
||||
update_user_meta(
|
||||
$user_id,
|
||||
'company_logo_attachment_id',
|
||||
absint( $_POST['image_attachment_id'] )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user