Skip to content

CRM: PHP notices: Translation loading for the zero-bs-crm domain was triggered too early. #3542#44109

Merged
tbradsha merged 32 commits intotrunkfrom
fix/crm/clean-translation-loading
Jul 3, 2025
Merged

CRM: PHP notices: Translation loading for the zero-bs-crm domain was triggered too early. #3542#44109
tbradsha merged 32 commits intotrunkfrom
fix/crm/clean-translation-loading

Conversation

@mikestottuk
Copy link
Copy Markdown
Contributor

@mikestottuk mikestottuk commented Jun 26, 2025

Fixes Automattic/zero-bs-crm#3542

Proposed changes:

  • Removed the plugins_loaded hook registration that was calling load_textdomain() from the init_hooks() method in ZeroBSCRM.Core.php
  • This prevents the text domain from being loaded too early in the WordPress initialization sequence
  • Fixes the PHP notice: "Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the zero-bs-crm domain was triggered too early."

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • Enable WP_DEBUG and WP_DEBUG_LOG in wp-config.php
  • Activate the plugin
  • Check debug.log for any "translation loaded too early" notices
  • Verify that all translations still work correctly in the admin area
  • Test with different languages to ensure translations are loading properly
  • Verify that no other functionality is affected by this change

@github-actions github-actions bot added the [Plugin] CRM Issues about the Jetpack CRM plugin label Jun 26, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 26, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jun 26, 2025
@mikestottuk mikestottuk requested a review from tbradsha June 26, 2025 17:58
@mikestottuk mikestottuk added [Status] In Progress [Status] Needs Review This PR is ready for review. Bug When a feature is broken and / or not performing as intended [Type] Janitorial and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels Jun 26, 2025
@jp-launch-control
Copy link
Copy Markdown

jp-launch-control bot commented Jun 27, 2025

Code Coverage Summary

Coverage changed in 3 files.

File Coverage Δ% Δ Uncovered
projects/plugins/crm/ZeroBSCRM.php 0/171 (0.00%) 0.00% 35 💔
projects/plugins/crm/includes/ZeroBSCRM.Database.php 0/276 (0.00%) 0.00% 2 ❤️‍🩹
projects/plugins/crm/includes/ZeroBSCRM.Core.php 0/973 (0.00%) 0.00% -7 💚

Full summary · PHP report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@mikestottuk mikestottuk force-pushed the fix/crm/clean-translation-loading branch from 0f11714 to 81e5f0d Compare June 27, 2025 15:53
$zbs = ZeroBSCRM::instance();
// init hook
add_action(
'init',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll note that we're changing the load order here; I'm not sure what implications this might have for extensions that register with CRM (e.g. Mail Campaigns or WooSync).

On the plus side, this sets the stage to clean up several lines in ZeroBSCRM::init_hooks() to no longer use the init hook.

do_action( 'before_zerobscrm_init' );

// After all the plugins have loaded (THESE FIRE BEFORE INIT)
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); // } Translations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we chop ZeroBSCRM::load_textdomain now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we should!

return $zbs->database_server_info['db_engine_label'];

// If $zbs is an object but database_server_info is not set, try to populate it.
if ( is_object( $zbs ) && ! isset( $zbs->database_server_info ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you run into an issue with this? If $zbs is not an object, we should probably return early.

Related, $zbs->database_server_info will always be set if $zbs is an object, given that it's initialized as an empty object. It's also populated as early as possible (within $zbs->verify_minimum_requirements()).

In other words, if $zbs is an object, the rest of the checks are unnecessary and the fallback scenario isn't possible.


// Activating the plugin directly loads the welcome wizard, so no need to move pages here.
// Click the activate link for jetpack-crm directly
$I->click( 'Activate', array( 'css' => 'tr[data-slug="jetpack-crm"] .activate a' ) );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I presume this is because the $I->activatePlugin() uses the bulk activation route? This might be irrelevant now that I've adjusted it to support bulk activation with one plugin.

global $zbs;
$zbs->install();
zeroBSCRM_notifyme_createDBtable();
if ( class_exists( 'zeroBSCRM' ) && ! isset( $zbs ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need this check? We literally load the class file and we know it's not set. :^)

// Run installation if needed
if ( isset( $zbs ) && is_object( $zbs ) && method_exists( $zbs, 'install' ) ) {
$zbs->install();
if ( function_exists( 'zeroBSCRM_notifyme_createDBtable' ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing here...if $zbs is instantiated, that means it's run the __construct(), which means it's run $zbs->includes(), which means this function does exist. There's no way to get to this point and not have the function exist.

}

// Run installation if needed
if ( isset( $zbs ) && is_object( $zbs ) && method_exists( $zbs, 'install' ) ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is overkill and not needed. :^)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unless someone deletes the install function?

Copy link
Copy Markdown
Contributor

@tbradsha tbradsha left a comment

Choose a reason for hiding this comment

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

Some comments to consider...

$this->assertWizardIsShown( $I );
}

public function test_bulk_plugin_activation_skips_wizard( AcceptanceTester $I ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suspect this doesn't show the wizard because technically the option already is set. So more accurately this is testing if the wizard shows on second load.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tbradsha and others added 8 commits July 1, 2025 13:21
tbradsha
tbradsha previously approved these changes Jul 3, 2025
public function frontend_includes() {
}

/**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🪓

$this->assertWizardIsShown( $I );
}

public function test_bulk_plugin_activation_skips_wizard( AcceptanceTester $I ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tbradsha tbradsha force-pushed the fix/crm/clean-translation-loading branch from 24dbd9f to d2e27d5 Compare July 3, 2025 16:24
@tbradsha tbradsha merged commit 7b9e31f into trunk Jul 3, 2025
64 checks passed
@tbradsha tbradsha deleted the fix/crm/clean-translation-loading branch July 3, 2025 17:07
@github-actions github-actions bot removed the [Status] Needs Review This PR is ready for review. label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Plugin] CRM Issues about the Jetpack CRM plugin [Tests] Includes Tests [Type] Janitorial

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants