| 1 |
<?php |
| 2 |
|
| 3 |
class LSD_Author extends LSD_Base |
| 4 |
{ |
| 5 |
public function init() |
| 6 |
{ |
| 7 |
add_action('show_user_profile', [$this, 'form']); |
| 8 |
add_action('edit_user_profile', [$this, 'form']); |
| 9 |
|
| 10 |
add_action('personal_options_update', [$this, 'save']); |
| 11 |
add_action('edit_user_profile_update', [$this, 'save']); |
| 12 |
} |
| 13 |
|
| 14 |
public function form($user) |
| 15 |
{ |
| 16 |
// Generate output |
| 17 |
include $this->include_html_file('metaboxes/author/form.php', ['return_path' => true]); |
| 18 |
} |
| 19 |
|
| 20 |
public function save($user_id): bool |
| 21 |
{ |
| 22 |
// No Access |
| 23 |
if (!current_user_can('edit_user', $user_id)) return false; |
| 24 |
|
| 25 |
$nonce = isset($_POST['_wpnonce']) ? sanitize_text_field(wp_unslash($_POST['_wpnonce'])) : ''; |
| 26 |
if (!$nonce || !wp_verify_nonce($nonce, 'update-user_' . $user_id)) return false; |
| 27 |
|
| 28 |
$profile_fields = LSD_User::profile_edit_fields(); |
| 29 |
|
| 30 |
// Job Title |
| 31 |
if (!empty($profile_fields['job_title'])) |
| 32 |
{ |
| 33 |
update_user_meta($user_id, 'lsd_job_title', isset($_POST['lsd_job_title']) |
| 34 |
? sanitize_text_field(wp_unslash($_POST['lsd_job_title'])) |
| 35 |
: '' |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
// Save Social Networks |
| 40 |
if (LSD_User::has_enabled_profile_social_fields()) do_action('lsd_social_networks_profile_save', $user_id); |
| 41 |
|
| 42 |
// Phone |
| 43 |
if (!empty($profile_fields['phone'])) |
| 44 |
{ |
| 45 |
update_user_meta($user_id, 'lsd_phone', isset($_POST['lsd_phone']) |
| 46 |
? sanitize_text_field(wp_unslash($_POST['lsd_phone'])) |
| 47 |
: '' |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
// Mobile |
| 52 |
if (!empty($profile_fields['mobile'])) |
| 53 |
{ |
| 54 |
update_user_meta($user_id, 'lsd_mobile', isset($_POST['lsd_mobile']) |
| 55 |
? sanitize_text_field(wp_unslash($_POST['lsd_mobile'])) |
| 56 |
: '' |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
// Website |
| 61 |
if (!empty($profile_fields['website'])) |
| 62 |
{ |
| 63 |
update_user_meta($user_id, 'lsd_website', isset($_POST['lsd_website']) |
| 64 |
? sanitize_text_field(wp_unslash($_POST['lsd_website'])) |
| 65 |
: '' |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
// Fax |
| 70 |
if (!empty($profile_fields['fax'])) |
| 71 |
{ |
| 72 |
update_user_meta($user_id, 'lsd_fax', isset($_POST['lsd_fax']) |
| 73 |
? sanitize_text_field(wp_unslash($_POST['lsd_fax'])) |
| 74 |
: '' |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
return true; |
| 79 |
} |
| 80 |
} |
| 81 |
|