Skip to content

Commit

Permalink
Add speculation rules in Dashboard using the new filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Swanand01 committed May 9, 2024
1 parent f4c9750 commit e85b4dc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions includes/Admin/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public function register(): void {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
add_action( 'admin_notices', [ $this, 'display_link_to_dashboard' ] );
add_action( 'load-web-story_page_stories-dashboard', [ $this, 'load_stories_dashboard' ] );
add_filter( 'web_stories_speculation_rules', [ $this, 'load_speculation_rules' ] );
}

/**
Expand Down Expand Up @@ -573,4 +574,32 @@ public function display_link_to_dashboard(): void {
</div>
<?php
}

/**
* Load the Speculation Rules for the Dashboard.
*
* @return array An array containing prerendering rules.
*/
public function load_speculation_rules(): array {
$new_story_url = sprintf(
'post-new.php?post_type=%s',
$this->story_post_type->get_slug()
);
$edit_story_url = 'post.php?post=*&action=edit';
return [
'prerender' => [
[
'source' => 'document',
'where' => [
'and' => [
[
'href_matches' => [ $edit_story_url, $new_story_url ],
],
],
],
'eagerness' => 'moderate',
],
],
];
}
}

0 comments on commit e85b4dc

Please sign in to comment.