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
5 changes: 5 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# scanfully-plugin

Repository instructions, shared with VS Code Copilot:

@.github/copilot-instructions.md
11 changes: 9 additions & 2 deletions 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.7.0
Stable tag: 1.8.0
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Requires PHP: 7.4
Expand Down Expand Up @@ -131,7 +131,7 @@ This helps you detect problems affecting contact forms, password resets, WooComm

Scanfully notifies you when monitored events need your attention.

You decide where those notifications should go using [notification channels](https://scanfully.com/docs/channels/).
You decide where those notifications should go using [notification channels](https://docs.scanfully.com/notifications/).

Scanfully currently supports email, Slack, Discord, and Pushover.

Expand Down Expand Up @@ -206,6 +206,13 @@ Scanfully is designed to keep monitoring work away from frontend page loads. The

== Changelog ==

= 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
* Fixed: a sync requested from the dashboard now runs right away instead of waiting for the next visit to the site or for the pending regular syncs
* Fixed: jobs scheduled within ten minutes of an uninstall being stored under the deleted Action Scheduler group
* Security: the connect flow uses PKCE, so an authorization code that ends up anywhere else cannot be exchanged for tokens

= 1.7.0: September 21, 2026 =
* Added: WooCommerce checkout monitoring support.
* Added: PHPCS, PHPStan, PHPUnit and wp-env tooling with composer scripts and QA workflow
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.7.0
* Version: 1.8.0
* 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.7.0' );
define( 'SCANFULLY_VERSION', '1.8.0' );

// boot.
require __DIR__ . '/vendor/autoload.php';
Expand Down
100 changes: 84 additions & 16 deletions src/Connect/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ private static function handle_connect_start(): void {
// the WordPress installation URL (which may be in a subdirectory).
$connect_url = add_query_arg(
[
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'code_challenge' => self::code_challenge( self::generate_code_verifier() ),
'code_challenge_method' => 'S256',
],
Main::get_connect_url()
);
Expand Down Expand Up @@ -157,9 +159,11 @@ private static function handle_reconnect(): void {
// build the connect URL and redirect directly into the connect flow.
$connect_url = add_query_arg(
[
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'code_challenge' => self::code_challenge( self::generate_code_verifier() ),
'code_challenge_method' => 'S256',
],
Main::get_connect_url()
);
Expand Down Expand Up @@ -198,13 +202,18 @@ private static function handle_request_connect_success(): void {
$code = sanitize_text_field( wp_unslash( $_GET['code'] ) );
$site = sanitize_text_field( wp_unslash( $_GET['site'] ) );

// the PKCE verifier proves to the API that this site started the
// connect request; like the state, it is single use.
$verifier = self::get_code_verifier();
self::delete_code_verifier();

// the site ID ends up in API URL paths, so only allow plain ID characters.
if ( 1 !== preg_match( '/^[A-Za-z0-9_-]{1,64}\z/', $site ) ) {
wp_die( 'Invalid Scanfully connect parameters' );
}

// exchange authorization code for access token.
$tokens = self::exchange_authorization_code( $code, $site );
$tokens = self::exchange_authorization_code( $code, $site, $verifier );

// validate token response so we fail gracefully if the API is unreachable or returned an error.
if ( empty( $tokens['access_token'] )
Expand Down Expand Up @@ -307,11 +316,21 @@ function () use ( $message, $type ) {
* Exchange the authorization code for an access and refresh token.
*
* @param string $code The authorization code.
* @param string $site The Scanfully site ID.
* @param string $site The Scanfully site ID.
* @param string $verifier The PKCE code verifier of the connect request, or an empty string without one.
*
* @return array<string, mixed> The token response (access_token, refresh_token, expires), or an empty array on failure.
*/
private static function exchange_authorization_code( string $code, string $site ): array {
private static function exchange_authorization_code( string $code, string $site, string $verifier ): array {

$body = [
'grant_type' => 'authorization_code',
'code' => $code,
'site_id' => $site,
];
if ( '' !== $verifier ) {
$body['code_verifier'] = $verifier;
}

// request arguments for the requests.
$request_args = [
Expand All @@ -320,13 +339,7 @@ private static function exchange_authorization_code( string $code, string $site
'blocking' => true,
'httpversion' => '1.0',
'sslverify' => Main::get_sslverify(),
'body' => wp_json_encode(
[
'grant_type' => 'authorization_code',
'code' => $code,
'site_id' => $site,
]
),
'body' => wp_json_encode( $body ),
];

// later check if post failed and show a notice to admins.
Expand Down Expand Up @@ -482,4 +495,59 @@ public static function delete_state(): void {
private static function get_state_key(): string {
return 'scanfully_connect_state_' . get_current_user_id();
}

/**
* Generate and store the PKCE code verifier (RFC 7636) for a connect
* request of the current user. The API only exchanges the code for a
* request that started with its challenge for the verifier, so a code
* that ends up elsewhere is worthless.
*
* @return string The verifier: 64 random letters and digits.
*/
public static function generate_code_verifier(): string {
$verifier = wp_generate_password( 64, false, false );
set_transient( self::get_code_verifier_key(), $verifier, 15 * MINUTE_IN_SECONDS );

return $verifier;
}

/**
* Get the stored PKCE code verifier of the current user.
*
* @return string The verifier, or an empty string when there is none.
*/
public static function get_code_verifier(): string {
$verifier = get_transient( self::get_code_verifier_key() );

return is_string( $verifier ) ? $verifier : '';
}

/**
* Delete the stored PKCE code verifier of the current user.
*
* @return void
*/
public static function delete_code_verifier(): void {
delete_transient( self::get_code_verifier_key() );
}

/**
* The S256 challenge of a code verifier: its SHA-256, base64url without padding.
*
* @param string $verifier The code verifier.
*
* @return string
*/
public static function code_challenge( string $verifier ): string {
return rtrim( strtr( base64_encode( hash( 'sha256', $verifier, true ) ), '+/', '-_' ), '=' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- base64url is the encoding RFC 7636 requires.
}

/**
* Get the transient key holding the PKCE code verifier for the current user.
*
* @return string
*/
private static function get_code_verifier_key(): string {
return 'scanfully_connect_verifier_' . get_current_user_id();
}
}
2 changes: 1 addition & 1 deletion src/Connect/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function render_page(): void {
</div>
<div class="scanfully-setup-footer">
<p>version <?php echo esc_html( SCANFULLY_VERSION ); ?></p>
<p><a href="https://scanfully.com/docs/"><?php esc_html_e( 'help center', 'scanfully' ); ?></a> - <a href="https://scanfully.com/contact/"><?php esc_html_e( 'contact us', 'scanfully' ); ?></a></p>
<p><a href="https://docs.scanfully.com/"><?php esc_html_e( 'help center', 'scanfully' ); ?></a> - <a href="https://scanfully.com/contact/"><?php esc_html_e( 'contact us', 'scanfully' ); ?></a></p>
</div>
</div>
<?php
Expand Down
30 changes: 30 additions & 0 deletions src/Health/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ private static function get_db_size(): int {
*/
private static function get_plugins(): array {
$plugins = get_plugins();
$updates = get_site_transient( 'update_plugins' );

$map = [];

Expand All @@ -391,6 +392,7 @@ private static function get_plugins(): array {
'slug' => '.' === $folder ? basename( $basename, '.php' ) : $folder,
'url' => $plugin['PluginURI'],
'version' => $plugin['Version'],
'latest_version' => self::get_latest_version( $updates, $plugin_path ),
'description' => $plugin['Description'],
'author' => $plugin['Author'],
'author_uri' => $plugin['AuthorURI'],
Expand All @@ -400,6 +402,34 @@ private static function get_plugins(): array {
return $map;
}

/**
* Get the latest version of a plugin as WordPress's own update check knows
* it, which covers premium plugins with their own updater too.
*
* @param mixed $updates The update_plugins site transient.
* @param string $plugin_path The plugin's file, relative to the plugins folder.
*
* @return string|null The latest version, or null when WordPress does not know it.
*/
private static function get_latest_version( $updates, string $plugin_path ): ?string {
if ( ! is_object( $updates ) ) {
return null;
}

// "response" holds the plugins with an update, "no_update" the ones
// that are up to date.
foreach ( [ 'response', 'no_update' ] as $list ) {
$item = $updates->{$list}[ $plugin_path ] ?? null;
// Some third-party updaters add an array instead of an object.
$version = is_array( $item ) ? ( $item['new_version'] ?? null ) : ( is_object( $item ) ? ( $item->new_version ?? null ) : null );
if ( is_scalar( $version ) && '' !== (string) $version ) {
return (string) $version;
}
}

return null;
}

/**
* Get the site data sent to Scanfully.
*
Expand Down
34 changes: 30 additions & 4 deletions src/Sync/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ private static function get_request_token( \WP_REST_Request $request ): string {

/**
* Handle an on-demand sync request. Schedules the existing health and
* directory syncs to run as soon as possible and returns immediately.
* directory syncs, starts the queue runner so they run now, and returns
* immediately.
*
* @return \WP_REST_Response
*/
Expand All @@ -137,6 +138,7 @@ public static function handle_sync(): \WP_REST_Response {
set_transient( self::RATE_LIMIT_TRANSIENT, time(), self::RATE_LIMIT_WINDOW );

self::schedule_syncs();
self::run_queue_now();

return new \WP_REST_Response( [ 'status' => 'scheduled' ], 202 );
}
Expand All @@ -153,8 +155,32 @@ private static function schedule_syncs(): void {
return;
}

// Unique: parallel requests can't queue duplicate syncs.
as_schedule_single_action( time(), Cron\Controller::ACTION_SYNC_SITE_HEALTH, [], self::AS_GROUP, true );
as_schedule_single_action( time(), Cron\Controller::ACTION_SYNC_DIRECTORIES, [], self::AS_GROUP, true );
// Not unique: a unique action is skipped while another one with the
// same hook is pending, and the recurring syncs always are, so the
// request would queue nothing. The rate limit bounds the duplicates.
as_schedule_single_action( time(), Cron\Controller::ACTION_SYNC_SITE_HEALTH, [], self::AS_GROUP );
as_schedule_single_action( time(), Cron\Controller::ACTION_SYNC_DIRECTORIES, [], self::AS_GROUP );
}

/**
* Start Action Scheduler's queue runner now, with the non-blocking
* loopback request (admin-ajax) it sends itself on admin pages. Without
* it the syncs wait for WP-Cron, which only runs on a later visit, so a
* quiet site would not sync until someone loads a page. The runner still
* decides for itself: it only runs with actions due, below its limit of
* concurrent batches, and when no filter turned async requests off.
*
* @return void
*/
private static function run_queue_now(): void {
if ( ! class_exists( 'ActionScheduler' ) || ! class_exists( 'ActionScheduler_AsyncRequest_QueueRunner' ) ) {
return;
}

// The lock keeps the admin shutdown hook from dispatching a second
// runner within its minute; a runner it already started picks up the
// new actions or dispatches again when it finishes.
\ActionScheduler::lock()->set( 'async-request-runner' );
( new \ActionScheduler_AsyncRequest_QueueRunner( \ActionScheduler::store() ) )->maybe_dispatch();
}
}
18 changes: 18 additions & 0 deletions tests/Integration/CleanupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ public function test_uninstall_removes_options_transients_jobs_and_the_probe_use
delete_option( 'unrelated_option_kept' );
}

/**
* Action Scheduler caches group ids, so a job scheduled after uninstall (a
* reinstall, or the next test) must not reuse the deleted group's id.
*
* @depends test_uninstall_keeps_an_account_that_is_not_the_probe_user
*/
public function test_jobs_scheduled_after_uninstall_are_found_by_their_group(): void {
$this->schedule_jobs();

scanfully_uninstall_site();
$this->schedule_jobs();

$this->assertSame( 2, $this->pending_jobs() );

as_unschedule_all_actions( '', [], 'scanfully' );
$this->assertSame( 0, $this->pending_jobs() );
}

/**
* @depends test_uninstall_keeps_an_account_that_is_not_the_probe_user
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Integration/EventSendFailureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function test_a_server_error_marks_the_job_failed_and_queues_a_retry(): v
[
'hook' => EventsController::ACTION_SEND_EVENT,
'args' => [ 'PostSaved', [ 'id' => 1 ], [ 'id' => 2 ], 1 ],
'group' => 'scanfully',
'status' => \ActionScheduler_Store::STATUS_PENDING,
'per_page' => -1,
],
Expand Down
Loading
Loading