Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the use of the gettext filter. #185

Closed
apermo opened this issue Jun 26, 2021 · 1 comment · Fixed by #255
Closed

Refactor the use of the gettext filter. #185

apermo opened this issue Jun 26, 2021 · 1 comment · Fixed by #255

Comments

@apermo
Copy link

apermo commented Jun 26, 2021

/src/ui/class-classic-editor.php line 71:
\add_filter( 'gettext', [ $this, 'change_republish_strings_classic_editor' ], 10, 2 );

In our local environment, this filter alone is called 10471 times, and is causing 507ms of wall time.

@therealgilles
Copy link

therealgilles commented May 30, 2022

Adding my voice here and links to an issue posted on wordpress.org as well as this important comment from the WP gettext documentation page:

Here is an extract from the WP gettext documentation first comment:

This filter is ideally avoided as the performance aspect can be huge. If you do need it, be aware with a common suite of plugins installed this can easily run thousands of times on one page! WooCommerce and similar make everything translatable.

It’s far improved to check the domain right away and return the translation instantly if it’s not the domain you’re wanting to translate. This minimises the overhead, rather than some of these examples that are running str_replace(), is_single() etc over and over unnecessarily which adds up due to the sheer quantity of times this code will run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants