You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When listing available languages for a plugin using the wp language plugin list <plugin> command, the status is always uninstalled if the plugin's slug ≠ plugin's text domain.
wp_get_installed_translations() returns an array keyed by the text domain. As a result, the subsequent check for available languages ($available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();) results in an empty array if the plugin's slug is different from its text domain.
get_installed_languages() is used by the list command:
That's where the following check (against an empty $installed_translations array returned by get_installed_languages()) results in the uninstalled value:
Can you give an example of a plugin where this is happening?
How would WP-CLI know what the correct text domain would be for the plugin?
WordPress plugins are really meant to have matching slugs and text domains. If they don't match, this kind of situation is to be expected. I assume WordPress itself also doesn't recognize the translations as being installed in that case.
I assume WordPress itself also doesn't recognize the translations as being installed in that case.
It does because it relies on the text domain, not the plugin slug.
Can you give an example of a plugin where this is happening?
It can happen with any plugin if it's placed in a folder that doesn't match its text domain. For example, install Gravity Forms, rename the gravityforms folder to gfforms, and you will see an issue.
How would WP-CLI know what the correct text domain would be for the plugin?
By the way, updating translations via WP CLI doesn't work since get_translations_update() also uses the get_installed_languages() method. Similarly, the update status is always none. Installation works just fine though except the status that always shows uninstalled (i.e., the issue at hand).
Anyway, this is an easy fix. Thanks for looking into this!
Bug Report
Describe the current, buggy behavior
When listing available languages for a plugin using the
wp language plugin list <plugin>
command, the status is alwaysuninstalled
if the plugin's slug ≠ plugin's text domain.This is due to the wp_get_installed_translations() method used in
language-command/src/WP_CLI/CommandWithTranslation.php
Lines 251 to 257 in 24f76e3
wp_get_installed_translations()
returns an array keyed by the text domain. As a result, the subsequent check for available languages ($available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
) results in an empty array if the plugin's slug is different from its text domain.get_installed_languages()
is used by thelist
command:language-command/src/Plugin_Language_Command.php
Lines 92 to 153 in 24f76e3
That's where the following check (against an empty
$installed_translations
array returned byget_installed_languages()
) results in theuninstalled
value:language-command/src/Plugin_Language_Command.php
Line 125 in 24f76e3
A solution is to account for the discrepancy between plugin slugs and text domains in the
get_installed_languages()
method.The text was updated successfully, but these errors were encountered: