Skip to content

Commit

Permalink
#1049 #1050 Proper escaping of atts in alt tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MARQAS committed Aug 18, 2017
1 parent f4c4f93 commit b206a96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions templates/features.php
Expand Up @@ -3311,6 +3311,9 @@ function ampforwp_thumbnail_alt(){
$thumb_alt = esc_attr(get_post_meta( $thumb_id, '_wp_attachment_image_alt', true));
if($thumb_alt){
echo "alt = '$thumb_alt'";
$thumb_alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true) ;
if($thumb_alt){
echo 'alt = "'. esc_attr($thumb_alt). '"';
}
}
// For Post ID in Body tag #1006
Expand Down
12 changes: 6 additions & 6 deletions templates/frontpage-elements.php
Expand Up @@ -47,15 +47,15 @@ function ampforwp_design_1_frontpage_content( $template, $post_id ){
$thumb_id = get_post_thumbnail_id($post_id);
$image = wp_get_attachment_image_src( $thumb_id, 'medium' );
$caption = get_the_post_thumbnail_caption( $post_id );
$thumb_alt = esc_attr(get_post_meta( $thumb_id, '_wp_attachment_image_alt', true));
$thumb_alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true);
if($thumb_alt){
$alt = $thumb_alt;
}
else{
$alt = get_the_title( $post_id );
}
?>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo $alt; ?>" > </amp-img>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo esc_attr($alt); ?>" > </amp-img>
<?php if ( $caption ) : ?>
<p class="wp-caption-text">
<?php echo wp_kses_data( $caption ); ?>
Expand Down Expand Up @@ -100,7 +100,7 @@ function ampforwp_design_2_frontpage_content($template, $post_id){
<?php if (has_post_thumbnail( $post_id ) ): ?>
<figure class="amp-wp-article-featured-image wp-caption"> <?php
$thumb_id = get_post_thumbnail_id($post_id);
$thumb_alt = esc_attr(get_post_meta( $thumb_id, '_wp_attachment_image_alt', true));
$thumb_alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true);
if($thumb_alt){
$alt = $thumb_alt;
}
Expand All @@ -109,7 +109,7 @@ function ampforwp_design_2_frontpage_content($template, $post_id){
}
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'medium' );
$caption = get_the_post_thumbnail_caption( $post_id ); ?>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo $alt; ?>" > </amp-img>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo esc_attr($alt); ?>" > </amp-img>
<?php if ( $caption ) : ?>
<p class="wp-caption-text">
<?php echo wp_kses_data( $caption ); ?>
Expand Down Expand Up @@ -152,7 +152,7 @@ function ampforwp_design_3_frontpage_content($template, $post_id){
<?php if (has_post_thumbnail( $post_id ) ): ?>
<figure class="amp-wp-article-featured-image wp-caption"> <?php
$thumb_id = get_post_thumbnail_id($post_id);
$thumb_alt = esc_attr(get_post_meta( $thumb_id, '_wp_attachment_image_alt', true));
$thumb_alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true);
if($thumb_alt){
$alt = $thumb_alt;
}
Expand All @@ -161,7 +161,7 @@ function ampforwp_design_3_frontpage_content($template, $post_id){
}
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'medium' );
$caption = get_the_post_thumbnail_caption( $post_id ); ?>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo $alt; ?>" > </amp-img>
<amp-img src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" layout=responsive alt="<?php echo esc_attr($alt); ?>" > </amp-img>
<?php if ( $caption ) : ?>
<p class="wp-caption-text">
<?php echo wp_kses_data( $caption ); ?>
Expand Down

0 comments on commit b206a96

Please sign in to comment.