array( 'type' => 'string', 'enum' => array( 'all', 'type', 'post' ), 'default' => 'all', 'description' => __( 'What to invalidate.', 'acrossai-abilities-manager' ), ), 'type' => array( 'type' => 'string', 'description' => __( 'Sitemap type, required for scope=type. Matches a post type or taxonomy name.', 'acrossai-abilities-manager' ), ), 'post_id' => array( 'type' => 'integer', 'minimum' => 1, 'description' => __( 'Post id, required for scope=post.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'scope' => array( 'type' => 'string' ), 'target' => array( 'type' => 'string' ), 'invalidated' => array( 'type' => 'boolean' ), 'cache_enabled' => array( 'type' => 'boolean' ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => false, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $scope = isset( $input['scope'] ) ? sanitize_key( (string) $input['scope'] ) : 'all'; if ( ! in_array( $scope, array( 'all', 'type', 'post' ), true ) ) { return new WP_Error( 'invalid_input', __( 'scope must be all, type or post.', 'acrossai-abilities-manager' ) ); } $type = isset( $input['type'] ) ? sanitize_key( (string) $input['type'] ) : ''; $post_id = isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0; $result = Sitemap_Repository::invalidate( $scope, $type, $post_id ); if ( is_wp_error( $result ) ) { return $result; } $result['message'] = $result['cache_enabled'] ? sprintf( /* translators: %s: what was invalidated */ __( 'Invalidated the Rank Math sitemap cache for %s.', 'acrossai-abilities-manager' ), $result['target'] ) : __( 'Sitemap file caching is disabled, so there was nothing to invalidate — the sitemap is already generated on every request.', 'acrossai-abilities-manager' ); return $result; } }