| 1 |
<?php |
| 2 |
namespace AATXT\App; |
| 3 |
|
| 4 |
class AltTextGeneratorParentPostTitle implements AltTextGeneratorInterface |
| 5 |
{ |
| 6 |
private function __construct() |
| 7 |
{ |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* @return AltTextGeneratorParentPostTitle |
| 12 |
*/ |
| 13 |
public static function make(): AltTextGeneratorParentPostTitle |
| 14 |
{ |
| 15 |
return new self(); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Get the alt text of the image |
| 20 |
* @param int $imageId |
| 21 |
* @return string |
| 22 |
*/ |
| 23 |
public function altText(int $imageId): string |
| 24 |
{ |
| 25 |
$parentPost = get_post_parent($imageId); |
| 26 |
|
| 27 |
if (empty($parentPost)) { |
| 28 |
return ''; |
| 29 |
} |
| 30 |
|
| 31 |
return get_the_title($parentPost); |
| 32 |
} |
| 33 |
} |