Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/carousel
File: jetpack-carousel.php
'blog_id' => (int) get_current_blog_id(),
[500] Fix | Delete
'meta_data' => array( 'camera', 'aperture', 'shutter_speed', 'focal_length', 'copyright' ),
[501] Fix | Delete
);
[502] Fix | Delete
[503] Fix | Delete
/**
[504] Fix | Delete
* Handle WP stats for images in full-screen.
[505] Fix | Delete
* Build string with tracking info.
[506] Fix | Delete
*/
[507] Fix | Delete
[508] Fix | Delete
/**
[509] Fix | Delete
* Filter if Jetpack should enable stats collection on carousel views
[510] Fix | Delete
*
[511] Fix | Delete
* @module carousel
[512] Fix | Delete
*
[513] Fix | Delete
* @since 4.3.2
[514] Fix | Delete
*
[515] Fix | Delete
* @param bool Enable Jetpack Carousel stat collection. Default false.
[516] Fix | Delete
*/
[517] Fix | Delete
if ( apply_filters( 'jetpack_enable_carousel_stats', false ) && in_array( 'stats', Jetpack::get_active_modules(), true ) && ! ( new Status() )->is_offline_mode() ) {
[518] Fix | Delete
$localize_strings['stats'] = 'blog=' . Jetpack_Options::get_option( 'id' ) . '&host=' . wp_parse_url( get_option( 'home' ), PHP_URL_HOST ) . '&v=ext&j=' . JETPACK__API_VERSION . ':' . JETPACK__VERSION;
[519] Fix | Delete
[520] Fix | Delete
// Set the stats as empty if user is logged in but logged-in users shouldn't be tracked.
[521] Fix | Delete
if ( is_user_logged_in() ) {
[522] Fix | Delete
$stats_options = Stats_Options::get_options();
[523] Fix | Delete
$track_loggedin_users = isset( $stats_options['count_roles'] ) ? (bool) $stats_options['count_roles'] : false;
[524] Fix | Delete
[525] Fix | Delete
if ( ! $track_loggedin_users ) {
[526] Fix | Delete
$localize_strings['stats'] = '';
[527] Fix | Delete
}
[528] Fix | Delete
}
[529] Fix | Delete
}
[530] Fix | Delete
[531] Fix | Delete
/**
[532] Fix | Delete
* Filter the strings passed to the Carousel's js file.
[533] Fix | Delete
*
[534] Fix | Delete
* @module carousel
[535] Fix | Delete
*
[536] Fix | Delete
* @since 1.6.0
[537] Fix | Delete
*
[538] Fix | Delete
* @param array $localize_strings Array of strings passed to the Jetpack js file.
[539] Fix | Delete
*/
[540] Fix | Delete
$localize_strings = apply_filters( 'jp_carousel_localize_strings', $localize_strings );
[541] Fix | Delete
wp_localize_script( 'jetpack-carousel', 'jetpackCarouselStrings', $localize_strings );
[542] Fix | Delete
wp_enqueue_style(
[543] Fix | Delete
'jetpack-swiper-library',
[544] Fix | Delete
plugins_url( '_inc/blocks/swiper.css', JETPACK__PLUGIN_FILE ),
[545] Fix | Delete
array(),
[546] Fix | Delete
JETPACK__VERSION
[547] Fix | Delete
);
[548] Fix | Delete
wp_enqueue_style( 'jetpack-carousel', plugins_url( 'jetpack-carousel.css', __FILE__ ), array(), $this->asset_version( JETPACK__VERSION ) );
[549] Fix | Delete
wp_style_add_data( 'jetpack-carousel', 'rtl', 'replace' );
[550] Fix | Delete
[551] Fix | Delete
/**
[552] Fix | Delete
* Fires after carousel assets are enqueued for the first time.
[553] Fix | Delete
* Allows for adding additional assets to the carousel page.
[554] Fix | Delete
*
[555] Fix | Delete
* @module carousel
[556] Fix | Delete
*
[557] Fix | Delete
* @since 1.6.0
[558] Fix | Delete
*
[559] Fix | Delete
* @param bool $first_run First load if Carousel on the page.
[560] Fix | Delete
* @param array $localized_strings Array of strings passed to the Jetpack js file.
[561] Fix | Delete
*/
[562] Fix | Delete
do_action( 'jp_carousel_enqueue_assets', $this->first_run, $localize_strings );
[563] Fix | Delete
[564] Fix | Delete
// Add the carousel skeleton to the page.
[565] Fix | Delete
$this->localize_strings = $localize_strings;
[566] Fix | Delete
add_action( 'wp_footer', array( $this, 'add_carousel_skeleton' ) );
[567] Fix | Delete
[568] Fix | Delete
$this->first_run = false;
[569] Fix | Delete
}
[570] Fix | Delete
}
[571] Fix | Delete
[572] Fix | Delete
/**
[573] Fix | Delete
* Generate the HTML skeleton that will be picked up by the Carousel JS and used for showing the carousel.
[574] Fix | Delete
*/
[575] Fix | Delete
public function add_carousel_skeleton() {
[576] Fix | Delete
$localize_strings = $this->localize_strings;
[577] Fix | Delete
$is_light = ( 'white' === $localize_strings['background_color'] );
[578] Fix | Delete
// Determine whether to fall back to standard local comments.
[579] Fix | Delete
$use_local_comments = ! isset( $localize_strings['jetpack_comments_iframe_src'] ) || empty( $localize_strings['jetpack_comments_iframe_src'] );
[580] Fix | Delete
$current_user = wp_get_current_user();
[581] Fix | Delete
$require_name_email = (int) get_option( 'require_name_email' );
[582] Fix | Delete
/* translators: %s is replaced with a field name in the form, e.g. "Email" */
[583] Fix | Delete
$required = ( $require_name_email ) ? __( '%s (Required)', 'jetpack' ) : '%s';
[584] Fix | Delete
?>
[585] Fix | Delete
<div id="jp-carousel-loading-overlay">
[586] Fix | Delete
<div id="jp-carousel-loading-wrapper">
[587] Fix | Delete
<span id="jp-carousel-library-loading">&nbsp;</span>
[588] Fix | Delete
</div>
[589] Fix | Delete
</div>
[590] Fix | Delete
<div class="jp-carousel-overlay<?php echo( $is_light ? ' jp-carousel-light' : '' ); ?>" style="display: none;">
[591] Fix | Delete
[592] Fix | Delete
<div class="jp-carousel-container<?php echo( $is_light ? ' jp-carousel-light' : '' ); ?>">
[593] Fix | Delete
<!-- The Carousel Swiper -->
[594] Fix | Delete
<div
[595] Fix | Delete
class="jp-carousel-wrap swiper jp-carousel-swiper-container jp-carousel-transitions"
[596] Fix | Delete
itemscope
[597] Fix | Delete
itemtype="https://schema.org/ImageGallery">
[598] Fix | Delete
<div class="jp-carousel swiper-wrapper"></div>
[599] Fix | Delete
<div class="jp-swiper-button-prev swiper-button-prev">
[600] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[601] Fix | Delete
<mask id="maskPrev" mask-type="alpha" maskUnits="userSpaceOnUse" x="8" y="6" width="9" height="12">
[602] Fix | Delete
<path d="M16.2072 16.59L11.6496 12L16.2072 7.41L14.8041 6L8.8335 12L14.8041 18L16.2072 16.59Z" fill="white"/>
[603] Fix | Delete
</mask>
[604] Fix | Delete
<g mask="url(#maskPrev)">
[605] Fix | Delete
<rect x="0.579102" width="23.8823" height="24" fill="#FFFFFF"/>
[606] Fix | Delete
</g>
[607] Fix | Delete
</svg>
[608] Fix | Delete
</div>
[609] Fix | Delete
<div class="jp-swiper-button-next swiper-button-next">
[610] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[611] Fix | Delete
<mask id="maskNext" mask-type="alpha" maskUnits="userSpaceOnUse" x="8" y="6" width="8" height="12">
[612] Fix | Delete
<path d="M8.59814 16.59L13.1557 12L8.59814 7.41L10.0012 6L15.9718 12L10.0012 18L8.59814 16.59Z" fill="white"/>
[613] Fix | Delete
</mask>
[614] Fix | Delete
<g mask="url(#maskNext)">
[615] Fix | Delete
<rect x="0.34375" width="23.8822" height="24" fill="#FFFFFF"/>
[616] Fix | Delete
</g>
[617] Fix | Delete
</svg>
[618] Fix | Delete
</div>
[619] Fix | Delete
</div>
[620] Fix | Delete
<!-- The main close buton -->
[621] Fix | Delete
<div class="jp-carousel-close-hint">
[622] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[623] Fix | Delete
<mask id="maskClose" mask-type="alpha" maskUnits="userSpaceOnUse" x="5" y="5" width="15" height="14">
[624] Fix | Delete
<path d="M19.3166 6.41L17.9135 5L12.3509 10.59L6.78834 5L5.38525 6.41L10.9478 12L5.38525 17.59L6.78834 19L12.3509 13.41L17.9135 19L19.3166 17.59L13.754 12L19.3166 6.41Z" fill="white"/>
[625] Fix | Delete
</mask>
[626] Fix | Delete
<g mask="url(#maskClose)">
[627] Fix | Delete
<rect x="0.409668" width="23.8823" height="24" fill="#FFFFFF"/>
[628] Fix | Delete
</g>
[629] Fix | Delete
</svg>
[630] Fix | Delete
</div>
[631] Fix | Delete
<!-- Image info, comments and meta -->
[632] Fix | Delete
<div class="jp-carousel-info">
[633] Fix | Delete
<div class="jp-carousel-info-footer">
[634] Fix | Delete
<div class="jp-carousel-pagination-container">
[635] Fix | Delete
<div class="jp-swiper-pagination swiper-pagination"></div>
[636] Fix | Delete
<div class="jp-carousel-pagination"></div>
[637] Fix | Delete
</div>
[638] Fix | Delete
<div class="jp-carousel-photo-title-container">
[639] Fix | Delete
<h2 class="jp-carousel-photo-caption"></h2>
[640] Fix | Delete
</div>
[641] Fix | Delete
<div class="jp-carousel-photo-icons-container">
[642] Fix | Delete
<a href="#" class="jp-carousel-icon-btn jp-carousel-icon-info" aria-label="<?php esc_attr_e( 'Toggle photo metadata visibility', 'jetpack' ); ?>">
[643] Fix | Delete
<span class="jp-carousel-icon">
[644] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[645] Fix | Delete
<mask id="maskInfo" mask-type="alpha" maskUnits="userSpaceOnUse" x="2" y="2" width="21" height="20">
[646] Fix | Delete
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.7537 2C7.26076 2 2.80273 6.48 2.80273 12C2.80273 17.52 7.26076 22 12.7537 22C18.2466 22 22.7046 17.52 22.7046 12C22.7046 6.48 18.2466 2 12.7537 2ZM11.7586 7V9H13.7488V7H11.7586ZM11.7586 11V17H13.7488V11H11.7586ZM4.79292 12C4.79292 16.41 8.36531 20 12.7537 20C17.142 20 20.7144 16.41 20.7144 12C20.7144 7.59 17.142 4 12.7537 4C8.36531 4 4.79292 7.59 4.79292 12Z" fill="white"/>
[647] Fix | Delete
</mask>
[648] Fix | Delete
<g mask="url(#maskInfo)">
[649] Fix | Delete
<rect x="0.8125" width="23.8823" height="24" fill="#FFFFFF"/>
[650] Fix | Delete
</g>
[651] Fix | Delete
</svg>
[652] Fix | Delete
</span>
[653] Fix | Delete
</a>
[654] Fix | Delete
<?php if ( $localize_strings['display_comments'] ) : ?>
[655] Fix | Delete
<a href="#" class="jp-carousel-icon-btn jp-carousel-icon-comments" aria-label="<?php esc_attr_e( 'Toggle photo comments visibility', 'jetpack' ); ?>">
[656] Fix | Delete
<span class="jp-carousel-icon">
[657] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[658] Fix | Delete
<mask id="maskComments" mask-type="alpha" maskUnits="userSpaceOnUse" x="2" y="2" width="21" height="20">
[659] Fix | Delete
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.3271 2H20.2486C21.3432 2 22.2388 2.9 22.2388 4V16C22.2388 17.1 21.3432 18 20.2486 18H6.31729L2.33691 22V4C2.33691 2.9 3.2325 2 4.3271 2ZM6.31729 16H20.2486V4H4.3271V18L6.31729 16Z" fill="white"/>
[660] Fix | Delete
</mask>
[661] Fix | Delete
<g mask="url(#maskComments)">
[662] Fix | Delete
<rect x="0.34668" width="23.8823" height="24" fill="#FFFFFF"/>
[663] Fix | Delete
</g>
[664] Fix | Delete
</svg>
[665] Fix | Delete
[666] Fix | Delete
<span class="jp-carousel-has-comments-indicator" aria-label="<?php esc_attr_e( 'This image has comments.', 'jetpack' ); ?>"></span>
[667] Fix | Delete
</span>
[668] Fix | Delete
</a>
[669] Fix | Delete
<?php endif; ?>
[670] Fix | Delete
</div>
[671] Fix | Delete
</div>
[672] Fix | Delete
<div class="jp-carousel-info-extra">
[673] Fix | Delete
<div class="jp-carousel-info-content-wrapper">
[674] Fix | Delete
<div class="jp-carousel-photo-title-container">
[675] Fix | Delete
<h2 class="jp-carousel-photo-title"></h2>
[676] Fix | Delete
</div>
[677] Fix | Delete
<div class="jp-carousel-comments-wrapper">
[678] Fix | Delete
<?php if ( $localize_strings['display_comments'] ) : ?>
[679] Fix | Delete
<div id="jp-carousel-comments-loading">
[680] Fix | Delete
<span><?php echo esc_html( $localize_strings['loading_comments'] ); ?></span>
[681] Fix | Delete
</div>
[682] Fix | Delete
<div class="jp-carousel-comments"></div>
[683] Fix | Delete
<div id="jp-carousel-comment-form-container">
[684] Fix | Delete
<span id="jp-carousel-comment-form-spinner">&nbsp;</span>
[685] Fix | Delete
<div id="jp-carousel-comment-post-results"></div>
[686] Fix | Delete
<?php if ( $use_local_comments ) : ?>
[687] Fix | Delete
<?php if ( ! $localize_strings['is_logged_in'] && $localize_strings['comment_registration'] ) : ?>
[688] Fix | Delete
<div id="jp-carousel-comment-form-commenting-as">
[689] Fix | Delete
<p id="jp-carousel-commenting-as">
[690] Fix | Delete
<?php
[691] Fix | Delete
echo wp_kses(
[692] Fix | Delete
__( 'You must be <a href="#" class="jp-carousel-comment-login">logged in</a> to post a comment.', 'jetpack' ),
[693] Fix | Delete
array(
[694] Fix | Delete
'a' => array(
[695] Fix | Delete
'href' => array(),
[696] Fix | Delete
'class' => array(),
[697] Fix | Delete
),
[698] Fix | Delete
)
[699] Fix | Delete
);
[700] Fix | Delete
?>
[701] Fix | Delete
</p>
[702] Fix | Delete
</div>
[703] Fix | Delete
<?php else : ?>
[704] Fix | Delete
<form id="jp-carousel-comment-form">
[705] Fix | Delete
<label for="jp-carousel-comment-form-comment-field" class="screen-reader-text"><?php echo esc_attr( $localize_strings['write_comment'] ); ?></label>
[706] Fix | Delete
<textarea
[707] Fix | Delete
name="comment"
[708] Fix | Delete
class="jp-carousel-comment-form-field jp-carousel-comment-form-textarea"
[709] Fix | Delete
id="jp-carousel-comment-form-comment-field"
[710] Fix | Delete
placeholder="<?php echo esc_attr( $localize_strings['write_comment'] ); ?>"
[711] Fix | Delete
></textarea>
[712] Fix | Delete
<div id="jp-carousel-comment-form-submit-and-info-wrapper">
[713] Fix | Delete
<div id="jp-carousel-comment-form-commenting-as">
[714] Fix | Delete
<?php if ( $localize_strings['is_logged_in'] ) : ?>
[715] Fix | Delete
<p id="jp-carousel-commenting-as">
[716] Fix | Delete
<?php
[717] Fix | Delete
printf(
[718] Fix | Delete
/* translators: %s is replaced with the user's display name */
[719] Fix | Delete
esc_html__( 'Commenting as %s', 'jetpack' ),
[720] Fix | Delete
esc_html( $current_user->data->display_name )
[721] Fix | Delete
);
[722] Fix | Delete
?>
[723] Fix | Delete
</p>
[724] Fix | Delete
<?php else : ?>
[725] Fix | Delete
<fieldset>
[726] Fix | Delete
<label for="jp-carousel-comment-form-email-field"><?php echo esc_html( sprintf( $required, __( 'Email', 'jetpack' ) ) ); ?></label>
[727] Fix | Delete
<input type="text" name="email" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-email-field" />
[728] Fix | Delete
</fieldset>
[729] Fix | Delete
<fieldset>
[730] Fix | Delete
<label for="jp-carousel-comment-form-author-field"><?php echo esc_html( sprintf( $required, __( 'Name', 'jetpack' ) ) ); ?></label>
[731] Fix | Delete
<input type="text" name="author" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-author-field" />
[732] Fix | Delete
</fieldset>
[733] Fix | Delete
<fieldset>
[734] Fix | Delete
<label for="jp-carousel-comment-form-url-field"><?php esc_html_e( 'Website', 'jetpack' ); ?></label>
[735] Fix | Delete
<input type="text" name="url" class="jp-carousel-comment-form-field jp-carousel-comment-form-text-field" id="jp-carousel-comment-form-url-field" />
[736] Fix | Delete
</fieldset>
[737] Fix | Delete
<?php endif ?>
[738] Fix | Delete
</div>
[739] Fix | Delete
<input
[740] Fix | Delete
type="submit"
[741] Fix | Delete
name="submit"
[742] Fix | Delete
class="jp-carousel-comment-form-button"
[743] Fix | Delete
id="jp-carousel-comment-form-button-submit"
[744] Fix | Delete
value="<?php echo esc_attr( $localize_strings['post_comment'] ); ?>" />
[745] Fix | Delete
</div>
[746] Fix | Delete
</form>
[747] Fix | Delete
<?php endif ?>
[748] Fix | Delete
<?php endif ?>
[749] Fix | Delete
</div>
[750] Fix | Delete
<?php endif ?>
[751] Fix | Delete
</div>
[752] Fix | Delete
<div class="jp-carousel-image-meta">
[753] Fix | Delete
<div class="jp-carousel-title-and-caption">
[754] Fix | Delete
<div class="jp-carousel-photo-info">
[755] Fix | Delete
<h3 class="jp-carousel-caption" itemprop="caption description"></h3>
[756] Fix | Delete
</div>
[757] Fix | Delete
[758] Fix | Delete
<div class="jp-carousel-photo-description"></div>
[759] Fix | Delete
</div>
[760] Fix | Delete
<ul class="jp-carousel-image-exif" style="display: none;"></ul>
[761] Fix | Delete
<a class="jp-carousel-image-download" href="#" target="_blank" style="display: none;">
[762] Fix | Delete
<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">
[763] Fix | Delete
<mask id="mask0" mask-type="alpha" maskUnits="userSpaceOnUse" x="3" y="3" width="19" height="18">
[764] Fix | Delete
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.84615 5V19H19.7775V12H21.7677V19C21.7677 20.1 20.8721 21 19.7775 21H5.84615C4.74159 21 3.85596 20.1 3.85596 19V5C3.85596 3.9 4.74159 3 5.84615 3H12.8118V5H5.84615ZM14.802 5V3H21.7677V10H19.7775V6.41L9.99569 16.24L8.59261 14.83L18.3744 5H14.802Z" fill="white"/>
[765] Fix | Delete
</mask>
[766] Fix | Delete
<g mask="url(#mask0)">
[767] Fix | Delete
<rect x="0.870605" width="23.8823" height="24" fill="#FFFFFF"/>
[768] Fix | Delete
</g>
[769] Fix | Delete
</svg>
[770] Fix | Delete
<span class="jp-carousel-download-text"></span>
[771] Fix | Delete
</a>
[772] Fix | Delete
<div class="jp-carousel-image-map" style="display: none;"></div>
[773] Fix | Delete
</div>
[774] Fix | Delete
</div>
[775] Fix | Delete
</div>
[776] Fix | Delete
</div>
[777] Fix | Delete
</div>
[778] Fix | Delete
[779] Fix | Delete
</div>
[780] Fix | Delete
<?php
[781] Fix | Delete
}
[782] Fix | Delete
[783] Fix | Delete
/**
[784] Fix | Delete
* Sets the "in_gallery" flag when the first gallery is encountered (unless in AMP mode).
[785] Fix | Delete
*
[786] Fix | Delete
* @deprecated since 10.8
[787] Fix | Delete
*
[788] Fix | Delete
* @param string $output Gallery shortcode output. Passed through unchanged.
[789] Fix | Delete
*
[790] Fix | Delete
* @return string
[791] Fix | Delete
*/
[792] Fix | Delete
public function set_in_gallery( $output ) {
[793] Fix | Delete
if (
[794] Fix | Delete
class_exists( 'Jetpack_AMP_Support' )
[795] Fix | Delete
&& Jetpack_AMP_Support::is_amp_request()
[796] Fix | Delete
) {
[797] Fix | Delete
return $output;
[798] Fix | Delete
}
[799] Fix | Delete
$this->in_gallery = true;
[800] Fix | Delete
return $output;
[801] Fix | Delete
}
[802] Fix | Delete
[803] Fix | Delete
/**
[804] Fix | Delete
* Adds data-* attributes required by carousel to img tags in post HTML
[805] Fix | Delete
* content. To be used by 'the_content' filter.
[806] Fix | Delete
*
[807] Fix | Delete
* @see add_data_to_images()
[808] Fix | Delete
* @see wp_make_content_images_responsive() in wp-includes/media.php
[809] Fix | Delete
*
[810] Fix | Delete
* @param string $content HTML content of the post.
[811] Fix | Delete
* @return string
[812] Fix | Delete
*/
[813] Fix | Delete
public function add_data_img_tags_and_enqueue_assets( $content ) {
[814] Fix | Delete
if ( ! is_string( $content ) || $content === '' ) {
[815] Fix | Delete
return '';
[816] Fix | Delete
}
[817] Fix | Delete
if (
[818] Fix | Delete
class_exists( 'Jetpack_AMP_Support' )
[819] Fix | Delete
&& Jetpack_AMP_Support::is_amp_request()
[820] Fix | Delete
) {
[821] Fix | Delete
return $this->maybe_add_amp_lightbox( $content );
[822] Fix | Delete
}
[823] Fix | Delete
[824] Fix | Delete
if ( ! preg_match_all( '/<img [^>]+>/', $content, $matches ) ) {
[825] Fix | Delete
return $content;
[826] Fix | Delete
}
[827] Fix | Delete
$selected_images = array();
[828] Fix | Delete
foreach ( $matches[0] as $image_html ) {
[829] Fix | Delete
if (
[830] Fix | Delete
preg_match( '/(wp-image-|data-id=)\"?([0-9]+)\"?/i', $image_html, $class_id )
[831] Fix | Delete
&& ! str_contains( $image_html, 'wp-block-jetpack-slideshow_image' )
[832] Fix | Delete
) {
[833] Fix | Delete
/**
[834] Fix | Delete
* Allow filtering the attachment ID used to fetch and populate metadata about an image in a gallery.
[835] Fix | Delete
*
[836] Fix | Delete
* @module carousel
[837] Fix | Delete
*
[838] Fix | Delete
* @since 12.6
[839] Fix | Delete
*
[840] Fix | Delete
* @param int $attachment_id Attachment ID pulled from image HTML.
[841] Fix | Delete
* @param string $image_html Full HTML image tag.
[842] Fix | Delete
*/
[843] Fix | Delete
$attachment_id = absint(
[844] Fix | Delete
apply_filters(
[845] Fix | Delete
'jetpack_carousel_image_attachment_id',
[846] Fix | Delete
$class_id[2],
[847] Fix | Delete
$image_html
[848] Fix | Delete
)
[849] Fix | Delete
);
[850] Fix | Delete
[851] Fix | Delete
/**
[852] Fix | Delete
* The same image tag may be used more than once but with different attribs,
[853] Fix | Delete
* so save each of them against the attachment id.
[854] Fix | Delete
*/
[855] Fix | Delete
if ( ! isset( $selected_images[ $attachment_id ] ) || ! in_array( $image_html, $selected_images[ $attachment_id ], true ) ) {
[856] Fix | Delete
$selected_images[ $attachment_id ][] = $image_html;
[857] Fix | Delete
}
[858] Fix | Delete
}
[859] Fix | Delete
}
[860] Fix | Delete
[861] Fix | Delete
$find = array();
[862] Fix | Delete
$replace = array();
[863] Fix | Delete
if ( empty( $selected_images ) ) {
[864] Fix | Delete
return $content;
[865] Fix | Delete
}
[866] Fix | Delete
[867] Fix | Delete
$attachments = get_posts(
[868] Fix | Delete
array(
[869] Fix | Delete
'include' => array_keys( $selected_images ),
[870] Fix | Delete
'post_type' => 'any',
[871] Fix | Delete
'post_status' => 'any',
[872] Fix | Delete
'suppress_filters' => false,
[873] Fix | Delete
)
[874] Fix | Delete
);
[875] Fix | Delete
[876] Fix | Delete
foreach ( $attachments as $attachment ) {
[877] Fix | Delete
/*
[878] Fix | Delete
* If the item from get_posts isn't an attachment, skip. This can occur when copy-pasta from another WP site.
[879] Fix | Delete
* For example, if one copies "<img class="wp-image-7 size-full" src="https://twentysixteendemo.files.wordpress.com/2015/11/post.png" alt="post" width="1000" height="563" />"
[880] Fix | Delete
* then, we're going to look up post 7 below, which making sure it is an attachment.
[881] Fix | Delete
*
[882] Fix | Delete
* This is meant as a relatively quick fix, as a better fix is likely to update the get_posts call above to only
[883] Fix | Delete
* include attachments.
[884] Fix | Delete
*/
[885] Fix | Delete
if (
[886] Fix | Delete
! isset( $attachment->ID )
[887] Fix | Delete
|| ! wp_attachment_is_image( $attachment->ID )
[888] Fix | Delete
|| ! isset( $selected_images[ $attachment->ID ] )
[889] Fix | Delete
) {
[890] Fix | Delete
continue;
[891] Fix | Delete
}
[892] Fix | Delete
$image_elements = $selected_images[ $attachment->ID ];
[893] Fix | Delete
[894] Fix | Delete
if ( ! is_array( $image_elements ) ) {
[895] Fix | Delete
continue;
[896] Fix | Delete
}
[897] Fix | Delete
[898] Fix | Delete
$attributes = $this->add_data_to_images( array(), $attachment );
[899] Fix | Delete
$attributes_html = '';
[900] Fix | Delete
foreach ( $attributes as $k => $v ) {
[901] Fix | Delete
$attributes_html .= esc_attr( $k ) . '="' . esc_attr( $v ) . '" ';
[902] Fix | Delete
}
[903] Fix | Delete
foreach ( $image_elements as $image_html ) {
[904] Fix | Delete
$find[] = $image_html;
[905] Fix | Delete
$replace[] = str_replace( '<img ', "<img $attributes_html", $image_html );
[906] Fix | Delete
}
[907] Fix | Delete
}
[908] Fix | Delete
[909] Fix | Delete
$content = str_replace( $find, $replace, $content );
[910] Fix | Delete
$this->enqueue_assets();
[911] Fix | Delete
return $content;
[912] Fix | Delete
}
[913] Fix | Delete
[914] Fix | Delete
/**
[915] Fix | Delete
* Adds the data attributes themselves to img tags.
[916] Fix | Delete
*
[917] Fix | Delete
* @see add_data_img_tags_and_enqueue_assets()
[918] Fix | Delete
* @see https://developer.wordpress.org/reference/functions/wp_get_attachment_image/ Documentation about wp_get_attachment_image
[919] Fix | Delete
*
[920] Fix | Delete
* @param string[] $attr Array of attribute values for the image markup, keyed by attribute name.
[921] Fix | Delete
* @param null|WP_Post $attachment Image attachment post.
[922] Fix | Delete
*
[923] Fix | Delete
* @return string[] Modified image attributes.
[924] Fix | Delete
*/
[925] Fix | Delete
public function add_data_to_images( $attr, $attachment = null ) {
[926] Fix | Delete
if (
[927] Fix | Delete
class_exists( 'Jetpack_AMP_Support' )
[928] Fix | Delete
&& Jetpack_AMP_Support::is_amp_request()
[929] Fix | Delete
) {
[930] Fix | Delete
return $attr;
[931] Fix | Delete
}
[932] Fix | Delete
[933] Fix | Delete
if (
[934] Fix | Delete
! $attachment instanceof WP_Post
[935] Fix | Delete
|| ! isset( $attachment->ID )
[936] Fix | Delete
|| ! wp_attachment_is_image( $attachment )
[937] Fix | Delete
) {
[938] Fix | Delete
return $attr;
[939] Fix | Delete
}
[940] Fix | Delete
[941] Fix | Delete
$attachment_id = (int) $attachment->ID;
[942] Fix | Delete
$orig_file = wp_get_attachment_image_src( $attachment_id, 'full' );
[943] Fix | Delete
$orig_file = isset( $orig_file[0] ) ? $orig_file[0] : wp_get_attachment_url( $attachment_id );
[944] Fix | Delete
$meta = wp_get_attachment_metadata( $attachment_id );
[945] Fix | Delete
$size = isset( $meta['width'] ) ? (int) $meta['width'] . ',' . (int) $meta['height'] : '';
[946] Fix | Delete
$img_meta = ( ! empty( $meta['image_meta'] ) ) ? (array) $meta['image_meta'] : array();
[947] Fix | Delete
$comments_opened = (int) comments_open( $attachment_id );
[948] Fix | Delete
[949] Fix | Delete
/**
[950] Fix | Delete
* Note: Cannot generate a filename from the width and height wp_get_attachment_image_src() returns because
[951] Fix | Delete
* it takes the $content_width global variable themes can set in consideration, therefore returning sizes
[952] Fix | Delete
* which when used to generate a filename will likely result in a 404 on the image.
[953] Fix | Delete
* $content_width has no filter we could temporarily de-register, run wp_get_attachment_image_src(), then
[954] Fix | Delete
* re-register. So using returned file URL instead, which we can define the sizes from through filename
[955] Fix | Delete
* parsing in the JS, as this is a failsafe file reference.
[956] Fix | Delete
*
[957] Fix | Delete
* EG with Twenty Eleven activated:
[958] Fix | Delete
* array(4) { [0]=> string(82) "http://vanillawpinstall.blah/wp-content/uploads/2012/06/IMG_3534-1024x764.jpg" [1]=> int(584) [2]=> int(435) [3]=> bool(true) }
[959] Fix | Delete
*
[960] Fix | Delete
* EG with Twenty Ten activated:
[961] Fix | Delete
* array(4) { [0]=> string(82) "http://vanillawpinstall.blah/wp-content/uploads/2012/06/IMG_3534-1024x764.jpg" [1]=> int(640) [2]=> int(477) [3]=> bool(true) }
[962] Fix | Delete
*/
[963] Fix | Delete
[964] Fix | Delete
$medium_file_info = wp_get_attachment_image_src( $attachment_id, 'medium' );
[965] Fix | Delete
$medium_file = isset( $medium_file_info[0] ) ? $medium_file_info[0] : '';
[966] Fix | Delete
[967] Fix | Delete
$large_file_info = wp_get_attachment_image_src( $attachment_id, 'large' );
[968] Fix | Delete
$large_file = isset( $large_file_info[0] ) ? $large_file_info[0] : '';
[969] Fix | Delete
[970] Fix | Delete
$attachment_title = wptexturize( $attachment->post_title );
[971] Fix | Delete
$attachment_desc = wpautop( wptexturize( $attachment->post_content ) );
[972] Fix | Delete
$attachment_caption = wpautop( wptexturize( $attachment->post_excerpt ) );
[973] Fix | Delete
[974] Fix | Delete
// See https://github.com/Automattic/jetpack/issues/2765.
[975] Fix | Delete
if ( isset( $img_meta['keywords'] ) ) {
[976] Fix | Delete
unset( $img_meta['keywords'] );
[977] Fix | Delete
}
[978] Fix | Delete
[979] Fix | Delete
$img_meta = wp_json_encode( array_map( 'strval', array_filter( $img_meta, 'is_scalar' ) ), JSON_UNESCAPED_SLASHES | JSON_HEX_AMP );
[980] Fix | Delete
[981] Fix | Delete
$attr['data-attachment-id'] = $attachment_id;
[982] Fix | Delete
$attr['data-permalink'] = esc_attr( get_permalink( $attachment_id ) );
[983] Fix | Delete
$attr['data-orig-file'] = esc_attr( $orig_file );
[984] Fix | Delete
$attr['data-orig-size'] = $size;
[985] Fix | Delete
$attr['data-comments-opened'] = $comments_opened;
[986] Fix | Delete
$attr['data-image-meta'] = esc_attr( $img_meta );
[987] Fix | Delete
// The lines below use `esc_attr( htmlspecialchars( ) )` because esc_attr tries to be too smart and won't double-encode, and we need that here.
[988] Fix | Delete
$attr['data-image-title'] = esc_attr( htmlspecialchars( $attachment_title, ENT_COMPAT ) );
[989] Fix | Delete
$attr['data-image-description'] = esc_attr( htmlspecialchars( $attachment_desc, ENT_COMPAT ) );
[990] Fix | Delete
$attr['data-image-caption'] = esc_attr( htmlspecialchars( $attachment_caption, ENT_COMPAT ) );
[991] Fix | Delete
$attr['data-medium-file'] = esc_attr( $medium_file );
[992] Fix | Delete
$attr['data-large-file'] = esc_attr( $large_file );
[993] Fix | Delete
return $attr;
[994] Fix | Delete
}
[995] Fix | Delete
[996] Fix | Delete
/**
[997] Fix | Delete
* Add additional attributes to the Gallery container HTML.
[998] Fix | Delete
*
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function