Changeset 4142
- Timestamp:
- 09/27/2016 07:00:59 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-users.php
r3880 r4142 6 6 7 7 public function __construct() { 8 // If the user has a custom title, use that instead of the forum role. 8 9 add_filter( 'bbp_get_user_display_role', array( $this, 'display_role' ), 10, 2 ); 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 ); 9 17 } 10 18 … … 12 20 * If the user has a custom title, use that instead of the forum role. 13 21 * 14 * @param string $role The user's forum role15 * @param int $user_id The user id16 * @return string The user's custom forum title, or their forum role 22 * @param string $role The user's forum role. 23 * @param int $user_id The user ID. 24 * @return string The user's custom forum title, or their forum role. 17 25 */ 18 26 public function display_role( $role, $user_id ) { … … 24 32 return $role; 25 33 } 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 ?> 44 <div> 45 <label for="title"><?php esc_html_e( 'Custom Title', 'wporg-forums' ); ?></label> 46 <input type="text" name="title" id="title" value="<?php echo esc_attr( get_user_option( 'title', bbpress()->displayed_user->ID ) ); ?>" class="regular-text" /> 47 </div> 48 <?php 49 } 50 51 /** 52 * Save Custom Title input value. 53 * 54 * @param int $user_id The user ID. 55 */ 56 public function save_custom_title( $user_id ) { 57 if ( ! current_user_can( 'moderate' ) || ! isset( $_POST['title'] ) ) { 58 return; 59 } 60 61 update_user_option( $user_id, 'title', sanitize_text_field( $_POST['title'] ) ); 62 } 63 26 64 }
Note: See TracChangeset
for help on using the changeset viewer.