Skip to content

Commit

Permalink
TMS-1017: Add news image alt-text
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Mar 8, 2024
1 parent 8043d16 commit beb2f7b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning][semver].

## [Unreleased]

- TMS-1017: Add news image alt-text

## [0.3.0] - 2022-04-11

- PIEN-8157: PHP 8.1
Expand Down
11 changes: 11 additions & 0 deletions src/ImportObjectData.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ public function get_image() {
return empty( $image ) ? '' : $image->image_full_url;
}

/**
* Get image alternative text.
*
* @return string
*/
public function get_image_alt() {
$image = $this->object_data->field_main_image->field_media_image ?: null;

return empty( $image ) ? '' : $image->meta->alt;
}

/**
* Get target sites.
*
Expand Down
6 changes: 6 additions & 0 deletions src/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public function create_importable_object( object $import_object ) : PostImportab
'key' => 'image_url',
'value' => $import_object->get_image(),
],
[
'key' => 'image_alt',
'value' => $import_object->get_image_alt(),
],
[
'key' => 'writing_credits',
'value' => $import_object->get_writing_credits(),
Expand Down Expand Up @@ -236,6 +240,7 @@ public function insert_post( int $id ) : void {
$target_site = unserialize( get_post_meta( $id, 'wp_site_id', true ) );

Check warning on line 240 in src/Importer.php

View workflow job for this annotation

GitHub Actions / phpcs-check

unserialize() found. Serialized data has known vulnerability problems with Object Injection. JSON is generally a better approach for serializing data. See https://www.owasp.org/index.php/PHP_Object_Injection
$drupal_post_id = get_post_meta( $id, 'drupal_post_id', true );
$image_url = get_post_meta( $id, 'image_url', true );
$image_alt = get_post_meta( $id, 'image_alt', true );
$post_lang = pll_get_post_language( $id );
$writing_credits = get_post_meta( $id, 'writing_credits', true );
$image_credits = get_post_meta( $id, 'image_credits', true );
Expand Down Expand Up @@ -267,6 +272,7 @@ public function insert_post( int $id ) : void {
'drupal_post_id' => $drupal_post_id,
'wp_site_id' => $site,
'image_url' => $image_url,
'image_alt' => $image_alt,
'writing_credits' => $writing_credits,
'image_credits' => $image_credits,
],
Expand Down

0 comments on commit beb2f7b

Please sign in to comment.