Changeset 5045
- Timestamp:
- 03/02/2017 02:04:40 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r4987 r5045 24 24 // Disable inline terms and mentions. 25 25 add_action( 'plugins_loaded', array( $this, 'disable_inline_terms' ) ); 26 27 // Replace bbp_make_mentions_clickable() to add `class="mention"`. 28 remove_filter( 'bbp_make_clickable', 'bbp_make_mentions_clickable', 8 ); 29 add_filter( 'bbp_make_clickable', array( $this, 'make_mentions_clickable' ), 8 ); 26 30 27 31 // Add notice to reply forms for privileged users in closed forums. … … 136 140 remove_action( 'init', array( 'Jetpack_Inline_Terms', 'init' ) ); 137 141 remove_action( 'init', array( 'Jetpack_Mentions', 'init' ) ); 142 } 143 144 /** 145 * Make mentions clickable in content areas. 146 * 147 * @param string $text Topic or reply content. 148 * @return string Filtered content. 149 */ 150 function make_mentions_clickable( $text = '' ) { 151 return preg_replace_callback( '#([\s>])@([0-9a-zA-Z-_]+)#i', array( $this, 'make_mentions_clickable_callback' ), $text ); 152 } 153 154 /** 155 * Callback to convert mention matches to HTML A tag. 156 * 157 * Replaces bbp_make_mentions_clickable_callback() to add `class="mention"` 158 * for styling purposes. 159 * 160 * @see https://meta.trac.wordpress.org/ticket/2542 161 * @see https://bbpress.trac.wordpress.org/ticket/3074 162 * 163 * @param array $matches Single Regex Match. 164 * @return string HTML A tag with link to user profile. 165 */ 166 function make_mentions_clickable_callback( $matches = array() ) { 167 168 // Get user; bail if not found 169 $user = get_user_by( 'slug', $matches[2] ); 170 if ( empty( $user ) || bbp_is_user_inactive( $user->ID ) ) { 171 return $matches[0]; 172 } 173 174 // Create the link to the user's profile 175 $url = bbp_get_user_profile_url( $user->ID ); 176 $anchor = '<a href="%1$s" class="mention" rel="nofollow">@%2$s</a>'; 177 $link = sprintf( $anchor, esc_url( $url ), esc_html( $user->user_nicename ) ); 178 179 return $matches[1] . $link; 138 180 } 139 181
Note: See TracChangeset
for help on using the changeset viewer.