Skip to content

Commit

Permalink
Add validation_errors, validated_url_post, and stale to scannable-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 7, 2021
1 parent 55d8a74 commit 3986b6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Validation/ScannableURLsRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

namespace AmpProject\AmpWP\Validation;

use WP_Error;
use WP_REST_Controller;
use AMP_Validated_URL_Post_Type;
use AmpProject\AmpWP\Infrastructure\Delayed;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
use WP_Error;
use WP_Post;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
Expand Down Expand Up @@ -85,6 +87,23 @@ public function get_items( $request ) { // phpcs:ignore VariableAnalysis.CodeAna
static function ( $entry ) {
$entry['amp_url'] = amp_add_paired_endpoint( $entry['url'] );

$validated_url_post = AMP_Validated_URL_Post_Type::get_invalid_url_post( $entry['url'] );
if ( $validated_url_post instanceof WP_Post ) {
$entry['validation_errors'] = [];

$data = json_decode( $validated_url_post->post_content, true );
if ( is_array( $data ) ) {
$entry['validation_errors'] = wp_list_pluck( $data, 'data' );
}

$entry['validated_url_post'] = [
'id' => $validated_url_post->ID,
'edit_link' => get_edit_post_link( $validated_url_post->ID, 'raw' ),
];

$entry['stale'] = ( count( AMP_Validated_URL_Post_Type::get_post_staleness( $validated_url_post ) ) > 0 );
}

return $entry;
},
$this->scannable_url_provider->get_urls()
Expand Down
2 changes: 2 additions & 0 deletions src/Validation/URLValidationRESTController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/**
* URLValidationRESTController class.
*
* @todo This can now be eliminated in favor of making validate requests to the frontend with `?amp_validate[cache]=true`.
*
* @since 2.1
* @internal
*/
Expand Down

0 comments on commit 3986b6e

Please sign in to comment.