| 1 |
<?php |
| 2 |
/** |
| 3 |
* Get robots meta 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 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; // Exit if accessed directly. |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Retrieves ThinkRank site-wide default robots meta settings. |
| 20 |
* |
| 21 |
* These flags form the base robots meta directives applied to the whole site, |
| 22 |
* before any post-type or per-post overrides. |
| 23 |
*/ |
| 24 |
class Get_Robots_Meta_Settings extends Ability_Base { |
| 25 |
/** |
| 26 |
* Option name that stores the global robots meta settings. |
| 27 |
*/ |
| 28 |
private const OPTION = 'thinkrank_global_robot_meta_settings'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Default robots meta directives. |
| 32 |
*/ |
| 33 |
private const DEFAULTS = [ |
| 34 |
'index' => true, |
| 35 |
'noindex' => false, |
| 36 |
'nofollow' => false, |
| 37 |
'noarchive' => false, |
| 38 |
'noimageindex' => false, |
| 39 |
'nosnippet' => false, |
| 40 |
]; |
| 41 |
|
| 42 |
/** |
| 43 |
* Constructor. |
| 44 |
*/ |
| 45 |
public function __construct() { |
| 46 |
$this->id = 'thinkrank/get-robots-meta-settings'; |
| 47 |
$this->label = __( 'Get ThinkRank Robots Meta Settings', 'thinkrank' ); |
| 48 |
$this->description = __( 'Retrieve ThinkRank site-wide default robots meta directives (index, noindex, nofollow, noarchive, noimageindex, nosnippet). Use update-robots-meta-settings to change them.', 'thinkrank' ); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* {@inheritDoc} |
| 53 |
* |
| 54 |
* @return array<string, bool|float|string> |
| 55 |
*/ |
| 56 |
public function get_annotations() { |
| 57 |
return [ |
| 58 |
'readonly' => true, |
| 59 |
'destructive' => false, |
| 60 |
'idempotent' => true, |
| 61 |
'priority' => 1.0, |
| 62 |
'openWorldHint' => false, |
| 63 |
]; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* {@inheritDoc} |
| 68 |
* |
| 69 |
* @return array<string, mixed> |
| 70 |
*/ |
| 71 |
public function get_input_schema() { |
| 72 |
return [ |
| 73 |
'type' => 'object', |
| 74 |
'additionalProperties' => false, |
| 75 |
'properties' => self::empty_properties(), |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* {@inheritDoc} |
| 81 |
* |
| 82 |
* @return array<string, mixed> |
| 83 |
*/ |
| 84 |
public function get_output_schema() { |
| 85 |
return [ |
| 86 |
'type' => 'object', |
| 87 |
'properties' => [ |
| 88 |
'index' => [ 'type' => 'boolean' ], |
| 89 |
'noindex' => [ 'type' => 'boolean' ], |
| 90 |
'nofollow' => [ 'type' => 'boolean' ], |
| 91 |
'noarchive' => [ 'type' => 'boolean' ], |
| 92 |
'noimageindex' => [ 'type' => 'boolean' ], |
| 93 |
'nosnippet' => [ 'type' => 'boolean' ], |
| 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 = wp_parse_args( (array) get_option( self::OPTION, [] ), self::DEFAULTS ); |
| 106 |
|
| 107 |
$out = []; |
| 108 |
foreach ( array_keys( self::DEFAULTS ) as $key ) { |
| 109 |
$out[ $key ] = (bool) ( $settings[ $key ] ?? self::DEFAULTS[ $key ] ); |
| 110 |
} |
| 111 |
|
| 112 |
return $out; |
| 113 |
} |
| 114 |
} |
| 115 |
|