Skip to content

Commit

Permalink
Accessibility: use mediafile alt text in player #1109
Browse files Browse the repository at this point in the history
  • Loading branch information
zahardev committed Mar 18, 2024
1 parent 70a70d2 commit 59ed6ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions php/classes/handlers/class-images-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,30 @@ public function is_image_square( $image_data = array() ) {
*/
public function get_attachment_image_src( $attachment_id, $size = 'medium' ) {
$src = wp_get_attachment_image_src( $attachment_id, $size );
return $this->make_associative_image_src( $src );
return $this->make_associative_image_src( $src, $attachment_id );
}

/**
* Convert the array returned from wp_get_attachment_image_src into a human readable version
*
* @param $image_data_array
*
* @return mixed
* @param array $image_data_array
* @param int|null $attachment_id
*
* @return array
*/
protected function make_associative_image_src( $image_data_array ) {
$new_image_data_array = array();
if ( is_array( $image_data_array ) && $image_data_array ) {
$new_image_data_array['src'] = isset( $image_data_array[0] ) ? $image_data_array[0] : '';
$new_image_data_array['width'] = isset( $image_data_array[1] ) ? $image_data_array[1] : '';
$new_image_data_array['height'] = isset( $image_data_array[2] ) ? $image_data_array[2] : '';
protected function make_associative_image_src( $image_data_array, $attachment_id = null ) {
if ( ! is_array( $image_data_array ) || ! $image_data_array ) {
return array();
}

$new_image_data_array['src'] = isset( $image_data_array[0] ) ? $image_data_array[0] : '';
$new_image_data_array['width'] = isset( $image_data_array[1] ) ? $image_data_array[1] : '';
$new_image_data_array['height'] = isset( $image_data_array[2] ) ? $image_data_array[2] : '';

$alt_text = $attachment_id ? get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) : '';

$new_image_data_array['alt'] = $alt_text ?: '';

return $new_image_data_array;
}
}
2 changes: 1 addition & 1 deletion templates/players/castos-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="player">
<div class="player__main">
<div class="player__artwork player__artwork-<?php echo $episode_id?>">
<img src="<?php echo apply_filters( 'ssp_album_art_cover', $album_art['src'], get_the_ID() ); ?>" alt="<?php echo $podcast_title ?>" title="<?php echo $podcast_title ?>">
<img src="<?php echo apply_filters( 'ssp_album_art_cover', $album_art['src'], get_the_ID() ); ?>" alt="<?php echo $album_art['alt'] ?: $podcast_title ?>" title="<?php echo $podcast_title ?>">
</div>
<div class="player__body">
<div class="currently-playing">
Expand Down

0 comments on commit 59ed6ad

Please sign in to comment.