Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack
File: functions.opengraph.php
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
[0] Fix | Delete
/**
[1] Fix | Delete
* Open Graph Tags
[2] Fix | Delete
*
[3] Fix | Delete
* Add Open Graph tags so that Facebook (and any other service that supports them)
[4] Fix | Delete
* can crawl the site better and we provide a better sharing experience.
[5] Fix | Delete
*
[6] Fix | Delete
* @link https://ogp.me/
[7] Fix | Delete
* @link https://developers.facebook.com/docs/opengraph/
[8] Fix | Delete
*
[9] Fix | Delete
* @package automattic/jetpack
[10] Fix | Delete
*/
[11] Fix | Delete
[12] Fix | Delete
use Automattic\Block_Scanner;
[13] Fix | Delete
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
[14] Fix | Delete
use Automattic\Jetpack\Current_Plan;
[15] Fix | Delete
use Automattic\Jetpack\Status\Host;
[16] Fix | Delete
[17] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[18] Fix | Delete
exit( 0 );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
add_action( 'wp_head', 'jetpack_og_tags' );
[22] Fix | Delete
add_action( 'web_stories_story_head', 'jetpack_og_tags' );
[23] Fix | Delete
[24] Fix | Delete
// Add a Fediverse Open Graph Tag when an author has connected their Mastodon account.
[25] Fix | Delete
add_filter( 'jetpack_open_graph_tags', 'jetpack_add_fediverse_creator_open_graph_tag', 10, 1 );
[26] Fix | Delete
add_filter( 'jetpack_open_graph_output', 'jetpack_filter_fediverse_cards_output', 10, 1 );
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Outputs Open Graph tags generated by Jetpack.
[30] Fix | Delete
*/
[31] Fix | Delete
function jetpack_og_tags() {
[32] Fix | Delete
global $post;
[33] Fix | Delete
$data = $post; // so that we don't accidentally explode the global.
[34] Fix | Delete
[35] Fix | Delete
$is_amp_response = ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() );
[36] Fix | Delete
[37] Fix | Delete
// Disable the widont filter on WP.com to avoid stray &nbsps.
[38] Fix | Delete
$disable_widont = remove_filter( 'the_title', 'widont' );
[39] Fix | Delete
[40] Fix | Delete
$og_output = "\n";
[41] Fix | Delete
if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head.
[42] Fix | Delete
$og_output .= "<!-- Jetpack Open Graph Tags -->\n";
[43] Fix | Delete
}
[44] Fix | Delete
$tags = array();
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Filter the minimum width of the images used in Jetpack Open Graph Meta Tags.
[48] Fix | Delete
*
[49] Fix | Delete
* @module sharedaddy, publicize
[50] Fix | Delete
*
[51] Fix | Delete
* @since 2.0.0
[52] Fix | Delete
*
[53] Fix | Delete
* @param int 200 Minimum image width used in Jetpack Open Graph Meta Tags.
[54] Fix | Delete
*/
[55] Fix | Delete
$image_width = absint( apply_filters( 'jetpack_open_graph_image_width', 200 ) );
[56] Fix | Delete
/**
[57] Fix | Delete
* Filter the minimum height of the images used in Jetpack Open Graph Meta Tags.
[58] Fix | Delete
*
[59] Fix | Delete
* @module sharedaddy, publicize
[60] Fix | Delete
*
[61] Fix | Delete
* @since 2.0.0
[62] Fix | Delete
*
[63] Fix | Delete
* @param int 200 Minimum image height used in Jetpack Open Graph Meta Tags.
[64] Fix | Delete
*/
[65] Fix | Delete
$image_height = absint( apply_filters( 'jetpack_open_graph_image_height', 200 ) );
[66] Fix | Delete
$description_length = 197;
[67] Fix | Delete
[68] Fix | Delete
if ( is_home() || is_front_page() ) {
[69] Fix | Delete
$site_type = Jetpack_Options::get_option_and_ensure_autoload( 'open_graph_protocol_site_type', '' );
[70] Fix | Delete
$tags['og:type'] = ! empty( $site_type ) ? $site_type : 'website';
[71] Fix | Delete
$tags['og:title'] = get_bloginfo( 'name' );
[72] Fix | Delete
$tags['og:description'] = get_bloginfo( 'description' );
[73] Fix | Delete
[74] Fix | Delete
$front_page_id = get_option( 'page_for_posts' );
[75] Fix | Delete
if ( 'page' === get_option( 'show_on_front' ) && $front_page_id && is_home() ) {
[76] Fix | Delete
$tags['og:url'] = get_permalink( $front_page_id );
[77] Fix | Delete
} else {
[78] Fix | Delete
$tags['og:url'] = home_url( '/' );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
// Associate a blog's root path with one or more Facebook accounts.
[82] Fix | Delete
$facebook_admins = Jetpack_Options::get_option_and_ensure_autoload( 'facebook_admins', array() );
[83] Fix | Delete
if ( ! empty( $facebook_admins ) ) {
[84] Fix | Delete
$tags['fb:admins'] = $facebook_admins;
[85] Fix | Delete
}
[86] Fix | Delete
} elseif ( is_author() ) {
[87] Fix | Delete
$tags['og:type'] = 'profile';
[88] Fix | Delete
[89] Fix | Delete
$author = get_queried_object();
[90] Fix | Delete
[91] Fix | Delete
if ( is_a( $author, 'WP_User' ) ) {
[92] Fix | Delete
$tags['og:title'] = $author->display_name;
[93] Fix | Delete
if ( ! empty( $author->user_url ) ) {
[94] Fix | Delete
$tags['og:url'] = $author->user_url;
[95] Fix | Delete
} else {
[96] Fix | Delete
$tags['og:url'] = get_author_posts_url( $author->ID );
[97] Fix | Delete
}
[98] Fix | Delete
$tags['og:description'] = $author->description;
[99] Fix | Delete
$tags['profile:first_name'] = get_the_author_meta( 'first_name', $author->ID );
[100] Fix | Delete
$tags['profile:last_name'] = get_the_author_meta( 'last_name', $author->ID );
[101] Fix | Delete
}
[102] Fix | Delete
} elseif ( is_archive() ) {
[103] Fix | Delete
$tags['og:type'] = 'website';
[104] Fix | Delete
$tags['og:title'] = wp_get_document_title();
[105] Fix | Delete
[106] Fix | Delete
$archive = get_queried_object();
[107] Fix | Delete
if ( $archive instanceof WP_Term ) {
[108] Fix | Delete
$tags['og:url'] = get_term_link( $archive->term_id, $archive->taxonomy );
[109] Fix | Delete
$tags['og:description'] = $archive->description;
[110] Fix | Delete
} elseif ( ! empty( $archive ) && is_post_type_archive() ) {
[111] Fix | Delete
$tags['og:url'] = get_post_type_archive_link( $archive->name );
[112] Fix | Delete
$tags['og:description'] = $archive->description;
[113] Fix | Delete
}
[114] Fix | Delete
} elseif ( is_singular() && is_a( $data, 'WP_Post' ) ) {
[115] Fix | Delete
$tags['og:type'] = 'article';
[116] Fix | Delete
if ( empty( $data->post_title ) ) {
[117] Fix | Delete
$tags['og:title'] = ' ';
[118] Fix | Delete
} else {
[119] Fix | Delete
/** This filter is documented in core/src/wp-includes/post-template.php */
[120] Fix | Delete
$tags['og:title'] = wp_kses( apply_filters( 'the_title', $data->post_title, $data->ID ), array() );
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
$tags['og:url'] = get_permalink( $data->ID );
[124] Fix | Delete
if ( ! post_password_required() ) {
[125] Fix | Delete
/*
[126] Fix | Delete
* If the post author set an excerpt, use that.
[127] Fix | Delete
* Otherwise, pick the post content that comes before the More tag if there is one.
[128] Fix | Delete
* Do not use the post content if it contains premium content.
[129] Fix | Delete
*/
[130] Fix | Delete
if ( ! empty( $data->post_excerpt ) ) {
[131] Fix | Delete
$tags['og:description'] = jetpack_og_get_description( $data->post_excerpt );
[132] Fix | Delete
} elseif ( ! has_block( 'premium-content/container', $data->post_content ) ) {
[133] Fix | Delete
$excerpt = explode( '<!--more-->', $data->post_content )[0];
[134] Fix | Delete
$tags['og:description'] = jetpack_og_get_description( $excerpt );
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$tags['article:published_time'] = gmdate( 'c', strtotime( $data->post_date_gmt ) );
[139] Fix | Delete
$tags['article:modified_time'] = gmdate( 'c', strtotime( $data->post_modified_gmt ) );
[140] Fix | Delete
if ( post_type_supports( get_post_type( $data ), 'author' ) && isset( $data->post_author ) ) {
[141] Fix | Delete
$publicize_facebook_user = get_post_meta( $data->ID, '_publicize_facebook_user', true );
[142] Fix | Delete
if ( ! empty( $publicize_facebook_user ) ) {
[143] Fix | Delete
$tags['article:author'] = esc_url( $publicize_facebook_user );
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
} elseif ( is_search() ) {
[147] Fix | Delete
if ( '' !== get_query_var( 's', '' ) ) {
[148] Fix | Delete
$tags['og:title'] = wp_get_document_title();
[149] Fix | Delete
}
[150] Fix | Delete
}
[151] Fix | Delete
/**
[152] Fix | Delete
* Allow plugins to inject additional template-specific Open Graph tags.
[153] Fix | Delete
*
[154] Fix | Delete
* @module sharedaddy, publicize
[155] Fix | Delete
*
[156] Fix | Delete
* @since 3.0.0
[157] Fix | Delete
*
[158] Fix | Delete
* @param array $tags Array of Open Graph Meta tags.
[159] Fix | Delete
* @param array $args Array of image size parameters.
[160] Fix | Delete
*/
[161] Fix | Delete
$tags = apply_filters( 'jetpack_open_graph_base_tags', $tags, compact( 'image_width', 'image_height' ) );
[162] Fix | Delete
[163] Fix | Delete
// Re-enable widont if we had disabled it.
[164] Fix | Delete
if ( $disable_widont ) {
[165] Fix | Delete
add_filter( 'the_title', 'widont' );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
/**
[169] Fix | Delete
* Do not return any Open Graph Meta tags if we don't have any info about a post.
[170] Fix | Delete
*
[171] Fix | Delete
* @module sharedaddy, publicize
[172] Fix | Delete
*
[173] Fix | Delete
* @since 3.0.0
[174] Fix | Delete
*
[175] Fix | Delete
* @param bool true Do not return any Open Graph Meta tags if we don't have any info about a post.
[176] Fix | Delete
*/
[177] Fix | Delete
if ( empty( $tags ) && apply_filters( 'jetpack_open_graph_return_if_empty', true ) ) {
[178] Fix | Delete
return;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
$tags['og:site_name'] = get_bloginfo( 'name' );
[182] Fix | Delete
[183] Fix | Delete
// Get image info and build tags.
[184] Fix | Delete
if ( ! post_password_required() ) {
[185] Fix | Delete
$image_info = jetpack_og_get_image( $image_width, $image_height );
[186] Fix | Delete
$tags['og:image'] = $image_info['src'];
[187] Fix | Delete
[188] Fix | Delete
if ( ! empty( $image_info['width'] ) ) {
[189] Fix | Delete
$tags['og:image:width'] = (int) $image_info['width'];
[190] Fix | Delete
}
[191] Fix | Delete
if ( ! empty( $image_info['height'] ) ) {
[192] Fix | Delete
$tags['og:image:height'] = (int) $image_info['height'];
[193] Fix | Delete
}
[194] Fix | Delete
// If we have an image, add the alt text even if it's empty.
[195] Fix | Delete
if ( ! empty( $image_info['src'] ) && isset( $image_info['alt_text'] ) ) {
[196] Fix | Delete
$tags['og:image:alt'] = esc_attr( $image_info['alt_text'] );
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
// Facebook whines if you give it an empty title.
[201] Fix | Delete
if ( empty( $tags['og:title'] ) ) {
[202] Fix | Delete
$tags['og:title'] = __( '(no title)', 'jetpack' );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
// Shorten the description if it's too long.
[206] Fix | Delete
if ( isset( $tags['og:description'] ) ) {
[207] Fix | Delete
$tags['og:description'] = strlen( $tags['og:description'] ) > $description_length ? mb_substr( $tags['og:description'], 0, $description_length ) . '…' : $tags['og:description'];
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
// Try to add OG locale tag if the WP->FB data mapping exists.
[211] Fix | Delete
if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
[212] Fix | Delete
require_once JETPACK__GLOTPRESS_LOCALES_PATH;
[213] Fix | Delete
$_locale = get_locale();
[214] Fix | Delete
[215] Fix | Delete
// We have to account for w.org vs WP.com locale divergence.
[216] Fix | Delete
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
[217] Fix | Delete
$gp_locale = GP_Locales::by_field( 'slug', $_locale );
[218] Fix | Delete
} else {
[219] Fix | Delete
$gp_locale = GP_Locales::by_field( 'wp_locale', $_locale );
[220] Fix | Delete
}
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
if ( isset( $gp_locale->facebook_locale ) && ! empty( $gp_locale->facebook_locale ) ) {
[224] Fix | Delete
$tags['og:locale'] = $gp_locale->facebook_locale;
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
/**
[228] Fix | Delete
* Allow the addition of additional Open Graph Meta tags, or modify the existing tags.
[229] Fix | Delete
*
[230] Fix | Delete
* @module sharedaddy, publicize
[231] Fix | Delete
*
[232] Fix | Delete
* @since 2.0.0
[233] Fix | Delete
*
[234] Fix | Delete
* @param array $tags Array of Open Graph Meta tags.
[235] Fix | Delete
* @param array $args Array of image size parameters.
[236] Fix | Delete
*/
[237] Fix | Delete
$tags = apply_filters( 'jetpack_open_graph_tags', $tags, compact( 'image_width', 'image_height' ) );
[238] Fix | Delete
[239] Fix | Delete
// secure_urls need to go right after each og:image to work properly so we will abstract them here.
[240] Fix | Delete
$tags['og:image:secure_url'] = ( empty( $tags['og:image:secure_url'] ) ) ? '' : $tags['og:image:secure_url'];
[241] Fix | Delete
$secure = $tags['og:image:secure_url'];
[242] Fix | Delete
unset( $tags['og:image:secure_url'] );
[243] Fix | Delete
$secure_image_num = 0;
[244] Fix | Delete
[245] Fix | Delete
$allowed_empty_tags = array(
[246] Fix | Delete
'og:image:alt',
[247] Fix | Delete
);
[248] Fix | Delete
[249] Fix | Delete
foreach ( (array) $tags as $tag_property => $tag_content ) {
[250] Fix | Delete
// to accommodate multiple images.
[251] Fix | Delete
$tag_content = (array) $tag_content;
[252] Fix | Delete
$tag_content = array_unique( array_filter( $tag_content, 'is_scalar' ) );
[253] Fix | Delete
[254] Fix | Delete
foreach ( $tag_content as $tag_content_single ) {
[255] Fix | Delete
if ( empty( $tag_content_single ) && ! in_array( $tag_property, $allowed_empty_tags, true ) ) {
[256] Fix | Delete
continue; // Only allow certain empty tags.
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
switch ( $tag_property ) {
[260] Fix | Delete
case 'og:url':
[261] Fix | Delete
case 'og:image':
[262] Fix | Delete
case 'og:image:url':
[263] Fix | Delete
case 'og:image:secure_url':
[264] Fix | Delete
case 'og:audio':
[265] Fix | Delete
case 'og:audio:url':
[266] Fix | Delete
case 'og:audio:secure_url':
[267] Fix | Delete
case 'og:video':
[268] Fix | Delete
case 'og:video:url':
[269] Fix | Delete
case 'og:video:secure_url':
[270] Fix | Delete
$og_tag = sprintf( '<meta property="%s" content="%s" />', esc_attr( $tag_property ), esc_url( $tag_content_single ) );
[271] Fix | Delete
break;
[272] Fix | Delete
default:
[273] Fix | Delete
$og_tag = sprintf( '<meta property="%s" content="%s" />', esc_attr( $tag_property ), esc_attr( $tag_content_single ) );
[274] Fix | Delete
}
[275] Fix | Delete
/**
[276] Fix | Delete
* Filter the HTML Output of each Open Graph Meta tag.
[277] Fix | Delete
*
[278] Fix | Delete
* @module sharedaddy, publicize
[279] Fix | Delete
*
[280] Fix | Delete
* @since 2.0.0
[281] Fix | Delete
*
[282] Fix | Delete
* @param string $og_tag HTML HTML Output of each Open Graph Meta tag.
[283] Fix | Delete
*/
[284] Fix | Delete
$og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
[285] Fix | Delete
$og_output .= "\n";
[286] Fix | Delete
[287] Fix | Delete
if ( 'og:image' === $tag_property ) {
[288] Fix | Delete
if ( is_array( $secure ) && ! empty( $secure[ $secure_image_num ] ) ) {
[289] Fix | Delete
$og_tag = sprintf( '<meta property="og:image:secure_url" content="%s" />', esc_url( $secure[ $secure_image_num ] ) );
[290] Fix | Delete
/** This filter is documented in functions.opengraph.php */
[291] Fix | Delete
$og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
[292] Fix | Delete
$og_output .= "\n";
[293] Fix | Delete
} elseif ( ! is_array( $secure ) && ! empty( $secure ) ) {
[294] Fix | Delete
$og_tag = sprintf( '<meta property="og:image:secure_url" content="%s" />', esc_url( $secure ) );
[295] Fix | Delete
/** This filter is documented in functions.opengraph.php */
[296] Fix | Delete
$og_output .= apply_filters( 'jetpack_open_graph_output', $og_tag );
[297] Fix | Delete
$og_output .= "\n";
[298] Fix | Delete
}
[299] Fix | Delete
++$secure_image_num;
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head.
[305] Fix | Delete
$og_output .= "\n<!-- End Jetpack Open Graph Tags -->";
[306] Fix | Delete
}
[307] Fix | Delete
$og_output .= "\n";
[308] Fix | Delete
// This is trusted output or added by a filter.
[309] Fix | Delete
echo $og_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Returns an image used in social shares.
[314] Fix | Delete
*
[315] Fix | Delete
* @since 2.0.0
[316] Fix | Delete
*
[317] Fix | Delete
* @param int $width Minimum width for the image. Default is 200 based on Facebook's requirement.
[318] Fix | Delete
* @param int $height Minimum height for the image. Default is 200 based on Facebook's requirement.
[319] Fix | Delete
* @param null $deprecated Deprecated.
[320] Fix | Delete
*
[321] Fix | Delete
* @return array The source ('src'), 'width', and 'height' of the image.
[322] Fix | Delete
*/
[323] Fix | Delete
function jetpack_og_get_image( $width = 200, $height = 200, $deprecated = null ) {
[324] Fix | Delete
if ( ! empty( $deprecated ) ) {
[325] Fix | Delete
_deprecated_argument( __FUNCTION__, 'jetpack-6.6.0' );
[326] Fix | Delete
}
[327] Fix | Delete
$image = array();
[328] Fix | Delete
[329] Fix | Delete
if ( is_singular() && ! is_home() ) {
[330] Fix | Delete
// Grab obvious image if post is an attachment page for an image.
[331] Fix | Delete
if ( is_attachment( get_the_ID() ) && str_starts_with( get_post_mime_type(), 'image' ) ) {
[332] Fix | Delete
$image['src'] = wp_get_attachment_url( get_the_ID() );
[333] Fix | Delete
$image['alt_text'] = Jetpack_PostImages::get_alt_text( get_the_ID() );
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
// Attempt to find something good for this post using our generalized PostImages code.
[337] Fix | Delete
if ( empty( $image ) && class_exists( 'Jetpack_PostImages' ) ) {
[338] Fix | Delete
$post_image = Jetpack_PostImages::get_image(
[339] Fix | Delete
get_the_ID(),
[340] Fix | Delete
array(
[341] Fix | Delete
'width' => $width,
[342] Fix | Delete
'height' => $height,
[343] Fix | Delete
)
[344] Fix | Delete
);
[345] Fix | Delete
if ( ! empty( $post_image ) && is_array( $post_image ) ) {
[346] Fix | Delete
$image['src'] = $post_image['src'];
[347] Fix | Delete
if ( isset( $post_image['src_width'] ) && isset( $post_image['src_height'] ) ) {
[348] Fix | Delete
$image['width'] = $post_image['src_width'];
[349] Fix | Delete
$image['height'] = $post_image['src_height'];
[350] Fix | Delete
}
[351] Fix | Delete
if ( ! empty( $post_image['alt_text'] ) ) {
[352] Fix | Delete
$image['alt_text'] = $post_image['alt_text'];
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
}
[356] Fix | Delete
} elseif ( is_author() ) {
[357] Fix | Delete
$author = get_queried_object();
[358] Fix | Delete
if ( is_a( $author, 'WP_User' ) ) {
[359] Fix | Delete
$image['src'] = get_avatar_url(
[360] Fix | Delete
$author->user_email,
[361] Fix | Delete
array(
[362] Fix | Delete
'size' => $width,
[363] Fix | Delete
)
[364] Fix | Delete
);
[365] Fix | Delete
$image['alt_text'] = $author->display_name;
[366] Fix | Delete
}
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
/*
[370] Fix | Delete
* Generate a fallback social image,
[371] Fix | Delete
* dynamically generated based on the site name,
[372] Fix | Delete
* a representative image of the site,
[373] Fix | Delete
* and a custom template used by our Social Image Generator.
[374] Fix | Delete
*/
[375] Fix | Delete
if ( empty( $image ) ) {
[376] Fix | Delete
$site_image = jetpack_og_get_fallback_social_image( $width, $height );
[377] Fix | Delete
if ( ! empty( $site_image ) ) {
[378] Fix | Delete
$image['src'] = $site_image['src'];
[379] Fix | Delete
$image['width'] = $site_image['width'];
[380] Fix | Delete
$image['height'] = $site_image['height'];
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
// If we didn't get an explicit alt tag from the image, set a default.
[385] Fix | Delete
if ( empty( $image['alt_text'] ) ) {
[386] Fix | Delete
/**
[387] Fix | Delete
* Filter the default Open Graph image alt text, used when the Open Graph image from the post does not have an alt text.
[388] Fix | Delete
*
[389] Fix | Delete
* @since 10.4
[390] Fix | Delete
*
[391] Fix | Delete
* @param string $str Default Open Graph image alt text.
[392] Fix | Delete
*/
[393] Fix | Delete
$image['alt_text'] = apply_filters( 'jetpack_open_graph_image_default_alt_text', '' );
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
return $image;
[397] Fix | Delete
}
[398] Fix | Delete
[399] Fix | Delete
/**
[400] Fix | Delete
* Get a fallback social image for the site.
[401] Fix | Delete
*
[402] Fix | Delete
* @since 14.9
[403] Fix | Delete
*
[404] Fix | Delete
* @param int $width The width of the image.
[405] Fix | Delete
* @param int $height The height of the image.
[406] Fix | Delete
*
[407] Fix | Delete
* @return array The source ('src'), 'width', 'height', and source type of the image.
[408] Fix | Delete
*/
[409] Fix | Delete
function jetpack_og_get_fallback_social_image( $width, $height ) {
[410] Fix | Delete
// Default template.
[411] Fix | Delete
$template = 'edge';
[412] Fix | Delete
[413] Fix | Delete
// Let's get the site's representative image.
[414] Fix | Delete
$site_image = jetpack_og_get_site_image( $width, $height );
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Define your own site's representative image,
[418] Fix | Delete
* to override any fallback image found by looking through site's logo, site icon, and blavatar.
[419] Fix | Delete
* This will allow you to overwrite the default fallback image generated dynamically.
[420] Fix | Delete
*
[421] Fix | Delete
* @since 15.0
[422] Fix | Delete
*
[423] Fix | Delete
* @param array $site_image Your own site's representative image.
[424] Fix | Delete
* @param array $site_image The site's representative image picked by Jetpack. {
[425] Fix | Delete
* @type string $src The source of the image.
[426] Fix | Delete
* @type int $width The width of the image.
[427] Fix | Delete
* @type int $height The height of the image.
[428] Fix | Delete
* @type string $type The type of the image.
[429] Fix | Delete
* }
[430] Fix | Delete
*/
[431] Fix | Delete
$custom_site_image = apply_filters( 'jetpack_og_default_site_image', array(), $site_image );
[432] Fix | Delete
if ( ! empty( $custom_site_image['src'] ) ) {
[433] Fix | Delete
return $custom_site_image;
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
if ( empty( $site_image['src'] ) ) {
[437] Fix | Delete
// When using the default blank image, use a different template in Social Image Generator.
[438] Fix | Delete
$template = 'highway';
[439] Fix | Delete
$site_image['src'] = jetpack_og_get_site_fallback_blank_image();
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
/*
[443] Fix | Delete
* Only attempt to generate a dynamic fallback image
[444] Fix | Delete
* if we have a healthy connection to WPCOM.
[445] Fix | Delete
* and if the site has the right plan.
[446] Fix | Delete
*/
[447] Fix | Delete
if (
[448] Fix | Delete
( ( new Host() )->is_wpcom_simple()
[449] Fix | Delete
|| ( new Connection_Manager() )->is_connected()
[450] Fix | Delete
)
[451] Fix | Delete
&& Current_Plan::supports( 'social-image-generator' )
[452] Fix | Delete
) {
[453] Fix | Delete
/**
[454] Fix | Delete
* Allow filtering the template to use with Social Image Generator.
[455] Fix | Delete
* Available templates: highway, dois, fullscreen, edge.
[456] Fix | Delete
*
[457] Fix | Delete
* @since 14.9
[458] Fix | Delete
*
[459] Fix | Delete
* @param string $template The template to use.
[460] Fix | Delete
*/
[461] Fix | Delete
$template = apply_filters( 'jetpack_og_fallback_social_image_template', $template );
[462] Fix | Delete
[463] Fix | Delete
// Let's generate the image.
[464] Fix | Delete
$site_image = jetpack_og_generate_fallback_social_image( $site_image, $template );
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
return $site_image;
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
/**
[471] Fix | Delete
* Get the site's representative image.
[472] Fix | Delete
*
[473] Fix | Delete
* @since 14.9
[474] Fix | Delete
*
[475] Fix | Delete
* @param int $width The width of the image.
[476] Fix | Delete
* @param int $height The height of the image.
[477] Fix | Delete
*
[478] Fix | Delete
* @return array The source ('src'), 'width', 'height', and source type of the image.
[479] Fix | Delete
*/
[480] Fix | Delete
function jetpack_og_get_site_image( $width, $height ) {
[481] Fix | Delete
// First fall back, blavatar.
[482] Fix | Delete
if ( function_exists( 'blavatar_domain' ) ) {
[483] Fix | Delete
$blavatar_domain = blavatar_domain( site_url() );
[484] Fix | Delete
if ( blavatar_exists( $blavatar_domain ) ) {
[485] Fix | Delete
return array(
[486] Fix | Delete
'src' => blavatar_url( $blavatar_domain, 'img', $width, false, true ),
[487] Fix | Delete
'width' => $width,
[488] Fix | Delete
'height' => $height,
[489] Fix | Delete
'type' => 'blavatar',
[490] Fix | Delete
);
[491] Fix | Delete
}
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
// Second fall back, Site Logo.
[495] Fix | Delete
if (
[496] Fix | Delete
function_exists( 'jetpack_has_site_logo' )
[497] Fix | Delete
&& jetpack_has_site_logo()
[498] Fix | Delete
) {
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function