diff --git a/readme.txt b/readme.txt index 1668ea4..e12e9d1 100644 --- a/readme.txt +++ b/readme.txt @@ -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.9.0 +Stable tag: 1.9.1 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html Requires PHP: 7.4 @@ -215,7 +215,7 @@ Once connected, the plugin sends data to the Scanfully API at api.scanfully.com * The WordPress activity described above, as it happens. It includes the display name of the person who made a change, and the old and new value of a changed setting. Content and file editor changes are sent as a short diff of the lines that changed. * For accounts with elevated rights only: their email address with their user events, and the IP address and browser of their logins and of the first use of an application password. * Failed logins as counts per hour, with the accounts with elevated rights that were tried, but without IP addresses or the usernames tried. -* When WooCommerce checkout monitoring is on: the shop details its test checkout needs, such as the product, shipping method and checkout page. Scanfully then places test orders, which the plugin cancels and removes. +* When WooCommerce is active: the shop details a test checkout needs, such as the product, shipping method and checkout page, on connect, once a day and when they change. Scanfully only places test orders when WooCommerce checkout monitoring is on for the site, and the plugin cancels and removes them. Email deliverability checks are on by default: the plugin sends test emails to a Scanfully address through your site's own mail setup. You can turn them off under Settings > Scanfully. @@ -226,6 +226,11 @@ Scanfully's [terms and conditions](https://scanfully.com/terms/) and [privacy po == Changelog == += 1.9.1: October 27, 2026 = +* Fixed: the WooCommerce checkout test reported a false failure on shops with Mollie +* Fixed: test orders of the WooCommerce checkout test no longer email the shop a cancelled order notice, which WooCommerce 11 started sending, and no other WooCommerce email is sent about a test order +* Fixed: FooEvents tickets, Greyd Forms entries, WP RSS Aggregator feed items and WP User Activity log entries no longer show in the activity log as saved posts + = 1.9.0: October 19, 2026 = * Added: the activity log reports what changed in a saved post, posts deleted permanently, categories, tags and other terms, and bulk actions as one row listing every post or term * Added: media library changes, every setting of the core settings screens, navigation menus and widgets, Customizer theme settings, and Site Editor styles, templates, template parts and fonts in the activity log diff --git a/scanfully.php b/scanfully.php index efa243d..bc4047a 100644 --- a/scanfully.php +++ b/scanfully.php @@ -8,7 +8,7 @@ * * @wordpress-plugin * Plugin Name: Scanfully - * Version: 1.9.0 + * Version: 1.9.1 * Plugin URI: https://scanfully.com/wp-plugin * Description: Scanfully is your favorite WordPress performance and health monitoring tool. * Author: Scanfully @@ -68,7 +68,7 @@ function Scanfully(): \Scanfully\Main { // phpcs:ignore WordPress.NamingConventi function () { // meta. define( 'SCANFULLY_PLUGIN_FILE', __FILE__ ); - define( 'SCANFULLY_VERSION', '1.9.0' ); + define( 'SCANFULLY_VERSION', '1.9.1' ); // boot. require __DIR__ . '/vendor/autoload.php'; diff --git a/src/Events/PostSaved.php b/src/Events/PostSaved.php index 21708fe..0ef8fcc 100644 --- a/src/Events/PostSaved.php +++ b/src/Events/PostSaved.php @@ -214,6 +214,14 @@ private static function summarize_post( $post ): ?array { 'acf-field-group', // SEOPress logs every request for a missing URL as a post. 'seopress_404', + // FooEvents saves a post for every ticket sold, and changes it when + // the ticket is checked in. + 'event_magic_tickets', + // Greyd Forms saves every form entry as a post. + 'tp_forms_entry', + // WP RSS Aggregator saves every item it imports from a feed as a + // post, and deletes old ones. + 'wprss_feed_item', ]; /** @@ -283,10 +291,10 @@ public static function is_reported( object $post ): bool { /** * Whether saves of this post type are reported. Skips internal types, - * types without an admin screen, and every WooCommerce order type: with - * HPOS, each order also saves a backup post (a placeholder, or a - * `shop_order` draft when sync is on), which would otherwise turn every - * checkout into a timeline event. + * types without an admin screen, the log of WP User Activity, and every + * WooCommerce order type: with HPOS, each order also saves a backup post + * (a placeholder, or a `shop_order` draft when sync is on), which would + * otherwise turn every checkout into a timeline event. * * @param string $post_type The post type. * @@ -301,8 +309,30 @@ public static function is_tracked_post_type( string $post_type ): bool { return false; } + if ( self::is_user_activity_log( $post_type ) ) { + return false; + } + $type_object = get_post_type_object( $post_type ); return is_object( $type_object ) && ! empty( $type_object->show_ui ); } + + /** + * Whether a post type is the log of WP User Activity, another activity + * log plugin that saves every entry as a post. Its name (`activity`) is + * too common to skip while that plugin is not active. + * + * @param string $post_type The post type. + * + * @return bool + */ + private static function is_user_activity_log( string $post_type ): bool { + // Version 2.3.0 and later name the type with a filter. + if ( function_exists( 'wp_user_activity_get_post_type' ) ) { + return wp_user_activity_get_post_type() === $post_type; + } + + return 'activity' === $post_type && function_exists( '_wp_user_activity' ); + } } diff --git a/src/WooCheckout/BlocksIntegration.php b/src/WooCheckout/BlocksIntegration.php index 2aa0eba..ea678b8 100644 --- a/src/WooCheckout/BlocksIntegration.php +++ b/src/WooCheckout/BlocksIntegration.php @@ -38,6 +38,29 @@ static function ( $registry ) { } } ); + add_action( 'woocommerce_blocks_payment_method_type_registration', [ self::class, 'keep_only_probe_method' ], PHP_INT_MAX ); + } + + /** + * During a validated probe request, unregister every other block payment + * method. ProbeGateway leaves only the probe gateway registered, and some + * block integrations (Mollie) throw when their own gateway is missing, + * which breaks every page that loads the payment method registry, + * product pages included. + * + * @param object $registry The WooCommerce Blocks payment method registry. + * + * @return void + */ + public static function keep_only_probe_method( $registry ): void { + if ( ! Controller::is_probe_request() || ! method_exists( $registry, 'get_all_registered' ) || ! method_exists( $registry, 'unregister' ) ) { + return; + } + foreach ( array_keys( $registry->get_all_registered() ) as $name ) { + if ( Controller::PROBE_GATEWAY_ID !== $name ) { + $registry->unregister( $name ); + } + } } /** diff --git a/src/WooCheckout/ProbeGateway.php b/src/WooCheckout/ProbeGateway.php index 6774343..260067a 100644 --- a/src/WooCheckout/ProbeGateway.php +++ b/src/WooCheckout/ProbeGateway.php @@ -52,14 +52,13 @@ public static function setup(): void { add_filter( 'woocommerce_available_payment_gateways', [ self::class, 'filter_available_gateways' ], 99 ); // Probe-only filters: suppress emails + prevent stock decrement. - add_filter( 'woocommerce_email_recipient_new_order', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); - add_filter( 'woocommerce_email_recipient_customer_processing_order', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); - add_filter( 'woocommerce_email_recipient_customer_on_hold_order', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); - // WooCommerce Subscriptions: the subscription a probe order creates - // is cancelled right away, which would otherwise email the shop. - add_filter( 'woocommerce_email_recipient_cancelled_subscription', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); - add_filter( 'woocommerce_email_recipient_expired_subscription', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); - add_filter( 'woocommerce_email_recipient_suspended_subscription', [ self::class, 'suppress_email_for_probe' ], 10, 2 ); + // Every registered email is covered, not a list: WooCommerce 11 emails + // the admin on pending -> cancelled, and WooCommerce Subscriptions + // emails the shop when the probe subscription is cancelled. + add_action( 'woocommerce_email', [ self::class, 'suppress_probe_emails' ] ); + if ( did_action( 'woocommerce_email' ) && function_exists( 'WC' ) ) { + self::suppress_probe_emails( WC()->mailer() ); + } add_filter( 'woocommerce_can_reduce_order_stock', [ self::class, 'skip_stock_reduction_for_probe' ], 10, 2 ); add_filter( 'woocommerce_webhook_should_deliver', [ self::class, 'skip_webhooks_for_probe' ], 10, 3 ); @@ -169,8 +168,9 @@ private static function probe_only_gateways( array $gateways ): array { * plugin-owned stub PSP URL. * * The scan ends at the stub PSP, so the order is cancelled right away. - * Cancelling releases the stock WooCommerce reserved at checkout, and - * pending -> cancelled sends no email. Subscriptions the order created + * Cancelling releases the stock WooCommerce reserved at checkout; the + * cancelled order email it triggers is suppressed with every other email + * of a tagged order (suppress_probe_emails). Subscriptions the order created * (WooCommerce Subscriptions) are tagged before and cancelled after, so * their emails stay suppressed and the cleanup deletes them too. * @@ -264,6 +264,26 @@ private static function cancel_subscription( \WC_Order $subscription ): void { } } + /** + * Hook the probe suppression into the recipient filter of every email the + * WooCommerce mailer has registered, including those added by other + * plugins through `woocommerce_email_classes`. + * + * @param \WC_Emails|object $mailer The WooCommerce mailer. + * + * @return void + */ + public static function suppress_probe_emails( $mailer ): void { + if ( ! is_object( $mailer ) || ! method_exists( $mailer, 'get_emails' ) ) { + return; + } + foreach ( (array) $mailer->get_emails() as $email ) { + if ( is_object( $email ) && ! empty( $email->id ) ) { + add_filter( 'woocommerce_email_recipient_' . $email->id, [ self::class, 'suppress_email_for_probe' ], 10, 2 ); + } + } + } + /** * Suppress WC email recipients for probe orders. * diff --git a/tests/Fixtures/wp-user-activity.php b/tests/Fixtures/wp-user-activity.php new file mode 100644 index 0000000..8ab0971 --- /dev/null +++ b/tests/Fixtures/wp-user-activity.php @@ -0,0 +1,18 @@ + true ] ); + + $this->assertSame( + [ + 'created' => 0, + 'updated' => 0, + 'status changed' => 0, + 'trashed' => 0, + 'deleted' => 0, + ], + $this->jobs_queued_per_step( 'event_magic_tickets' ) + ); + } + + public function test_a_greyd_forms_entry_queues_nothing_from_creation_to_deletion(): void { + // Greyd Forms registers the type with an admin screen and saves a + // post for every form a visitor sends. + register_post_type( 'tp_forms_entry', [ 'show_ui' => true ] ); + + $this->assertSame( + [ + 'created' => 0, + 'updated' => 0, + 'status changed' => 0, + 'trashed' => 0, + 'deleted' => 0, + ], + $this->jobs_queued_per_step( 'tp_forms_entry' ) + ); + } + + public function test_a_wp_rss_aggregator_feed_item_queues_nothing_from_creation_to_deletion(): void { + // WP RSS Aggregator registers the type with an admin screen, saves a + // post for every item it imports from a feed, and deletes old ones. + register_post_type( 'wprss_feed_item', [ 'show_ui' => true ] ); + + $this->assertSame( + [ + 'created' => 0, + 'updated' => 0, + 'status changed' => 0, + 'trashed' => 0, + 'deleted' => 0, + ], + $this->jobs_queued_per_step( 'wprss_feed_item' ) + ); + } + + /** + * Runs in its own process: the plugin's function stays declared. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_a_wp_user_activity_entry_queues_nothing_from_creation_to_deletion(): void { + // WP User Activity registers the type with an admin screen, saves a + // post for every entry of its own activity log, and deletes old ones. + require_once dirname( __DIR__ ) . '/Fixtures/wp-user-activity.php'; + register_post_type( 'activity', [ 'show_ui' => true ] ); + + $this->assertSame( + [ + 'created' => 0, + 'updated' => 0, + 'status changed' => 0, + 'trashed' => 0, + 'deleted' => 0, + ], + $this->jobs_queued_per_step( 'activity' ) + ); + } + + public function test_an_activity_type_is_still_reported_while_wp_user_activity_is_not_active(): void { + register_post_type( 'activity', [ 'show_ui' => true ] ); + + $queued = $this->jobs_queued_per_step( 'activity' ); + + $this->assertSame( 1, $queued['created'] ); + $this->assertSame( 1, $queued['trashed'] ); + } + public function test_a_custom_post_type_with_an_admin_screen_is_still_reported(): void { register_post_type( 'scanfully_test_type', [ 'show_ui' => true ] ); diff --git a/tests/Unit/Events/PostSavedFilterTest.php b/tests/Unit/Events/PostSavedFilterTest.php index 719c814..784ce1a 100644 --- a/tests/Unit/Events/PostSavedFilterTest.php +++ b/tests/Unit/Events/PostSavedFilterTest.php @@ -30,7 +30,7 @@ final class PostSavedFilterTest extends TestCase { * * @var array */ - private array $ui_types = [ 'post', 'page', 'product', 'shop_order', 'seopress_404' ]; + private array $ui_types = [ 'post', 'page', 'product', 'shop_order', 'seopress_404', 'event_magic_tickets', 'tp_forms_entry', 'wprss_feed_item', 'activity', 'site_activity' ]; protected function setUp(): void { parent::setUp(); @@ -97,11 +97,64 @@ public function provide_ignored_saves(): array { 'SEOPress 404 record' => [ 'seopress_404', 'publish' ], 'SEOPress 404 record as a draft' => [ 'seopress_404', 'draft' ], 'trashed SEOPress 404 record' => [ 'seopress_404', 'trash' ], + 'FooEvents ticket' => [ 'event_magic_tickets', 'publish' ], + 'trashed FooEvents ticket' => [ 'event_magic_tickets', 'trash' ], + 'Greyd Forms entry' => [ 'tp_forms_entry', 'publish' ], + 'trashed Greyd Forms entry' => [ 'tp_forms_entry', 'trash' ], + 'WP RSS Aggregator feed item' => [ 'wprss_feed_item', 'publish' ], + 'trashed WP RSS Aggregator feed item' => [ 'wprss_feed_item', 'trash' ], 'custom type without an admin screen' => [ 'my_internal_type', 'publish' ], 'pending review status' => [ 'post', 'pending' ], ]; } + public function test_an_activity_type_is_reported_while_wp_user_activity_is_not_active(): void { + $this->assertTrue( $this->fires( 'activity' ) ); + } + + /** + * Runs in its own process: the plugin's functions stay declared. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_wp_user_activity_entries_do_not_fire(): void { + Functions\when( 'wp_user_activity_get_post_type' )->justReturn( 'activity' ); + + $this->assertFalse( $this->fires( 'activity' ) ); + $this->assertFalse( $this->fires( 'activity', 'trash' ) ); + $this->assertTrue( $this->fires( 'post' ) ); + } + + /** + * Runs in its own process: the plugin's functions stay declared. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_a_renamed_wp_user_activity_type_does_not_fire(): void { + // The `wp_user_activity_get_post_type` filter renamed the type. + Functions\when( 'wp_user_activity_get_post_type' )->justReturn( 'site_activity' ); + + $this->assertFalse( $this->fires( 'site_activity' ) ); + $this->assertTrue( $this->fires( 'activity' ) ); + } + + /** + * Before version 2.3.0 the type was always `activity`, without a + * function to name it. Runs in its own process: the plugin's functions + * stay declared. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_wp_user_activity_entries_before_2_3_do_not_fire(): void { + Functions\when( '_wp_user_activity' )->justReturn( null ); + + $this->assertFalse( $this->fires( 'activity' ) ); + $this->assertTrue( $this->fires( 'post' ) ); + } + public function test_publishing_right_after_saving_a_draft_is_reported(): void { $this->assertTrue( $this->fires( 'post', 'draft', 5 ) ); $this->assertTrue( $this->fires( 'post', 'publish', 5 ), 'The publish event must not be dropped as a duplicate of the draft save.' ); diff --git a/tests/Unit/WooCheckout/BlocksIntegrationTest.php b/tests/Unit/WooCheckout/BlocksIntegrationTest.php new file mode 100644 index 0000000..72b8107 --- /dev/null +++ b/tests/Unit/WooCheckout/BlocksIntegrationTest.php @@ -0,0 +1,92 @@ +set_probe_request( null ); + parent::tearDown(); + } + + /** + * Set the memoised probe-request result. + * + * @param ?bool $is_probe Whether the current request is a probe, null to reset. + */ + private function set_probe_request( ?bool $is_probe ): void { + $property = new ReflectionProperty( Controller::class, 'probe_request_cache' ); + $property->setAccessible( true ); + $property->setValue( null, $is_probe ); + } + + /** + * A registry double holding the given payment method names. + * + * @param string[] $names Registered payment method names. + * + * @return object + */ + private function registry( array $names ): object { + return new class( $names ) { + /** + * Registered methods by name. + * + * @var array + */ + public array $registered; + + /** + * @param string[] $names Registered payment method names. + */ + public function __construct( array $names ) { + $this->registered = array_fill_keys( $names, true ); + } + + /** + * @return array + */ + public function get_all_registered(): array { + return $this->registered; + } + + /** + * @param string $name Payment method name. + */ + public function unregister( string $name ): void { + unset( $this->registered[ $name ] ); + } + }; + } + + public function test_a_probe_request_keeps_only_the_probe_method(): void { + $this->set_probe_request( true ); + $registry = $this->registry( [ 'mollie_wc_gateway_ideal', Controller::PROBE_GATEWAY_ID, 'cod' ] ); + + BlocksIntegration::keep_only_probe_method( $registry ); + + $this->assertSame( [ Controller::PROBE_GATEWAY_ID ], array_keys( $registry->registered ) ); + } + + public function test_a_normal_request_keeps_every_method(): void { + $this->set_probe_request( false ); + $registry = $this->registry( [ 'mollie_wc_gateway_ideal', Controller::PROBE_GATEWAY_ID, 'cod' ] ); + + BlocksIntegration::keep_only_probe_method( $registry ); + + $this->assertSame( [ 'mollie_wc_gateway_ideal', Controller::PROBE_GATEWAY_ID, 'cod' ], array_keys( $registry->registered ) ); + } +} diff --git a/tests/Unit/WooCheckout/ProbeOrderTest.php b/tests/Unit/WooCheckout/ProbeOrderTest.php index 76f33c3..0908ebc 100644 --- a/tests/Unit/WooCheckout/ProbeOrderTest.php +++ b/tests/Unit/WooCheckout/ProbeOrderTest.php @@ -156,6 +156,27 @@ public function test_emails_about_probe_subscriptions_are_suppressed(): void { $this->assertSame( 'shop@scanfully.com', ProbeGateway::suppress_email_for_probe( 'shop@scanfully.com', $this->order( false ) ) ); } + public function test_every_registered_email_gets_the_probe_filter(): void { + $mailer = new class() { + /** + * Registered emails, as WC_Emails::get_emails() returns them. + * + * @return object[] + */ + public function get_emails(): array { + return [ + (object) [ 'id' => 'cancelled_order' ], + (object) [ 'id' => 'cancelled_subscription' ], + ]; + } + }; + + ProbeGateway::suppress_probe_emails( $mailer ); + + $this->assertNotFalse( has_filter( 'woocommerce_email_recipient_cancelled_order', [ ProbeGateway::class, 'suppress_email_for_probe' ] ) ); + $this->assertNotFalse( has_filter( 'woocommerce_email_recipient_cancelled_subscription', [ ProbeGateway::class, 'suppress_email_for_probe' ] ) ); + } + public function test_orders_created_during_a_probe_are_tagged(): void { $this->set_probe_request( true ); $_SERVER['HTTP_X_SCANFULLY_PROBE'] = 'sf-1-abcd:sig';