Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release speculation-rules 1.2.1 #1154

Merged
merged 5 commits into from Apr 16, 2024

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Apr 16, 2024

  • Bump versions in readme.txt and load.php
  • npm run since -- -p speculation-rules -r 1.2.1
  • npm run changelog -- --milestone="speculation-rules 1.2.1"
  • Update readme documentation

@westonruter westonruter added [Type] Documentation Documentation to be added or enhanced [Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) labels Apr 16, 2024
@westonruter westonruter added this to the speculation-rules 1.2.1 milestone Apr 16, 2024
Copy link

github-actions bot commented Apr 16, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: mukeshpanchal27 <mukesh27@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter
Copy link
Member Author

westonruter commented Apr 16, 2024

Build for testing: speculation-rules.zip

image

Build command:

npm run build:plugin:speculation-rules; 
cd build; 
zip -r speculation-rules.zip speculation-rules

Diff of changes via:

git diff 3.0.0...plugin-release/speculation-rules-1.2.1 -- plugins/speculation-rules
diff --git a/plugins/speculation-rules/helper.php b/plugins/speculation-rules/helper.php
index d210edb1..804ab63f 100644
--- a/plugins/speculation-rules/helper.php
+++ b/plugins/speculation-rules/helper.php
@@ -42,6 +42,7 @@ function plsr_get_speculation_rules() {
 	$base_href_exclude_paths = array(
 		$prefixer->prefix_path_pattern( '/wp-login.php', 'site' ),
 		$prefixer->prefix_path_pattern( '/wp-admin/*', 'site' ),
+		$prefixer->prefix_path_pattern( '/*\\?*(^|&)_wpnonce=*', 'site' ),
 	);
 	$href_exclude_paths      = $base_href_exclude_paths;
 
@@ -77,7 +78,7 @@ function plsr_get_speculation_rules() {
 			'source'    => 'document',
 			'where'     => array(
 				'and' => array(
-					// Prerender any URLs within the same site.
+					// Include any URLs within the same site.
 					array(
 						'href_matches' => $prefixer->prefix_path_pattern( '/*' ),
 					),
@@ -87,6 +88,12 @@ function plsr_get_speculation_rules() {
 							'href_matches' => $href_exclude_paths,
 						),
 					),
+					// Also exclude rel=nofollow links, as plugins like WooCommerce use that on their add-to-cart links.
+					array(
+						'not' => array(
+							'selector_matches' => 'a[rel=nofollow]',
+						),
+					),
 				),
 			),
 			'eagerness' => $eagerness,
diff --git a/plugins/speculation-rules/load.php b/plugins/speculation-rules/load.php
index 37156cf3..c0d77702 100644
--- a/plugins/speculation-rules/load.php
+++ b/plugins/speculation-rules/load.php
@@ -4,8 +4,8 @@
  * Plugin URI: https://github.com/WordPress/performance/tree/trunk/plugins/speculation-rules
  * Description: Enables browsers to speculatively prerender or prefetch pages when hovering over links.
  * Requires at least: 6.4
- * Requires PHP: 7.0
- * Version: 1.2.0
+ * Requires PHP: 7.2
+ * Version: 1.2.1
  * Author: WordPress Performance Team
  * Author URI: https://make.wordpress.org/performance/
  * License: GPLv2 or later
@@ -25,7 +25,8 @@ if ( defined( 'SPECULATION_RULES_VERSION' ) ) {
 	return;
 }
 
-define( 'SPECULATION_RULES_VERSION', '1.2.0' );
+define( 'SPECULATION_RULES_VERSION', '1.2.1' );
+define( 'SPECULATION_RULES_MAIN_FILE', plugin_basename( __FILE__ ) );
 
 require_once __DIR__ . '/class-plsr-url-pattern-prefixer.php';
 require_once __DIR__ . '/helper.php';
diff --git a/plugins/speculation-rules/readme.txt b/plugins/speculation-rules/readme.txt
index c6f6dd19..2cde137c 100644
--- a/plugins/speculation-rules/readme.txt
+++ b/plugins/speculation-rules/readme.txt
@@ -3,8 +3,8 @@
 Contributors:      wordpressdotorg
 Requires at least: 6.4
 Tested up to:      6.5
-Requires PHP:      7.0
-Stable tag:        1.2.0
+Requires PHP:      7.2
+Stable tag:        1.2.1
 License:           GPLv2 or later
 License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 Tags:              performance, javascript, speculation rules, prerender, prefetch
@@ -19,7 +19,7 @@ See the [Speculation Rules WICG specification draft](https://wicg.github.io/nav-
 
 By default, the plugin is configured to prerender WordPress frontend URLs when the user hovers over a relevant link. This can be customized via the "Speculative Loading" section under _Settings > Reading_.
 
-A filter can be used to exclude certain URL paths from being eligible for prefetching and prerendering (see FAQ section). Alternatively, you can add the 'no-prerender' CSS class to any link (`<a>` tag) that should not be prerendered.
+A filter can be used to exclude certain URL paths from being eligible for prefetching and prerendering (see FAQ section). Alternatively, you can add the 'no-prerender' CSS class to any link (`<a>` tag) that should not be prerendered. See FAQ for more information.
 
 = Browser support =
 
@@ -50,7 +50,7 @@ _This plugin was formerly known as Speculation Rules._
 
 = How can I prevent certain URLs from being prefetched and prerendered? =
 
-Not every URL can be reasonably prerendered. Prerendering static content is typically reliable, however prerendering interactive content, such as a logout URL, can lead to issues. For this reason, certain WordPress core URLs such as `/wp-login.php` and `/wp-admin/*` are excluded from prefetching and prerendering. You can exclude additional URL patterns by using the `plsr_speculation_rules_href_exclude_paths` filter.
+Not every URL can be reasonably prerendered. Prerendering static content is typically reliable, however prerendering interactive content, such as a logout URL, can lead to issues. For this reason, certain WordPress core URLs such as `/wp-login.php` and `/wp-admin/*` are excluded from prefetching and prerendering. Additionally, any URL generated with `wp_nonce_url()` (or which contain the `_wpnonce` query var) is also ignored. You can exclude additional URL patterns by using the `plsr_speculation_rules_href_exclude_paths` filter.
 
 This example would ensure that URLs like `https://example.com/cart/` or `https://example.com/cart/foo` would be excluded from prefetching and prerendering.
 `
@@ -86,6 +86,8 @@ add_filter(
 );
 `
 
+As mentioned above, adding the `no-prerender` CSS class to a link will prevent it from being prerendered (but not prefetched). Additionally, links with `rel=nofollow` will neither be prefetched nor prerendered because some plugins add this to non-idempotent links (e.g. add to cart); such links ideally should rather be buttons which trigger a POST request or at least they should use `wp_nonce_url()`.
+
 = Where can I submit my plugin feedback? =
 
 Feedback is encouraged and much appreciated, especially since this plugin may contain future WordPress core features. If you have suggestions or requests for new features, you can [submit them as an issue in the WordPress Performance Team's GitHub repository](https://github.com/WordPress/performance/issues/new/choose). If you need help with troubleshooting or have a question about the plugin, please [create a new topic on our support forum](https://wordpress.org/support/plugin/speculation-rules/#new-topic-0).
@@ -102,6 +104,18 @@ Contributions are always welcome! Learn more about how to get involved in the [C
 
 == Changelog ==
 
+= 1.2.1 =
+
+**Enhancements**
+
+* Add settings link to Speculative Loading plugin action links. ([1145](https://github.com/WordPress/performance/pull/1145))
+* Bump minimum PHP version to 7.2. ([1130](https://github.com/WordPress/performance/pull/1130))
+
+**Bug Fixes**
+
+* Exclude _wpnonce URLs in speculation rules. ([1143](https://github.com/WordPress/performance/pull/1143))
+* Exclude rel=nofollow links from prefetch/prerender. ([1142](https://github.com/WordPress/performance/pull/1142))
+
 = 1.2.0 =
 
 * Add missing uninstall.php to remove plugin's database option. ([1128](https://github.com/WordPress/performance/pull/1128))
diff --git a/plugins/speculation-rules/settings.php b/plugins/speculation-rules/settings.php
index 9b10007b..1c39a9f6 100644
--- a/plugins/speculation-rules/settings.php
+++ b/plugins/speculation-rules/settings.php
@@ -149,7 +149,11 @@ function plsr_add_setting_ui() {
 			</p>
 			<?php
 		},
-		'reading'
+		'reading',
+		array(
+			'before_section' => '<div id="speculative-loading">',
+			'after_section'  => '</div>',
+		)
 	);
 
 	$fields = array(
@@ -236,3 +240,29 @@ function plsr_render_settings_field( array $args ) {
 	</fieldset>
 	<?php
 }
+
+/**
+ * Adds a settings link to the plugin's action links.
+ *
+ * @since 1.2.1
+ *
+ * @param string[]|mixed $links An array of plugin action links.
+ * @return string[]|mixed The modified list of actions.
+ */
+function plsr_add_settings_action_link( $links ) {
+	if ( ! is_array( $links ) ) {
+		return $links;
+	}
+
+	return array_merge(
+		array(
+			'settings' => sprintf(
+				'<a href="%1$s">%2$s</a>',
+				esc_url( admin_url( 'options-reading.php#speculative-loading' ) ),
+				esc_html__( 'Settings', 'speculation-rules' )
+			),
+		),
+		$links
+	);
+}
+add_filter( 'plugin_action_links_' . SPECULATION_RULES_MAIN_FILE, 'plsr_add_settings_action_link' );

Copy link
Member

@adamsilverstein adamsilverstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spectacular

@github-actions github-actions bot temporarily deployed to wp.org plugin: speculation-rules April 16, 2024 18:22 Destroyed
@github-actions github-actions bot temporarily deployed to wp.org plugin: speculation-rules April 16, 2024 18:26 Destroyed
@westonruter
Copy link
Member Author

1.2.1 is now released: https://wordpress.org/plugins/speculation-rules/

@westonruter westonruter merged commit 528429d into trunk Apr 16, 2024
31 checks passed
@westonruter westonruter deleted the plugin-release/speculation-rules-1.2.1 branch April 16, 2024 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Speculative Loading Issues for the Speculative Loading plugin (formerly Speculation Rules) [Type] Documentation Documentation to be added or enhanced
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants