'ImageObject', 'url' => blavatar_url( blavatar_domain( site_url() ), 'img', $size, self::staticize_subdomain( 'https://wordpress.com/i/favicons/apple-touch-icon-60x60.png' ) ), 'width' => $size, 'height' => $size, ); } else if ( $site_icon_url = Jetpack_Sync_Functions::site_icon_url( $size ) ) { $metadata['publisher']['logo'] = array( '@type' => 'ImageObject', 'url' => $site_icon_url, 'width' => $size, 'height' => $size, ); } return $metadata; } /** * Add image to legacy AMP post metadata. * * @since 6.2.0 * * @param array $metadata Metadata. * @param WP_Post $post Post. * @return array Metadata. */ static function add_image_to_metadata( $metadata, $post ) { $image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true, 'avatar_size' => 200, // AMP already attempts these. 'from_thumbnail' => false, 'from_attachment' => false, ) ); if ( empty( $image ) ) { return self::add_fallback_image_to_metadata( $metadata ); } if ( ! isset( $image['src_width'] ) ) { $dimensions = self::extract_image_dimensions_from_getimagesize( array( $image['src'] => false, ) ); if ( false !== $dimensions[ $image['src'] ] ) { $image['src_width'] = $dimensions['width']; $image['src_height'] = $dimensions['height']; } } $metadata['image'] = array( '@type' => 'ImageObject', 'url' => $image['src'], 'width' => $image['src_width'], 'height' => $image['src_height'], ); return $metadata; } /** * Add fallback image to legacy AMP post metadata. * * @since 6.2.0 * * @param array $metadata Metadata. * @return array Metadata. */ static function add_fallback_image_to_metadata( $metadata ) { /** This filter is documented in functions.opengraph.php */ $default_image = apply_filters( 'jetpack_open_graph_image_default', 'https://wordpress.com/i/blank.jpg' ); $metadata['image'] = array( '@type' => 'ImageObject', 'url' => self::staticize_subdomain( $default_image ), 'width' => 200, 'height' => 200, ); return $metadata; } static function staticize_subdomain( $domain ) { // deal with WPCOM vs Jetpack if ( function_exists( 'staticize_subdomain' ) ) { return staticize_subdomain( $domain ); } else { return Jetpack::staticize_subdomain( $domain ); } } /** * Extract image dimensions via wpcom/imagesize, only on WPCOM * * @since 6.2.0 * * @param array $dimensions Dimensions. * @return array Dimensions. */ static function extract_image_dimensions_from_getimagesize( $dimensions ) { if ( ! ( defined('WPCOM') && WPCOM && function_exists( 'require_lib' ) ) ) { return $dimensions; } require_lib( 'wpcom/imagesize' ); foreach ( $dimensions as $url => $value ) { if ( is_array( $value ) ) { continue; } $result = wpcom_getimagesize( $url ); if ( is_array( $result ) ) { $dimensions[ $url ] = array( 'width' => $result[0], 'height' => $result[1], ); } } return $dimensions; } static function amp_post_jetpack_og_tags() { Jetpack::init()->check_open_graph(); if ( function_exists( 'jetpack_og_tags' ) ) { jetpack_og_tags(); } } static function videopress_enable_freedom_mode( $options ) { $options['freedom'] = true; return $options; } static function render_sharing_html( $markup, $sharing_enabled ) { remove_action( 'wp_footer', 'sharing_add_footer' ); if ( empty( $sharing_enabled ) ) { return $markup; } $supported_services = array( 'facebook' => array( /** This filter is documented in modules/sharedaddy/sharing-sources.php */ 'data-param-app_id' => apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ), ), 'twitter' => array(), 'pinterest' => array(), 'whatsapp' => array(), 'google-plus-1' => array( 'type' => 'gplus', ), 'tumblr' => array(), 'linkedin' => array(), ); $sharing_links = array(); foreach ( $sharing_enabled['visible'] as $id => $service ) { if ( ! isset( $supported_services[ $id ] ) ) { $sharing_links[] = ""; continue; } $args = array_merge( array( 'type' => $id, ), $supported_services[ $id ] ); $sharing_link = ' $value ) { $sharing_link .= sprintf( ' %s="%s"', sanitize_key( $key ), esc_attr( $value ) ); } $sharing_link .= '>'; $sharing_links[] = $sharing_link; } return preg_replace( '#(?<=
).+?(?=
)#s', implode( '', $sharing_links ), $markup ); } } add_action( 'init', array( 'Jetpack_AMP_Support', 'init' ), 1 ); add_action( 'admin_init', array( 'Jetpack_AMP_Support', 'admin_init' ), 1 ); // this is necessary since for better or worse Jetpack modules and widget files are loaded during plugins_loaded, which means we must // take the opportunity to intercept initialisation before that point, either by adding explicit detection into the module, // or preventing it from loading in the first place (better for performance) add_action( 'plugins_loaded', array( 'Jetpack_AMP_Support', 'init_filter_jetpack_widgets' ), 1 );