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.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / functions.opengraph.php
jetpack Last commit date
3rd-party 7 years ago _inc 1 year ago bin 7 years ago css 7 years ago images 1 year ago json-endpoints 3 years ago languages 7 years ago modules 1 year ago sal 7 years ago scss 7 years ago sync 7 years ago views 8 years ago .svnignore 12 years ago CODE-OF-CONDUCT.md 9 years ago changelog.txt 7 years ago class.frame-nonce-preview.php 9 years ago class.jetpack-admin.php 8 years ago class.jetpack-autoupdate.php 8 years ago class.jetpack-bbpress-json-api-compat.php 9 years ago class.jetpack-cli.php 7 years ago class.jetpack-client-server.php 8 years ago class.jetpack-client.php 7 years ago class.jetpack-connection-banner.php 7 years ago class.jetpack-constants.php 8 years ago class.jetpack-data.php 7 years ago class.jetpack-debugger.php 8 years ago class.jetpack-error.php 10 years ago class.jetpack-heartbeat.php 7 years ago class.jetpack-idc.php 8 years ago class.jetpack-ixr-client.php 10 years ago class.jetpack-jitm.php 8 years ago class.jetpack-modules-list-table.php 8 years ago class.jetpack-network-sites-list-table.php 9 years ago class.jetpack-network.php 8 years ago class.jetpack-options.php 7 years ago class.jetpack-post-images.php 7 years ago class.jetpack-signature.php 7 years ago class.jetpack-tracks.php 8 years ago class.jetpack-twitter-cards.php 7 years ago class.jetpack-user-agent.php 8 years ago class.jetpack-xmlrpc-server.php 7 years ago class.jetpack.php 7 years ago class.json-api-endpoints.php 3 years ago class.json-api.php 7 years ago class.photon.php 7 years ago composer.json 7 years ago functions.compat.php 7 years ago functions.gallery.php 8 years ago functions.global.php 7 years ago functions.opengraph.php 8 years ago functions.photon.php 8 years ago jetpack.php 1 year ago json-api-config.php 10 years ago json-endpoints.php 8 years ago locales.php 9 years ago phpcs.xml 7 years ago readme.txt 1 year ago require-lib.php 8 years ago uninstall.php 8 years ago wpml-config.xml 10 years ago
functions.opengraph.php
381 lines
1 <?php
2 /**
3 * Open Graph Tags
4 *
5 * Add Open Graph tags so that Facebook (and any other service that supports them)
6 * can crawl the site better and we provide a better sharing experience.
7 *
8 * @link http://ogp.me/
9 * @link http://developers.facebook.com/docs/opengraph/
10 */
11 add_action( 'wp_head', 'jetpack_og_tags' );
12
13 function jetpack_og_tags() {
14 /**
15 * Allow Jetpack to output Open Graph Meta Tags.
16 *
17 * @module sharedaddy, publicize
18 *
19 * @since 2.0.0
20 * @deprecated 2.0.3 Duplicative filter. Use `jetpack_enable_open_graph`.
21 *
22 * @param bool true Should Jetpack's Open Graph Meta Tags be enabled. Default to true.
23 */
24 if ( false === apply_filters( 'jetpack_enable_opengraph', true ) ) {
25 _deprecated_function( 'jetpack_enable_opengraph', '2.0.3', 'jetpack_enable_open_graph' );
26 return;
27 }
28
29 // Disable the widont filter on WP.com to avoid stray &nbsps
30 $disable_widont = remove_filter( 'the_title', 'widont' );
31
32 $og_output = "\n<!-- Jetpack Open Graph Tags -->\n";
33 $tags = array();
34
35 /**
36 * Filter the minimum width of the images used in Jetpack Open Graph Meta Tags.
37 *
38 * @module sharedaddy, publicize
39 *
40 * @since 2.0.0
41 *
42 * @param int 200 Minimum image width used in Jetpack Open Graph Meta Tags.
43 */
44 $image_width = absint( apply_filters( 'jetpack_open_graph_image_width', 200 ) );
45 /**
46 * Filter the minimum height of the images used in Jetpack Open Graph Meta Tags.
47 *
48 * @module sharedaddy, publicize
49 *
50 * @since 2.0.0
51 *
52 * @param int 200 Minimum image height used in Jetpack Open Graph Meta Tags.
53 */
54 $image_height = absint( apply_filters( 'jetpack_open_graph_image_height', 200 ) );
55 $description_length = 197;
56
57 if ( is_home() || is_front_page() ) {
58 $site_type = Jetpack_Options::get_option_and_ensure_autoload( 'open_graph_protocol_site_type', '' );
59 $tags['og:type'] = ! empty( $site_type ) ? $site_type : 'website';
60 $tags['og:title'] = get_bloginfo( 'name' );
61 $tags['og:description'] = get_bloginfo( 'description' );
62
63 $front_page_id = get_option( 'page_for_posts' );
64 if ( 'page' == get_option( 'show_on_front' ) && $front_page_id && is_home() )
65 $tags['og:url'] = get_permalink( $front_page_id );
66 else
67 $tags['og:url'] = home_url( '/' );
68
69 // Associate a blog's root path with one or more Facebook accounts
70 $facebook_admins = Jetpack_Options::get_option_and_ensure_autoload( 'facebook_admins', array() );
71 if ( ! empty( $facebook_admins ) )
72 $tags['fb:admins'] = $facebook_admins;
73
74 } else if ( is_author() ) {
75 $tags['og:type'] = 'profile';
76
77 $author = get_queried_object();
78
79 $tags['og:title'] = $author->display_name;
80 if ( ! empty( $author->user_url ) ) {
81 $tags['og:url'] = $author->user_url;
82 } else {
83 $tags['og:url'] = get_author_posts_url( $author->ID );
84 }
85 $tags['og:description'] = $author->description;
86 $tags['profile:first_name'] = get_the_author_meta( 'first_name', $author->ID );
87 $tags['profile:last_name'] = get_the_author_meta( 'last_name', $author->ID );
88
89 } else if ( is_singular() ) {
90 global $post;
91 $data = $post; // so that we don't accidentally explode the global
92
93 $tags['og:type'] = 'article';
94 if ( empty( $data->post_title ) ) {
95 $tags['og:title'] = ' ';
96 } else {
97 /** This filter is documented in core/src/wp-includes/post-template.php */
98 $tags['og:title'] = wp_kses( apply_filters( 'the_title', $data->post_title, $data->ID ), array() );
99 }
100
101 $tags['og:url'] = get_permalink( $data->ID );
102 if ( ! post_password_required() ) {
103 if ( ! empty( $data->post_excerpt ) ) {
104 $tags['og:description'] = preg_replace( '@https?://[\S]+@', '', strip_shortcodes( wp_kses( $data->post_excerpt, array() ) ) );
105 } else {
106 $exploded_content_on_more_tag = explode( '<!--more-->', $data->post_content );
107 $tags['og:description'] = wp_trim_words( preg_replace( '@https?://[\S]+@', '', strip_shortcodes( wp_kses( $exploded_content_on_more_tag[0], array() ) ) ) );
108 }
109 }
110 if ( empty( $tags['og:description'] ) ) {
111 /**
112 * Filter the fallback `og:description` used when no excerpt information is provided.
113 *
114 * @module sharedaddy, publicize
115 *
116 * @since 3.9.0
117 *
118 * @param string $var Fallback og:description. Default is translated `Visit the post for more'.
119 * @param object $data Post object for the current post.
120 */
121 $tags['og:description'] = apply_filters( 'jetpack_open_graph_fallback_description', __( 'Visit the post for more.', 'jetpack' ), $data );
122 } else {
123 // Intentionally not using a filter to prevent pollution. @see https://github.com/Automattic/jetpack/pull/2899#issuecomment-151957382
124 $tags['og:description'] = wp_kses( trim( convert_chars( wptexturize( $tags['og:description'] ) ) ), array() );
125 }
126
127 $tags['article:published_time'] = date( 'c', strtotime( $data->post_date_gmt ) );
128 $tags['article:modified_time'] = date( 'c', strtotime( $data->post_modified_gmt ) );
129 if ( post_type_supports( get_post_type( $data ), 'author' ) && isset( $data->post_author ) ) {
130 $publicize_facebook_user = get_post_meta( $data->ID, '_publicize_facebook_user', true );
131 if ( ! empty( $publicize_facebook_user ) ) {
132 $tags['article:author'] = esc_url( $publicize_facebook_user );
133 }
134 }
135 }
136
137 /**
138 * Allow plugins to inject additional template-specific Open Graph tags.
139 *
140 * @module sharedaddy, publicize
141 *
142 * @since 3.0.0
143 *
144 * @param array $tags Array of Open Graph Meta tags.
145 * @param array $args Array of image size parameters.
146 */
147 $tags = apply_filters( 'jetpack_open_graph_base_tags', $tags, compact( 'image_width', 'image_height' ) );
148
149 // Re-enable widont if we had disabled it
150 if ( $disable_widont )
151 add_filter( 'the_title', 'widont' );
152
153 /**
154 * Do not return any Open Graph Meta tags if we don't have any info about a post.
155 *
156 * @module sharedaddy, publicize
157 *
158 * @since 3.0.0
159 *
160 * @param bool true Do not return any Open Graph Meta tags if we don't have any info about a post.
161 */
162 if ( empty( $tags ) && apply_filters( 'jetpack_open_graph_return_if_empty', true ) )
163 return;
164
165 $tags['og:site_name'] = get_bloginfo( 'name' );
166
167 // Get image info and build tags
168 if ( ! post_password_required() ) {
169 $image_info = jetpack_og_get_image( $image_width, $image_height );
170 $tags['og:image'] = $image_info['src'];
171
172 if ( ! empty( $image_info['width'] ) ) {
173 $tags['og:image:width'] = (int) $image_info['width'];
174 }
175 if ( ! empty( $image_info['height'] ) ) {
176 $tags['og:image:height'] = (int) $image_info['height'];
177 }
178 }
179
180 // Facebook whines if you give it an empty title
181 if ( empty( $tags['og:title'] ) )
182 $tags['og:title'] = __( '(no title)', 'jetpack' );
183
184 // Shorten the description if it's too long
185 if ( isset( $tags['og:description'] ) ) {
186 $tags['og:description'] = strlen( $tags['og:description'] ) > $description_length ? mb_substr( $tags['og:description'], 0, $description_length ) . '' : $tags['og:description'];
187 }
188
189 // Try to add OG locale tag if the WP->FB data mapping exists
190 if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
191 require_once JETPACK__GLOTPRESS_LOCALES_PATH;
192 $_locale = get_locale();
193
194 // We have to account for w.org vs WP.com locale divergence
195 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
196 $gp_locale = GP_Locales::by_field( 'slug', $_locale );
197 } else {
198 $gp_locale = GP_Locales::by_field( 'wp_locale', $_locale );
199 }
200 }
201
202 if ( isset( $gp_locale->facebook_locale ) && ! empty( $gp_locale->facebook_locale ) ) {
203 $tags['og:locale'] = $gp_locale->facebook_locale;
204 }
205
206 /**
207 * Allow the addition of additional Open Graph Meta tags, or modify the existing tags.
208 *
209 * @module sharedaddy, publicize
210 *
211 * @since 2.0.0
212 *
213 * @param array $tags Array of Open Graph Meta tags.
214 * @param array $args Array of image size parameters.
215 */
216 $tags = apply_filters( 'jetpack_open_graph_tags', $tags, compact( 'image_width', 'image_height' ) );
217
218 // secure_urls need to go right after each og:image to work properly so we will abstract them here
219 $secure = $tags['og:image:secure_url'] = ( empty( $tags['og:image:secure_url'] ) ) ? '' : $tags['og:image:secure_url'];
220 unset( $tags['og:image:secure_url'] );
221 $secure_image_num = 0;
222
223 foreach ( (array) $tags as $tag_property => $tag_content ) {
224 // to accommodate multiple images
225 $tag_content = (array) $tag_content;
226 $tag_content = array_unique( $tag_content );
227
228 foreach ( $tag_content as $tag_content_single ) {
229 if ( empty( $tag_content_single ) )
230 continue; // Don't ever output empty tags
231 $og_tag = sprintf( '<meta property="%s" content="%s" />', esc_attr( $tag_property ), esc_attr( $tag_content_single ) );
232 /**
233 * Filter the HTML Output of each Open Graph Meta tag.
234 *
235 * @module sharedaddy, publicize
236 *
237 * @since 2.0.0
238 *
239 * @param string $og_tag HTML HTML Output of each Open Graph Meta tag.
240 */
241 $og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
242 $og_output .= "\n";
243
244 if ( 'og:image' == $tag_property ) {
245 if ( is_array( $secure ) && !empty( $secure[$secure_image_num] ) ) {
246 $og_tag = sprintf( '<meta property="og:image:secure_url" content="%s" />', esc_url( $secure[ $secure_image_num ] ) );
247 /** This filter is documented in functions.opengraph.php */
248 $og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
249 $og_output .= "\n";
250 } else if ( !is_array( $secure ) && !empty( $secure ) ) {
251 $og_tag = sprintf( '<meta property="og:image:secure_url" content="%s" />', esc_url( $secure ) );
252 /** This filter is documented in functions.opengraph.php */
253 $og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
254 $og_output .= "\n";
255 }
256 $secure_image_num++;
257 }
258 }
259 }
260 $og_output .= "\n<!-- End Jetpack Open Graph Tags -->\n";
261 echo $og_output;
262 }
263
264 function jetpack_og_get_image( $width = 200, $height = 200, $max_images = 4 ) { // Facebook requires thumbnails to be a minimum of 200x200
265 $image = array();
266
267 if ( is_singular() && ! is_home() ) {
268 // Grab obvious image if post is an attachment page for an image
269 if ( is_attachment( get_the_ID() ) && 'image' == substr( get_post_mime_type(), 0, 5 ) ) {
270 $image['src'] = wp_get_attachment_url( get_the_ID() );
271 }
272
273 // Attempt to find something good for this post using our generalized PostImages code
274 if ( empty( $image ) && class_exists( 'Jetpack_PostImages' ) ) {
275 $post_images = Jetpack_PostImages::get_images( get_the_ID(), array( 'width' => $width, 'height' => $height ) );
276 if ( $post_images && ! is_wp_error( $post_images ) ) {
277 foreach ( (array) $post_images as $post_image ) {
278 $image['src'] = $post_image['src'];
279 if ( isset( $post_image['src_width'], $post_image['src_height'] ) ) {
280 $image['width'] = $post_image['src_width'];
281 $image['height'] = $post_image['src_height'];
282 }
283 }
284 }
285 }
286 } elseif ( is_author() ) {
287 $author = get_queried_object();
288 $image['src'] = get_avatar_url( $author->user_email, array(
289 'size' => $width,
290 ) );
291 }
292
293 // First fall back, blavatar.
294 if ( empty( $image ) && function_exists( 'blavatar_domain' ) ) {
295 $blavatar_domain = blavatar_domain( site_url() );
296 if ( blavatar_exists( $blavatar_domain ) ) {
297 $image['src'] = blavatar_url( $blavatar_domain, 'img', $width, false, true );
298 $image['width'] = $width;
299 $image['height'] = $height;
300 }
301 }
302
303 // Second fall back, Site Logo.
304 if ( empty( $image ) && ( function_exists( 'jetpack_has_site_logo' ) && jetpack_has_site_logo() ) ) {
305 $image_id = jetpack_get_site_logo( 'id' );
306 $logo = wp_get_attachment_image_src( $image_id, 'full' );
307 if (
308 isset( $logo[0], $logo[1], $logo[2] )
309 && ( _jetpack_og_get_image_validate_size( $logo[1], $logo[2], $width, $height ) )
310 ) {
311 $image['src'] = $logo[0];
312 $image['width'] = $logo[1];
313 $image['height'] = $logo[2];
314 }
315 }
316
317 // Third fall back, Core Site Icon, if valid in size. Added in WP 4.3.
318 if ( empty( $image ) && ( function_exists( 'has_site_icon' ) && has_site_icon() ) ) {
319 $image_id = get_option( 'site_icon' );
320 $icon = wp_get_attachment_image_src( $image_id, 'full' );
321 if (
322 isset( $icon[0], $icon[1], $icon[2] )
323 && ( _jetpack_og_get_image_validate_size( $icon[1], $icon[2], $width, $height ) )
324 ) {
325 $image['src'] = $icon[0];
326 $image['width'] = $icon[1];
327 $image['height'] = $icon[2];
328 }
329 }
330
331 // Final fall back, blank image.
332 if ( empty( $image ) ) {
333 /**
334 * Filter the default Open Graph Image tag, used when no Image can be found in a post.
335 *
336 * @since 3.0.0
337 *
338 * @param string $str Default Image URL.
339 */
340 $image['src'] = apply_filters( 'jetpack_open_graph_image_default', 'https://s0.wp.com/i/blank.jpg' );
341 }
342
343 return $image;
344 }
345
346
347 /**
348 * Validate the width and height against required width and height
349 *
350 * @param int $width Width of the image.
351 * @param int $height Height of the image.
352 * @param int $req_width Required width to pass validation.
353 * @param int $req_height Required height to pass validation.
354 *
355 * @return bool - True if the image passed the required size validation
356 */
357 function _jetpack_og_get_image_validate_size( $width, $height, $req_width, $req_height ) {
358 if ( ! $width || ! $height ) {
359 return false;
360 }
361
362 $valid_width = ( $width >= $req_width );
363 $valid_height = ( $height >= $req_height );
364 $is_image_acceptable = $valid_width && $valid_height;
365
366 return $is_image_acceptable;
367 }
368
369 /**
370 * Gets a gravatar URL of the specified size.
371 *
372 * @param string $email E-mail address to get gravatar for.
373 * @param int $width Size of returned gravatar.
374 * @return array|bool|mixed|string
375 */
376 function jetpack_og_get_image_gravatar( $email, $width ) {
377 return get_avatar_url( $email, array(
378 'size' => $width,
379 ) );
380 }
381