Changeset 4328
- Timestamp:
- 11/04/2016 11:53:08 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/wp-i18n-teams.php
r4249 r4328 11 11 12 12 class WP_I18n_Teams { 13 const TEAM_PAGE = 'https://make.wordpress.org/polyglots/teams/?locale=%s'; 14 13 15 public function __construct() { 14 16 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); … … 18 20 * Attaches hooks and registers shortcodes once plugins are loasded. 19 21 */ 20 function plugins_loaded() {22 public function plugins_loaded() { 21 23 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); 22 24 add_shortcode( 'wp-locales', array( $this, 'wp_locales' ) ); 23 25 24 add_filter( 'the_content', array( $this, 'link_locales' ), 0 ); 25 add_filter( 'comment_text', array( $this, 'link_locales' ), 0 ); 26 add_filter( 'term_link', array( $this, 'link_locales' ), 10, 3 ); 26 27 } 27 28 … … 29 30 * Links #locale to the teams page. 30 31 * 31 * @param string $content Post or comment content. 32 * @return string Filtered post or comment content. 33 */ 34 function link_locales( $content ) { 32 * @param string $termlink Term link URL. 33 * @param object $term Term object. 34 * @param string $taxonomy Taxonomy slug. 35 * @return string URL to teams page of a locale. 36 */ 37 public function link_locales( $termlink, $term, $taxonomy ) { 38 if ( 'post_tag' !== $taxonomy ) { 39 return $termlink; 40 } 41 35 42 static $available_locales; 36 43 … … 38 45 $available_locales = self::get_locales(); 39 46 $available_locales = wp_list_pluck( $available_locales, 'wp_locale' ); 40 } 41 42 $regex = '/\B#([\w]+)\b/'; 43 if ( ! preg_match_all( $regex, $content, $matches ) ) { 44 return $content; 45 } 46 47 $possible_locales = $matches[1]; 48 $possible_locales = array_unique( $possible_locales ); 49 $locales = array_intersect( $available_locales, $possible_locales ); 50 51 foreach ( $locales as $locale ) { 52 $url = esc_url( 'https://make.wordpress.org/polyglots/teams/?locale=' . $locale ); 53 $replacement = "<a href='$url'>#$locale</a>"; 54 $content = preg_replace( "/#$locale\b/", $replacement, $content ); 55 } 56 57 return $content; 47 $available_locales = array_flip( $available_locales ); 48 } 49 50 if ( isset( $available_locales[ $term->name ] ) || isset( $available_locales[ $term->slug ] ) ) { 51 return sprintf( self::TEAM_PAGE, $term->slug ); 52 } 53 54 return $termlink; 58 55 } 59 56
Note: See TracChangeset
for help on using the changeset viewer.