array( 'type' => 'string', 'description' => __( 'Start date, YYYY-MM-DD. Defaults with end_date to Search Console\'s last 28 days.', 'acrossai-abilities-manager' ), ), 'end_date' => array( 'type' => 'string', 'description' => __( 'End date, YYYY-MM-DD. Search Console data lags about two days, so a range ending today returns nothing for its last days.', 'acrossai-abilities-manager' ), ), 'dimensions' => array( 'type' => 'array', 'items' => array( 'type' => 'string' ), 'description' => __( 'How to break the totals down: query, page, country, device, date. Omit for site-wide totals over the period.', 'acrossai-abilities-manager' ), ), 'url' => array( 'type' => 'string', 'description' => __( 'Restrict the report to one page URL.', 'acrossai-abilities-manager' ), ), 'limit' => array( 'type' => 'integer', 'default' => 20, 'minimum' => 1, 'maximum' => 1000, 'description' => __( 'Maximum rows to return.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'rows' => array( 'type' => 'array' ), 'request' => array( 'type' => 'object' ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $result = Report_Repository::search_analytics( $input ); if ( is_wp_error( $result ) ) { return $result; } $count = count( $result['rows'] ); $result['message'] = 0 === $count // An empty result is almost never an error here, and saying so saves a // round of debugging a connection that is working fine. ? __( 'Search Console returned no rows for that period. That usually means the range is too recent — its data lags about two days — or the page filter matched nothing it has data for.', 'acrossai-abilities-manager' ) : sprintf( /* translators: %d: number of rows */ __( 'Search Console returned %d rows.', 'acrossai-abilities-manager' ), $count ); return $result; } }