Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/.vscode
/.idea
/.wp-env.json
/.wp-env.test.json

# Tooling and tests
/tests
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ jobs:
shell: bash
run: |
set -euo pipefail
# The full checkout (fetch-depth: 0) already has the base branch.
BASE="origin/${{ github.base_ref }}"
git fetch origin "${{ github.base_ref }}" --depth=1

# Count lines added to the baseline that look like a new ignore entry.
# Commented lines (such as the example in the file header) are skipped.
# grep exits 1 when nothing matches, which pipefail would turn into a failure.
ADDED=$(git diff "$BASE"...HEAD -- phpstan-baseline.neon \
| grep -E '^\+[[:space:]]*message:' \
| { grep -E '^\+[[:space:]]*message:' || true; } \
| wc -l \
| tr -d ' ')

Expand All @@ -43,7 +44,7 @@ jobs:
echo "Detected $ADDED new baseline entries; checking for matching BASELINE: blocks..."

JUSTIFIED=$(git diff "$BASE"...HEAD -- phpstan-baseline.neon \
| grep -E '^\+\s*#\s*BASELINE:' \
| { grep -E '^\+\s*#\s*BASELINE:' || true; } \
| wc -l \
| tr -d ' ')

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/tmp/
/dev/
phpcs.txt
CLAUDE.md

# OS / Editor
.DS_Store
Expand Down
5 changes: 0 additions & 5 deletions CLAUDE.md

This file was deleted.

7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://scanfully.com
Tags: monitoring, site health, broken links, broken media, activity log
Requires at least: 6.0
Tested up to: 7.1.0
Stable tag: 1.8.0
Stable tag: 1.8.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Requires PHP: 7.4
Expand Down Expand Up @@ -206,6 +206,11 @@ Scanfully is designed to keep monitoring work away from frontend page loads. The

== Changelog ==

= 1.8.1: October 16, 2026 =
* Added: WooCommerce checkout monitoring can buy subscription and variable subscription products; subscriptions created by a test order are cancelled right away without sending emails and removed with the test order
* Removed: development-only files from the plugin package
* Fixed: subscriptions created by WooCommerce checkout tests showing in the Subscriptions admin list and its status counts

= 1.8.0: October 13, 2026 =
* Added: site data includes each plugin's latest version from WordPress's own update check, so Scanfully can show which plugins have an update
* Changed: help center and notification channels links now point to docs.scanfully.com
Expand Down
4 changes: 2 additions & 2 deletions scanfully.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @wordpress-plugin
* Plugin Name: Scanfully
* Version: 1.8.0
* Version: 1.8.1
* Plugin URI: https://scanfully.com/wp-plugin
* Description: Scanfully is your favorite WordPress performance and health monitoring tool.
* Author: Scanfully
Expand Down Expand Up @@ -68,7 +68,7 @@ function Scanfully(): \Scanfully\Main { // phpcs:ignore WordPress.NamingConventi
function () {
// meta.
define( 'SCANFULLY_PLUGIN_FILE', __FILE__ );
define( 'SCANFULLY_VERSION', '1.8.0' );
define( 'SCANFULLY_VERSION', '1.8.1' );

// boot.
require __DIR__ . '/vendor/autoload.php';
Expand Down
141 changes: 121 additions & 20 deletions src/WooCheckout/AdminFilter.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,55 @@
<?php
/**
* Admin filter — hide Scanfully probe orders from the WC admin orders list
* by default to keep merchant noise low. Toggle with `?scanfully_show_probe=1`.
* Admin filter — hide Scanfully probe orders, and the subscriptions they create,
* from the WC admin orders and subscriptions lists by default to keep merchant
* noise low. Toggle with `?scanfully_show_probe=1`.
*
* @package Scanfully
*/

namespace Scanfully\WooCheckout;

/**
* Hide probe orders from the WooCommerce admin order list.
* Hide probe orders and probe subscriptions from the WooCommerce admin lists.
*/
class AdminFilter {

public const META_KEY = '_scanfully_probe_order';
public const TOGGLE_PARAM = 'scanfully_show_probe';

/**
* Order types that can be probes: test orders and the subscriptions they create.
*/
private const ORDER_TYPES = [ 'shop_order', 'shop_subscription' ];

/**
* Probe counts per status, keyed by "{backend}:{order type}", cached per request.
*
* @var array<string,array<string,int>>
*/
private static array $probe_counts_cache = [];

/**
* Boot hooks.
*
* @return void
*/
public static function setup(): void {
// HPOS order list (WC 8.0+).
// HPOS order list (WC 8.0+). This generic filter runs for every order type's
// list table, so it covers the WooCommerce Subscriptions list too.
add_filter( 'woocommerce_order_list_table_prepare_items_query_args', [ self::class, 'filter_hpos_query_args' ] );

// Legacy CPT order list.
// Legacy CPT order and subscription lists.
add_action( 'pre_get_posts', [ self::class, 'filter_legacy_orders' ] );

// Status view counts, e.g. "Pending payment (1)". These bypass the list query.
add_filter( 'woocommerce_shop_order_list_table_order_count', [ self::class, 'filter_hpos_status_counts' ], 10, 2 );
add_filter( 'woocommerce_shop_subscription_list_table_order_count', [ self::class, 'filter_hpos_subscription_status_counts' ], 10, 2 );
add_filter( 'wp_count_posts', [ self::class, 'filter_legacy_status_counts' ], 10, 2 );

// WooCommerce Subscriptions replaces the HPOS subscription views at priority 10
// with counts from its own unfiltered query, so correct them afterwards.
add_filter( 'views_woocommerce_page_wc-orders--shop_subscription', [ self::class, 'filter_hpos_subscription_views' ], 20 );
}

/**
Expand Down Expand Up @@ -67,7 +86,7 @@ public static function filter_hpos_query_args( $args ) {
}

/**
* Filter the legacy CPT order-list query to exclude probe orders.
* Filter the legacy CPT order- and subscription-list query to exclude probes.
*
* @param \WP_Query $query The query.
*
Expand All @@ -81,7 +100,7 @@ public static function filter_legacy_orders( $query ): void {
return;
}
$post_type = $query->get( 'post_type' );
if ( 'shop_order' !== $post_type ) {
if ( ! in_array( $post_type, self::ORDER_TYPES, true ) ) {
return;
}
if ( self::should_show_probe_orders() ) {
Expand All @@ -107,10 +126,35 @@ public static function filter_legacy_orders( $query ): void {
* @return int
*/
public static function filter_hpos_status_counts( $count, $status ) {
return self::subtract_hpos_probe_counts( $count, $status, 'shop_order' );
}

/**
* Subtract probe subscriptions from the HPOS subscription status counts.
*
* @param int $count Subscription count for the status(es).
* @param string|string[] $status Status slug(s) being counted.
*
* @return int
*/
public static function filter_hpos_subscription_status_counts( $count, $status ) {
return self::subtract_hpos_probe_counts( $count, $status, 'shop_subscription' );
}

/**
* Subtract probes of one order type from an HPOS status count.
*
* @param int $count Count for the status(es).
* @param string|string[] $status Status slug(s) being counted.
* @param string $type Order type.
*
* @return int
*/
private static function subtract_hpos_probe_counts( $count, $status, string $type ) {
if ( self::should_show_probe_orders() ) {
return $count;
}
$probe_counts = self::get_probe_counts_by_status( 'hpos' );
$probe_counts = self::get_probe_counts_by_status( 'hpos', $type );
foreach ( (array) $status as $slug ) {
if ( isset( $probe_counts[ $slug ] ) ) {
$count -= $probe_counts[ $slug ];
Expand All @@ -120,18 +164,72 @@ public static function filter_hpos_status_counts( $count, $status ) {
}

/**
* Subtract probe orders from the legacy CPT status view counts (wp_count_posts).
* Subtract probe subscriptions from the HPOS subscription status views.
*
* WooCommerce Subscriptions builds these links itself, each as
* `Label <span class="count">(N)</span>`, and leaves out statuses without
* subscriptions; a status view left with only probes is removed the same way.
*
* @param array<string,string> $views View links keyed by status slug.
*
* @return array<string,string>
*/
public static function filter_hpos_subscription_views( $views ) {
if ( ! is_array( $views ) || self::should_show_probe_orders() ) {
return $views;
}
$probe_counts = self::get_probe_counts_by_status( 'hpos', 'shop_subscription' );
if ( empty( $probe_counts ) ) {
return $views;
}

foreach ( $views as $slug => $link ) {
if ( 'all' === $slug ) {
// "All" sums the statuses that show in the all list (not trash).
$probe_count = 0;
foreach ( $probe_counts as $status => $status_count ) {
$status_object = get_post_status_object( $status );
if ( $status_object && $status_object->show_in_admin_all_list ) {
$probe_count += $status_count;
}
}
} else {
$probe_count = $probe_counts[ $slug ] ?? 0;
}
if ( 0 === $probe_count || ! is_string( $link ) ) {
continue;
}

$remaining = null;
$views[ $slug ] = (string) preg_replace_callback(
'/<span class="count">\(([\d.,\s]+)\)<\/span>/',
static function ( array $matches ) use ( $probe_count, &$remaining ): string {
$remaining = max( 0, (int) preg_replace( '/\D/', '', $matches[1] ) - $probe_count );
return '<span class="count">(' . $remaining . ')</span>';
},
$link,
1
);
if ( 0 === $remaining && 'all' !== $slug ) {
unset( $views[ $slug ] );
}
}
return $views;
}

/**
* Subtract probes from the legacy CPT order and subscription status counts (wp_count_posts).
*
* @param \stdClass $counts Counts keyed by post status.
* @param string $type Post type being counted.
*
* @return \stdClass
*/
public static function filter_legacy_status_counts( $counts, $type ) {
if ( 'shop_order' !== $type || self::should_show_probe_orders() ) {
if ( ! in_array( $type, self::ORDER_TYPES, true ) || self::should_show_probe_orders() ) {
return $counts;
}
foreach ( self::get_probe_counts_by_status( 'legacy' ) as $slug => $probe_count ) {
foreach ( self::get_probe_counts_by_status( 'legacy', $type ) as $slug => $probe_count ) {
if ( isset( $counts->$slug ) ) {
$counts->$slug = max( 0, (int) $counts->$slug - $probe_count );
}
Expand All @@ -140,16 +238,17 @@ public static function filter_legacy_status_counts( $counts, $type ) {
}

/**
* Count probe orders per status, cached per request.
* Count probes of one order type per status, cached per request.
*
* @param string $backend Either 'hpos' or 'legacy'.
* @param string $type Order type, 'shop_order' or 'shop_subscription'.
*
* @return array<string,int> Status slug => probe order count.
* @return array<string,int> Status slug => probe count.
*/
private static function get_probe_counts_by_status( string $backend ): array {
static $cache = [];
if ( isset( $cache[ $backend ] ) ) {
return $cache[ $backend ];
private static function get_probe_counts_by_status( string $backend, string $type ): array {
$cache_key = $backend . ':' . $type;
if ( isset( self::$probe_counts_cache[ $cache_key ] ) ) {
return self::$probe_counts_cache[ $cache_key ];
}

global $wpdb;
Expand All @@ -161,8 +260,9 @@ private static function get_probe_counts_by_status( string $backend ): array {
"SELECT o.status AS status, COUNT(*) AS cnt
FROM {$wpdb->prefix}wc_orders o
INNER JOIN {$wpdb->prefix}wc_orders_meta m ON m.order_id = o.id
WHERE o.type = 'shop_order' AND m.meta_key = %s
WHERE o.type = %s AND m.meta_key = %s
GROUP BY o.status",
$type,
self::META_KEY
)
);
Expand All @@ -173,8 +273,9 @@ private static function get_probe_counts_by_status( string $backend ): array {
"SELECT p.post_status AS status, COUNT(*) AS cnt
FROM {$wpdb->posts} p
INNER JOIN {$wpdb->postmeta} m ON m.post_id = p.ID
WHERE p.post_type = 'shop_order' AND m.meta_key = %s
WHERE p.post_type = %s AND m.meta_key = %s
GROUP BY p.post_status",
$type,
self::META_KEY
)
);
Expand All @@ -185,7 +286,7 @@ private static function get_probe_counts_by_status( string $backend ): array {
$counts[ (string) $row->status ] = (int) $row->cnt;
}

$cache[ $backend ] = $counts;
self::$probe_counts_cache[ $cache_key ] = $counts;
return $counts;
}
}
Loading
Loading