atarim-connect-screen.php
2 weeks ago
class-avcf-offboarding.php
2 weeks ago
class-avcf-settings.php
2 weeks ago
class-avcf-upgrade-notice.php
2 weeks ago
class-user-meta.php
2 weeks ago
class-user-meta.php
62 lines
| 1 | <?php |
| 2 | if (!defined('ABSPATH')) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | class AVCF_User_Meta { |
| 7 | public function __construct() { |
| 8 | // Display checkbox |
| 9 | add_action('show_user_profile', [$this, 'add_webmaster_checkbox']); |
| 10 | add_action('edit_user_profile', [$this, 'add_webmaster_checkbox']); |
| 11 | |
| 12 | // Save checkbox |
| 13 | add_action('personal_options_update', [$this, 'save_webmaster_checkbox']); // admin editing self |
| 14 | add_action('edit_user_profile_update', [$this, 'save_webmaster_checkbox']); // admin editing others |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Add the "Webmaster" checkbox to the user profile screen. |
| 19 | * |
| 20 | * @param WP_User $user |
| 21 | */ |
| 22 | public function add_webmaster_checkbox($user) { |
| 23 | // Only admins can see this |
| 24 | if (!current_user_can('administrator')) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | $checked = get_user_meta($user->ID, 'avc_user_type', true) === 'webmaster' ? 'checked' : ''; |
| 29 | ?> |
| 30 | <h3><?php esc_html_e('Custom User Settings', 'atarim-visual-collaboration'); ?></h3> |
| 31 | <table class="form-table" role="presentation"> |
| 32 | <tr> |
| 33 | <th><label for="avc_user_type"><?php esc_html_e('Webmaster', 'atarim-visual-collaboration'); ?></label></th> |
| 34 | <td> |
| 35 | <input type="checkbox" name="avc_user_type" id="avc_user_type" value="webmaster" <?php echo $checked; ?> /> |
| 36 | <label for="avc_user_type"><?php esc_html_e('Make this user webmaster', 'atarim-visual-collaboration'); ?></label> |
| 37 | </td> |
| 38 | </tr> |
| 39 | </table> |
| 40 | <?php |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Save the "Webmaster" checkbox value. |
| 45 | * |
| 46 | * @param int $user_id |
| 47 | */ |
| 48 | public function save_webmaster_checkbox($user_id) { |
| 49 | // Only admins can save |
| 50 | if (!current_user_can('administrator')) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (isset($_POST['avc_user_type']) && sanitize_text_field(wp_unslash($_POST['avc_user_type'])) === 'webmaster') { |
| 55 | update_user_meta($user_id, 'avc_user_type', 'webmaster'); |
| 56 | } else { |
| 57 | delete_user_meta($user_id, 'avc_user_type'); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | new AVCF_User_Meta(); |