Changeset 11778
- Timestamp:
- 04/22/2022 02:27:45 AM (4 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub
- Files:
-
- 1 deleted
- 1 edited
-
jetpack-social-metadata.php (deleted)
-
site-branding.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/site-branding.php
r11451 r11778 49 49 * Filter Jetpack opengraph tags to reference the localised WordPress.org site. 50 50 */ 51 function jetpack_open graph( $fields ) {51 function jetpack_open_graph_tags( $fields ) { 52 52 if ( isset( $fields['og:site_name'] ) && 'WordPress.org' === $fields['og:site_name'] ) { 53 53 $fields['og:site_name'] = get_wordpress_brand(); 54 54 } 55 55 56 // Don't use our default Site Logo for default Jetpack Opengraph fields. 57 $default_site_logo = get_site_icon_url(); // Namespaced filter, not the WordPress function. 58 if ( $default_site_logo ) { 59 if ( ! empty( $fields['og:image'] ) && $fields['og:image'] === $default_site_logo ) { 60 $fields['og:image'] = jetpack_open_graph_image_default(); 61 unset( $fields['og:image:width'], $fields['og:image:height'], $fields['og:image:secure_url'] ); 62 } 63 64 if ( ! empty( $fields['twitter:image'] ) && $fields['twitter:image'] === $default_site_logo ) { 65 $fields['twitter:image'] = jetpack_twitter_cards_image_default(); 66 } 67 } 68 69 /* 70 * Jetpack extracts image URLs like they are used in the content which leads 71 * to blurry previews if they are too small. 72 * This removes the size part of the image URL so the full URL is used. 73 */ 74 $strip_size = function( $url ) { 75 return preg_replace( '/-\d+x\d+(\..+$)/', '$1', $url, 1 ); 76 }; 77 foreach ( [ 'og:image', 'og:image:secure_url', 'twitter:image' ] as $field ) { 78 if ( isset( $fields[ $field ] ) ) { 79 $fields[ $field ] = is_string( $fields[ $field ] ) ? 80 $strip_size( $fields[ $field ] ) : 81 array_map( $strip_size, $fields[ $field ] ); 82 } 83 } 84 56 85 return $fields; 57 86 } 58 add_filter( 'jetpack_open_graph_tags', __NAMESPACE__ . '\jetpack_opengraph', 100 ); 87 add_filter( 'jetpack_open_graph_tags', __NAMESPACE__ . '\jetpack_open_graph_tags', 100 ); 88 89 /** 90 * Set a default og:image image. 91 */ 92 function jetpack_open_graph_image_default() { 93 return 'https://s.w.org/images/backgrounds/wordpress-bg-medblue.png'; 94 } 95 add_filter( 'jetpack_open_graph_image_default', __NAMESPACE__ . '\jetpack_open_graph_image_default' ); 96 97 /** 98 * To prevent a cropped version of the og:image on Twitter, provide a square version. 99 */ 100 function jetpack_twitter_cards_image_default() { 101 return 'https://s.w.org/images/backgrounds/wordpress-bg-medblue-square.png'; 102 } 103 add_filter( 'jetpack_twitter_cards_image_default', __NAMESPACE__ . '\jetpack_twitter_cards_image_default' ); 104 105 /** 106 * Customize the Twitter username used as "twitter:site" Twitter Card Meta Tag. 107 * 108 * This username will also be appended to tweets launched by the tweet button. 109 * 110 * @param string $handle Twitter Username. 111 */ 112 function jetpack_twitter_cards_site_tag( $handle ) { 113 return $handle ?: 'WordPress'; 114 } 115 add_filter( 'jetpack_twitter_cards_site_tag', __NAMESPACE__ . '\jetpack_twitter_cards_site_tag' ); 59 116 60 117 /** … … 81 138 82 139 /** 83 * Output the WordPress favicon on all WordPress.org themes. 140 * Set a default Site Icon if one is not set. 141 * 142 * Causes the icon to be set for all WordPress.org themes. 143 * 144 * NOTE: See the above `jetpack_open_graph_tags()` function for where this is overridden for OpenGraph. 84 145 */ 85 function favicon_icon() { 86 echo '<link rel="icon" href="https://s.w.org/favicon.ico?2" type="image/x-icon" />', "\n"; 146 function get_site_icon_url( $url = '', $size = 0 ) { 147 // Return the favicon for the 32px variety if needed, the wmark image is just a higher resolution variant. 148 if ( 32 === $size ) { 149 return $url ?: 'https://s.w.org/favicon.ico?2'; 150 } 151 152 return $url ?: 'https://s.w.org/images/wmark.png'; 87 153 } 88 add_action( 'wp_head', __NAMESPACE__ . '\favicon_icon', 1 ); 89 154 add_filter( 'get_site_icon_url', __NAMESPACE__ . '\get_site_icon_url', 10, 2 ); 90 155 } 91 156
Note: See TracChangeset
for help on using the changeset viewer.