| 10 | |
| 11 | // Add a Custom Title input to user's profile. |
| 12 | add_action( 'bbp_user_edit_after_name', array( $this, 'add_custom_title_input' ) ); |
| 13 | |
| 14 | // Save Custom Title input value. |
| 15 | add_action( 'personal_options_update', array( $this, 'save_custom_title' ), 10, 2 ); |
| 16 | add_action( 'edit_user_profile_update', array( $this, 'save_custom_title' ), 10, 2 ); |
| 34 | |
| 35 | /** |
| 36 | * Add a Custom Title input (only available to moderators) to user's profile. |
| 37 | */ |
| 38 | public function add_custom_title_input() { |
| 39 | if ( ! current_user_can( 'moderate' ) ) { |
| 40 | return; |
| 41 | } |
| 42 | ?> |
| 43 | <div> |
| 44 | <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label> |
| 45 | <input type="text" name="title" id="title" value="<?php bbp_displayed_user_field( 'title', 'edit' ); ?>" class="regular-text" /> |
| 46 | </div> |
| 47 | <?php |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Save Custom Title input value. |
| 52 | * |
| 53 | * @param int $user_id The user ID. |
| 54 | */ |
| 55 | public function save_custom_title( $user_id ) { |
| 56 | if ( ! current_user_can( 'moderate' ) || ! isset( $_POST['title'] ) ) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) ); |
| 61 | } |
| 62 | |