jetpack
Last commit date
3rd-party
2 years ago
_inc
2 years ago
css
2 years ago
extensions
2 years ago
images
2 years ago
jetpack_vendor
1 year ago
json-endpoints
2 years ago
modules
2 years ago
sal
2 years ago
src
2 years ago
vendor
2 years ago
views
3 years ago
CHANGELOG.md
2 years ago
LICENSE.txt
5 years ago
SECURITY.md
2 years ago
class-jetpack-connection-status.php
2 years ago
class-jetpack-gallery-settings.php
3 years ago
class-jetpack-pre-connection-jitms.php
2 years ago
class-jetpack-stats-dashboard-widget.php
2 years ago
class-jetpack-xmlrpc-methods.php
2 years ago
class.frame-nonce-preview.php
4 years ago
class.jetpack-admin.php
2 years ago
class.jetpack-affiliate.php
2 years ago
class.jetpack-autoupdate.php
2 years ago
class.jetpack-bbpress-json-api.compat.php
2 years ago
class.jetpack-cli.php
2 years ago
class.jetpack-client-server.php
2 years ago
class.jetpack-gutenberg.php
2 years ago
class.jetpack-heartbeat.php
2 years ago
class.jetpack-modules-list-table.php
2 years ago
class.jetpack-network-sites-list-table.php
2 years ago
class.jetpack-network.php
2 years ago
class.jetpack-plan.php
2 years ago
class.jetpack-post-images.php
2 years ago
class.jetpack-twitter-cards.php
2 years ago
class.jetpack-user-agent.php
2 years ago
class.jetpack.php
2 years ago
class.json-api-endpoints.php
2 years ago
class.json-api.php
2 years ago
class.photon.php
3 years ago
composer.json
2 years ago
enhanced-open-graph.php
3 years ago
functions.compat.php
2 years ago
functions.cookies.php
2 years ago
functions.global.php
2 years ago
functions.is-mobile.php
2 years ago
functions.opengraph.php
2 years ago
functions.photon.php
2 years ago
jetpack.php
1 year ago
json-api-config.php
3 years ago
json-endpoints.php
2 years ago
load-jetpack.php
2 years ago
locales.php
4 years ago
readme.txt
1 year ago
uninstall.php
2 years ago
wpml-config.xml
3 years ago
enhanced-open-graph.php
169 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Enhanced Open Graph for Jetpack. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | if ( ! class_exists( 'Jetpack_Media_Summary' ) ) { |
| 9 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/class.media-summary.php'; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Better OG Image Tags for Image Post Formats |
| 14 | * |
| 15 | * @param array $tags Array of Open Graph tags. |
| 16 | */ |
| 17 | function enhanced_og_image( $tags ) { |
| 18 | if ( ! is_singular() || post_password_required() ) { |
| 19 | return $tags; |
| 20 | } |
| 21 | |
| 22 | global $post; |
| 23 | |
| 24 | // Bail if we do not have info about the post. |
| 25 | if ( ! $post instanceof WP_Post ) { |
| 26 | return $tags; |
| 27 | } |
| 28 | |
| 29 | // Always favor featured images. |
| 30 | if ( enhanced_og_has_featured_image( $post->ID ) ) { |
| 31 | return $tags; |
| 32 | } |
| 33 | |
| 34 | $summary = Jetpack_Media_Summary::get( $post->ID ); |
| 35 | |
| 36 | if ( 'image' !== $summary['type'] ) { |
| 37 | return $tags; |
| 38 | } |
| 39 | |
| 40 | $tags['og:image'] = $summary['image']; |
| 41 | $tags['og:image:secure_url'] = $summary['secure']['image']; |
| 42 | |
| 43 | return $tags; |
| 44 | } |
| 45 | add_filter( 'jetpack_open_graph_tags', 'enhanced_og_image' ); |
| 46 | |
| 47 | /** |
| 48 | * Better OG Image Tags for Gallery Post Formats |
| 49 | * |
| 50 | * @param array $tags Array of Open Graph tags. |
| 51 | */ |
| 52 | function enhanced_og_gallery( $tags ) { |
| 53 | if ( ! is_singular() || post_password_required() ) { |
| 54 | return $tags; |
| 55 | } |
| 56 | |
| 57 | global $post; |
| 58 | |
| 59 | // Bail if we do not have info about the post. |
| 60 | if ( ! $post instanceof WP_Post ) { |
| 61 | return $tags; |
| 62 | } |
| 63 | |
| 64 | // Always favor featured images. |
| 65 | if ( enhanced_og_has_featured_image( $post->ID ) ) { |
| 66 | return $tags; |
| 67 | } |
| 68 | |
| 69 | $summary = Jetpack_Media_Summary::get( $post->ID ); |
| 70 | |
| 71 | if ( 'gallery' !== $summary['type'] ) { |
| 72 | return $tags; |
| 73 | } |
| 74 | |
| 75 | if ( ! isset( $summary['images'] ) || ! is_array( $summary['images'] ) || empty( $summary['images'] ) ) { |
| 76 | return $tags; |
| 77 | } |
| 78 | |
| 79 | $images = array(); |
| 80 | $secures = array(); |
| 81 | |
| 82 | foreach ( $summary['images'] as $i => $image ) { |
| 83 | $images[] = $image['url']; |
| 84 | $secures[] = $summary['secure']['images'][ $i ]['url']; |
| 85 | } |
| 86 | |
| 87 | $tags['og:image'] = $images; |
| 88 | $tags['og:image:secure_url'] = $secures; |
| 89 | |
| 90 | return $tags; |
| 91 | } |
| 92 | add_filter( 'jetpack_open_graph_tags', 'enhanced_og_gallery' ); |
| 93 | |
| 94 | /** |
| 95 | * Allows VideoPress, YouTube, and Vimeo videos to play inline on Facebook |
| 96 | * |
| 97 | * @param array $tags Array of Open Graph tags. |
| 98 | */ |
| 99 | function enhanced_og_video( $tags ) { |
| 100 | if ( ! is_singular() || post_password_required() ) { |
| 101 | return $tags; |
| 102 | } |
| 103 | |
| 104 | global $post; |
| 105 | |
| 106 | // Bail if we do not have info about the post. |
| 107 | if ( ! $post instanceof WP_Post ) { |
| 108 | return $tags; |
| 109 | } |
| 110 | |
| 111 | // Always favor featured images. |
| 112 | if ( enhanced_og_has_featured_image( $post->ID ) ) { |
| 113 | return $tags; |
| 114 | } |
| 115 | |
| 116 | $summary = Jetpack_Media_Summary::get( $post->ID ); |
| 117 | |
| 118 | if ( 'video' !== $summary['type'] ) { |
| 119 | if ( $summary['count']['video'] > 0 && $summary['count']['image'] < 1 ) { |
| 120 | $tags['og:image'] = $summary['image']; |
| 121 | $tags['og:image:secure_url'] = $summary['secure']['image']; |
| 122 | } |
| 123 | return $tags; |
| 124 | } |
| 125 | |
| 126 | $tags['og:image'] = $summary['image']; |
| 127 | $tags['og:image:secure_url'] = $summary['secure']['image']; |
| 128 | |
| 129 | // This should be html by default for youtube/vimeo, since we're linking to HTML pages. |
| 130 | $tags['og:video:type'] = isset( $summary['video_type'] ) ? $summary['video_type'] : 'text/html'; |
| 131 | |
| 132 | $video_url = $summary['video']; |
| 133 | $secure_video_url = $summary['secure']['video']; |
| 134 | |
| 135 | if ( preg_match( '/((youtube|vimeo)\.com|youtu.be)/', $video_url ) ) { |
| 136 | if ( strstr( $video_url, 'youtube' ) ) { |
| 137 | $id = jetpack_get_youtube_id( $video_url ); |
| 138 | $video_url = 'http://www.youtube.com/embed/' . $id; |
| 139 | $secure_video_url = 'https://www.youtube.com/embed/' . $id; |
| 140 | } elseif ( strstr( $video_url, 'vimeo' ) ) { |
| 141 | preg_match( '|vimeo\.com/(\d+)/?$|i', $video_url, $match ); |
| 142 | $id = (int) $match[1]; |
| 143 | $video_url = 'http://vimeo.com/moogaloop.swf?clip_id=' . $id; |
| 144 | $secure_video_url = 'https://vimeo.com/moogaloop.swf?clip_id=' . $id; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | $tags['og:video'] = $video_url; |
| 149 | $tags['og:video:secure_url'] = $secure_video_url; |
| 150 | |
| 151 | if ( empty( $post->post_title ) ) { |
| 152 | /* translators: %s is the name of the site */ |
| 153 | $tags['og:title'] = sprintf( __( 'Video on %s', 'jetpack' ), get_option( 'blogname' ) ); |
| 154 | } |
| 155 | |
| 156 | return $tags; |
| 157 | } |
| 158 | add_filter( 'jetpack_open_graph_tags', 'enhanced_og_video' ); |
| 159 | |
| 160 | /** |
| 161 | * Check if a post has a suitable featured image. |
| 162 | * |
| 163 | * @param int $post_id The post ID to check. |
| 164 | * @return bool True if the post has a suitable featured image, false otherwise. |
| 165 | */ |
| 166 | function enhanced_og_has_featured_image( $post_id ) { |
| 167 | return ! empty( Jetpack_PostImages::from_thumbnail( $post_id ) ); |
| 168 | } |
| 169 |