| 1 |
<?php |
| 2 |
/** |
| 3 |
* Get author archives settings ability. |
| 4 |
* |
| 5 |
* @package ThinkRank\Abilities\Settings |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
namespace ThinkRank\Abilities\Settings; |
| 11 |
|
| 12 |
use ThinkRank\Abilities\Ability_Base; |
| 13 |
use ThinkRank\Core\Settings; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Retrieves ThinkRank author archives settings. |
| 21 |
* |
| 22 |
* Controls whether author archives are enabled and indexable, whether empty |
| 23 |
* archives are shown, and the SEO title/meta description templates. |
| 24 |
*/ |
| 25 |
class Get_Author_Archives_Settings extends Ability_Base { |
| 26 |
/** |
| 27 |
* Boolean settings: API alias => [ storage_key, default ]. |
| 28 |
*/ |
| 29 |
private const BOOL_MAP = [ |
| 30 |
'enabled' => [ 'author_archives_enabled', true ], |
| 31 |
'show_in_search_results' => [ 'author_archives_index', true ], |
| 32 |
'show_empty_archives' => [ 'author_archives_show_empty', false ], |
| 33 |
]; |
| 34 |
|
| 35 |
/** |
| 36 |
* String settings: API alias => [ storage_key, default ]. |
| 37 |
*/ |
| 38 |
private const STRING_MAP = [ |
| 39 |
'title' => [ 'author_archives_title', Settings::DEFAULT_AUTHOR_ARCHIVES_TITLE ], |
| 40 |
'meta_description' => [ 'author_archives_meta_desc', Settings::DEFAULT_AUTHOR_ARCHIVES_META_DESC ], |
| 41 |
]; |
| 42 |
|
| 43 |
/** |
| 44 |
* Constructor. |
| 45 |
*/ |
| 46 |
public function __construct() { |
| 47 |
$this->id = 'thinkrank/get-author-archives-settings'; |
| 48 |
$this->label = __( 'Get ThinkRank Author Archives Settings', 'thinkrank' ); |
| 49 |
$this->description = __( 'Retrieve ThinkRank author archives settings: enable/index toggles, empty-archive visibility, and the SEO title/meta description templates. Use update-author-archives-settings to change them.', 'thinkrank' ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* {@inheritDoc} |
| 54 |
* |
| 55 |
* @return array<string, bool|float|string> |
| 56 |
*/ |
| 57 |
public function get_annotations() { |
| 58 |
return [ |
| 59 |
'readonly' => true, |
| 60 |
'destructive' => false, |
| 61 |
'idempotent' => true, |
| 62 |
'priority' => 1.0, |
| 63 |
'openWorldHint' => false, |
| 64 |
]; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* {@inheritDoc} |
| 69 |
* |
| 70 |
* @return array<string, mixed> |
| 71 |
*/ |
| 72 |
public function get_input_schema() { |
| 73 |
return [ |
| 74 |
'type' => 'object', |
| 75 |
'additionalProperties' => false, |
| 76 |
'properties' => self::empty_properties(), |
| 77 |
]; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* {@inheritDoc} |
| 82 |
* |
| 83 |
* @return array<string, mixed> |
| 84 |
*/ |
| 85 |
public function get_output_schema() { |
| 86 |
return [ |
| 87 |
'type' => 'object', |
| 88 |
'properties' => [ |
| 89 |
'enabled' => [ 'type' => 'boolean' ], |
| 90 |
'show_in_search_results' => [ 'type' => 'boolean' ], |
| 91 |
'show_empty_archives' => [ 'type' => 'boolean' ], |
| 92 |
'title' => [ 'type' => 'string' ], |
| 93 |
'meta_description' => [ 'type' => 'string' ], |
| 94 |
], |
| 95 |
]; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Execute ability. |
| 100 |
* |
| 101 |
* @param array<string, mixed> $input Ability input payload. |
| 102 |
* @return array<string, mixed> |
| 103 |
*/ |
| 104 |
public function execute( $input ) { |
| 105 |
$settings = Settings::instance(); |
| 106 |
$out = []; |
| 107 |
|
| 108 |
foreach ( self::BOOL_MAP as $alias => $config ) { |
| 109 |
$out[ $alias ] = (bool) $settings->get( $config[0], $config[1] ); |
| 110 |
} |
| 111 |
foreach ( self::STRING_MAP as $alias => $config ) { |
| 112 |
$out[ $alias ] = (string) $settings->get( $config[0], $config[1] ); |
| 113 |
} |
| 114 |
|
| 115 |
return $out; |
| 116 |
} |
| 117 |
} |
| 118 |
|