Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Europe/Madrid (GMT+01:00)

Tagged: 

This topic contains 3 replies, has 1 voice.

Last updated by Marcel 2 days, 3 hours ago.

Assisted by: Marcel.

Author Posts
January 24, 2025 at 2:00 pm #16631651

desireeM

Background of the issue:
I am trying to use the wpml_get_element_translations hook, but it is missing private posts when running in cron.

Symptoms:
I expected to see all translations, but instead, I got only public translations.

Questions:
Why is the wpml_get_element_translations hook missing private posts in cron?
How can I ensure all translations, including private posts, are retrieved?

January 24, 2025 at 2:04 pm #16631659

desireeM

Issue happens bc of `get_sql_parts_for_post` in class-wpml-translations.php has a check:

if ( current_user_can( 'read_private_pages' ) || current_user_can( 'read_private_posts' ) || $skipPrivilegeChecking ) {

and there is no way to set this to skip privilege checking with the filter

Also this code has an unintended side effect, that it will load the user too early, if the filter is used on plugins loaded hook for example.
The $skipPrivilegeChecking should be first in the condition, in case it's true it won't check current user can and therefore won't load the user too early

January 27, 2025 at 11:27 am #16637375

Marcel
Supporter

Languages: English (English ) German (Deutsch )

Timezone: Europe/Madrid (GMT+01:00)

Hi,

thanks for the report! Let me run some tests, and I’ll get back to you shortly.

Best regards,
Marcel

January 27, 2025 at 3:07 pm #16638480

Marcel
Supporter

Languages: English (English ) German (Deutsch )

Timezone: Europe/Madrid (GMT+01:00)

Hi,

As a temporary workaround, you can check for cron jobs using the following code:

if ( ( defined( 'DOING_CRON' ) && DOING_CRON ) || ( defined( 'WP_CLI' ) && WP_CLI ) || current_user_can( 'read_private_pages' ) || current_user_can( 'read_private_posts' ) || $skipPrivilegeChecking ) {

This issue has been escalated to our developers. For the upcoming release (4.7), we’ve already included a check for WP-CLI, and we will also add a check for cron jobs.

Best regards,
Marcel