From fbbb0459a354eb00da13d3369345f16b6fbc20b2 Mon Sep 17 00:00:00 2001 From: Kristian Vitozev Date: Mon, 24 Nov 2025 15:29:02 +0200 Subject: [PATCH] A4A Client: defer connection check to plugins_loaded hook Move the connection check from init() to plugins_loaded hook to prevent fatal errors when WordPress core functions (like get_user_by) are not yet available. This fixes an issue introduced in PR #37337 where the connection check ran too early in the plugin initialization. Fixes a bug where the connection check would run before WordPress core functions are loaded, causing fatal errors in environments like Atomic where get_user_by() is used by the connection check. --- .../changelog/fix-a4a-defer-connection-check | 5 +++++ .../src/class-automattic-for-agencies-client.php | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 projects/plugins/automattic-for-agencies-client/changelog/fix-a4a-defer-connection-check diff --git a/projects/plugins/automattic-for-agencies-client/changelog/fix-a4a-defer-connection-check b/projects/plugins/automattic-for-agencies-client/changelog/fix-a4a-defer-connection-check new file mode 100644 index 0000000000000..5cf16e3b3fea3 --- /dev/null +++ b/projects/plugins/automattic-for-agencies-client/changelog/fix-a4a-defer-connection-check @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed + +A4A Client: defer connection check to plugins_loaded hook to prevent fatal errors when WordPress core functions are not yet available. + diff --git a/projects/plugins/automattic-for-agencies-client/src/class-automattic-for-agencies-client.php b/projects/plugins/automattic-for-agencies-client/src/class-automattic-for-agencies-client.php index 2ce6571b1aa48..12a588325f85f 100644 --- a/projects/plugins/automattic-for-agencies-client/src/class-automattic-for-agencies-client.php +++ b/projects/plugins/automattic-for-agencies-client/src/class-automattic-for-agencies-client.php @@ -37,6 +37,19 @@ public static function init() { add_action( 'load-settings_page_' . AUTOMATTIC_FOR_AGENCIES_CLIENT_SLUG, array( static::class, 'load_scripts_styles' ) ); // Display a modal when trying to deactivate the plugin. + // Hook to plugins_loaded at priority 20 to ensure connection package is initialized + // and WordPress core functions (like get_user_by) are available. + add_action( 'plugins_loaded', array( static::class, 'init_deactivation_handler' ), 20 ); + } + + /** + * Initialize the deactivation handler if the site is connected. + * + * @since 0.1.0 + * + * @return void + */ + public static function init_deactivation_handler() { $manager = new Connection_Manager( 'automattic-for-agencies-client' ); if ( $manager->is_connected() ) { Deactivation_Handler::init( AUTOMATTIC_FOR_AGENCIES_CLIENT_SLUG, __DIR__ . '/admin/deactivation-dialog.php' );