PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.7.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.7.0
2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 All 48 releases
thinkrank / includes / abilities / media / class-get-image-alt-text.php

class-get-image-alt-text.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.7.0, at includes/abilities/media/class-get-image-alt-text.php

93 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Get image alt text ability.
4 *
5 * @package ThinkRank\Abilities\Media
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\Abilities\Media;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 /**
17 * Reads one image's stored alt text. Read-only.
18 */
19 class Get_Image_Alt_Text extends Image_Alt_Ability_Base {
20
21 /**
22 * Constructor.
23 */
24 public function __construct() {
25 $this->id = 'thinkrank/get-image-alt-text';
26 $this->label = __( 'Get ThinkRank Image Alt Text', 'thinkrank' );
27 $this->description = __( 'Read one image\'s alt text from the Media Library, along with its title, filename and URL. Use list-images to find ids, and update-image-alt-text to change the value.', 'thinkrank' );
28 }
29
30 /**
31 * {@inheritDoc}
32 *
33 * @return array<string, bool|float|string>
34 */
35 public function get_annotations() {
36 return [
37 'readonly' => true,
38 'destructive' => false,
39 'idempotent' => true,
40 'priority' => 1.0,
41 'openWorldHint' => false,
42 ];
43 }
44
45 /**
46 * {@inheritDoc}
47 *
48 * @return array<string, mixed>
49 */
50 public function get_input_schema() {
51 return [
52 'type' => 'object',
53 'additionalProperties' => false,
54 'required' => [ 'attachment_id' ],
55 'properties' => [
56 'attachment_id' => [
57 'type' => 'integer',
58 'description' => __( 'Attachment ID from list-images.', 'thinkrank' ),
59 ],
60 ],
61 ];
62 }
63
64 /**
65 * {@inheritDoc}
66 *
67 * @return array<string, mixed>
68 */
69 public function get_output_schema() {
70 return [
71 'type' => 'object',
72 'properties' => $this->image_properties(),
73 ];
74 }
75
76 /**
77 * Execute ability.
78 *
79 * @param array<string, mixed> $input Ability input payload.
80 * @return array<string, mixed>|\WP_Error
81 */
82 public function execute( $input ) {
83 $attachment_id = (int) ( ( (array) $input )['attachment_id'] ?? 0 );
84
85 $rejection = $this->reject_if_not_an_image( $attachment_id );
86 if ( null !== $rejection ) {
87 return $rejection;
88 }
89
90 return $this->describe_image( $attachment_id );
91 }
92 }
93