Changeset 7045
- Timestamp:
- 04/06/2018 02:41:48 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php
r6855 r7045 42 42 add_action( 'template_redirect', array( $this, 'prevent_canonical_for_plugins' ), 9 ); 43 43 add_action( 'template_redirect', array( $this, 'custom_redirects' ), 1 ); 44 add_action( 'template_redirect', array( $this, 'geopattern_icon_route' ), 0 ); 44 45 add_filter( 'query_vars', array( $this, 'filter_query_vars' ) ); 45 46 add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) ); … … 504 505 add_rewrite_rule( '^([^/]+)/advanced/?$', 'index.php?name=$matches[1]&plugin_advanced=1', 'top' ); 505 506 507 // Add a rule for generated plugin icons 508 add_rewrite_rule( '^([^/]+)/geopattern-icon(/([^/]*))?/?$', 'index.php?name=$matches[1]&geopattern_icon=$matches[3]', 'top' ); 509 506 510 // Handle the old plugin tabs URLs. 507 511 add_rewrite_rule( '^([^/]+)/(installation|faq|screenshots|changelog|stats|developers|other_notes)/?$', 'index.php?redirect_plugin=$matches[1]&redirect_plugin_tab=$matches[2]', 'top' ); … … 919 923 920 924 /** 921 * Returns the requested page's content, translated.925 * Returns the requested page's title, translated. 922 926 * 923 927 * @param string $title … … 928 932 $post = get_post( $post_id ); 929 933 934 // The $post_id passed may be a Support Forum post ID, which thankfully is much higher than plugins ID's for now. 930 935 if ( $post instanceof \WP_Post ) { 931 936 $title = Plugin_I18n::instance()->translate( 'title', $title, [ 'post_id' => $post ] ); … … 1054 1059 $vars[] = 'redirect_plugin_tab'; 1055 1060 $vars[] = 'plugin_advanced'; 1061 $vars[] = 'geopattern_icon'; 1056 1062 1057 1063 return $vars; … … 1199 1205 } 1200 1206 1207 } 1208 1209 /** 1210 * Output a SVG Geopattern for a given plugin. 1211 */ 1212 function geopattern_icon_route() { 1213 global $wp; 1214 1215 if ( ! isset( $wp->query_vars['name'], $wp->query_vars['geopattern_icon'] ) ) { 1216 return; 1217 } 1218 1219 $slug = get_query_var( 'name' ); 1220 $color = get_query_var( 'geopattern_icon' ); 1221 1222 $icon = new Plugin_Geopattern(); 1223 $icon->setString( $slug ); 1224 if ( strlen( $color ) === 6 && strspn( $color, 'abcdef0123456789' ) === 6 ) { 1225 $icon->setColor( '#' . $color ); 1226 } 1227 1228 status_header( 200 ); 1229 header( 'Content-Type: image/svg+xml' ); 1230 echo $icon->toSVG(); 1231 die(); 1201 1232 } 1202 1233
Note: See TracChangeset
for help on using the changeset viewer.