← All changes
|
includes/abilities/settings/class-get-global-settings.php
+23
-2
2.1.0
→
2.9.0
View file →
| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | */ |
| 34 | 34 | public function __construct() { |
| 35 | 35 | $this->id = 'thinkrank/get-global-settings'; |
| 36 | 36 | $this->label = __( 'Get ThinkRank Global Settings', 'thinkrank' ); |
| 37 | - $this->description = __( 'Retrieve ThinkRank global SEO settings. ThinkRank stores these as per-post-type templates; pass a post type to filter.', 'thinkrank' ); | |
| 37 | + $this->description = __( 'Retrieve ThinkRank global SEO settings. ThinkRank stores these as per-post-type templates; pass a post type to filter. Use update-global-settings to change them.', 'thinkrank' ); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * {@inheritDoc} |
| @@ -88,9 +88,9 @@ | ||
| 88 | 88 | /** |
| 89 | 89 | * Execute ability. |
| 90 | 90 | * |
| 91 | 91 | * @param array<string, mixed> $input Ability input payload. |
| 92 | - * @return array<string, mixed> | |
| 92 | + * @return array<string, mixed>|\WP_Error | |
| 93 | 93 | */ |
| 94 | 94 | public function execute( $input ) { |
| 95 | 95 | $all = get_option( self::OPTION_NAME, [] ); |
| 96 | 96 | if ( ! is_array( $all ) ) { |
| @@ -99,8 +99,29 @@ | ||
| 99 | 99 | |
| 100 | 100 | $post_type = isset( $input['post_type'] ) ? sanitize_key( (string) $input['post_type'] ) : ''; |
| 101 | 101 | |
| 102 | 102 | if ( '' !== $post_type ) { |
| 103 | + // A slug this ability cannot answer for used to come back as | |
| 104 | + // `settings: {}`, indistinguishable from a real post type with no | |
| 105 | + // templates configured — so "category", "home" and a typo all read | |
| 106 | + // as "nothing set" (#518). Reject it with the same two checks | |
| 107 | + // thinkrank/update-global-settings applies. | |
| 108 | + if ( ! post_type_exists( $post_type ) ) { | |
| 109 | + return new \WP_Error( | |
| 110 | + 'thinkrank_invalid_post_type', | |
| 111 | + __( 'A valid post type slug is required.', 'thinkrank' ), | |
| 112 | + [ 'status' => 400 ] | |
| 113 | + ); | |
| 114 | + } | |
| 115 | + | |
| 116 | + if ( ! \ThinkRank\SEO\Global_SEO_Post_Types::is_allowed( $post_type ) ) { | |
| 117 | + return new \WP_Error( | |
| 118 | + 'thinkrank_non_public_post_type', | |
| 119 | + __( 'Global SEO settings are only available for valid Global SEO target post types.', 'thinkrank' ), | |
| 120 | + [ 'status' => 400 ] | |
| 121 | + ); | |
| 122 | + } | |
| 123 | + | |
| 103 | 124 | $settings = isset( $all[ $post_type ] ) && is_array( $all[ $post_type ] ) ? $all[ $post_type ] : []; |
| 104 | 125 | |
| 105 | 126 | return [ |
| 106 | 127 | 'post_type' => $post_type, |