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.

Our next available supporter will start replying to tickets in about 3.13 hours from now. Thank you for your understanding.

This topic contains 10 replies, has 2 voices.

Last updated by Brent 1 month, 1 week ago.

Assigned support staff: Mateus Getulio.

Author Posts
April 29, 2021 at 11:23 am #8653169

Brent

Add a page for translation in the Translation Management Plugin

Is there any documentation that you are following?
Yes:
https://wpml.org/documentation/translating-your-contents/

After selecting the page and translations, the clicking "Add selected content to translation basket", the button goes grey but nothing else happens.
A "Translation Basket" tab does not appear

April 29, 2021 at 8:58 pm #8657695

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Brent,

Welcome to our forum. I'll be happy to assist you with this!

By chance, these pages contain images? We had a recent patch for a similar issue. Please check the errata if it is your case:

https://wpml.org/errata/fatal-error-while-trying-to-add-a-post-that-contains-images-to-the-translation-basket/

We can try the solution described there. Please make sure you have a working backup of your website before you add that temporary fix:

- Get access to your files
- Go to: wp-content/plugins/wpml-media-translation/classes/media-translation/class-wpml-media-post-with-media-files.php
- There, just before the line:

return apply_filters( 'wpml_ids_of_media_used_in_post', $media_ids, $this->post_id );

add this line:

$media_ids = \WPML\FP\Fns::filter( 'get_post', $media_ids );

If the problem persists, then we might be facing an interaction issue with a third-party functionality, in this case:

- Deactivate all the plugins that are not related to WPML
- Switch for a moment to a WordPress default theme like Twenty Twenty-one
- If the issue is gone, activate one by one to see with which one there is an interaction issue

Let us know the results of this investigation. Also, can you enable the debug mode? Please add the following code in your wp-config.php file:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
  
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
  
// Disable display of errors and warnings 
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
  
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define( 'SCRIPT_DEBUG', true );

Please check the following links to read more about debugging with WordPress.
- https://codex.wordpress.org/Debugging_in_WordPress
- https://codex.wordpress.org/Debugging_in_WordPress#Example_wp-config.php_for_Debugging

After adding the code above, try to reproduce the issue again and check if you'll find a debug.log file inside the wp-content folder. If you locate it there, please send us the last lines here in the ticket.

Looking forward to your reply. Best,
Mateus.

April 30, 2021 at 6:19 am #8659755

Brent

Hi Mateus,
Regarding the solution of adjusting the php file, The line of code that was mentioned does not exist in this file of my installation.

I tried deactivating all plugins except WPML. It still didnt work.
I made a screen shot of the errors the page was generating...see attached.

Also added the lines to wp.config. didnt find a debug file.

Im sorry but I rea

1.jpg
April 30, 2021 at 6:31 am #8659863

Brent

I tried putting the line of code in front of this similar line:

return Fns::filter( Post::get(), apply_filters( 'wpml_ids_of_media_used_in_post', $media_ids, $this->post_id ) );

Here is the file contents:

<?php

use WPML\FP\Fns;
use WPML\LIB\WP\Post;

class WPML_Media_Post_With_Media_Files {

	/**
	 * @var int
	 */
	private $post_id;
	/**
	 * @var WPML_Media_Img_Parse
	 */
	private $media_parser;
	/**
	 * @var WPML_Media_Attachment_By_URL_Factory
	 */
	private $attachment_by_url_factory;
	/**
	 * @var SitePress $sitepress
	 */
	private $sitepress;
	/**
	 * @var WPML_Custom_Field_Setting_Factory
	 */
	private $cf_settings_factory;

	/**
	 * WPML_Media_Post_With_Media_Files constructor.
	 *
	 * @param $post_id
	 * @param WPML_Media_Img_Parse $media_parser
	 * @param WPML_Media_Attachment_By_URL_Factory $attachment_by_url_factory
	 * @param SitePress $sitepress
	 * @param WPML_Custom_Field_Setting_Factory $cf_settings_factory
	 */
	public function __construct(
		$post_id,
		WPML_Media_Img_Parse $media_parser,
		WPML_Media_Attachment_By_URL_Factory $attachment_by_url_factory,
		SitePress $sitepress,
		WPML_Custom_Field_Setting_Factory $cf_settings_factory
	) {
		$this->post_id                   = $post_id;
		$this->media_parser              = $media_parser;
		$this->attachment_by_url_factory = $attachment_by_url_factory;
		$this->sitepress                 = $sitepress;
		$this->cf_settings_factory       = $cf_settings_factory;
	}

	public function get_media_ids() {
		$media_ids = array();

		if ( $post = get_post( $this->post_id ) ) {

			$content_to_parse   = apply_filters( 'wpml_media_content_for_media_usage', $post->post_content, $post );
			$post_content_media = $this->media_parser->get_imgs( $content_to_parse );
			$media_ids          = $this->_get_ids_from_media_array( $post_content_media );

			if ( $featured_image = get_post_meta( $this->post_id, '_thumbnail_id', true ) ) {
				$media_ids[] = $featured_image;
			}

			$media_localization_settings = WPML_Media::get_setting( 'media_files_localization' );
			if ( $media_localization_settings['custom_fields'] ) {
				$custom_fields_content = $this->get_content_in_translatable_custom_fields();
				$custom_fields_media   = $this->media_parser->get_imgs( $custom_fields_content );
				$media_ids             = array_merge( $media_ids, $this->_get_ids_from_media_array( $custom_fields_media ) );
			}

			if ( $gallery_media_ids = $this->get_gallery_media_ids( $content_to_parse ) ) {
				$media_ids = array_unique( array_values( array_merge( $media_ids, $gallery_media_ids ) ) );
			}

			if ( $attached_media_ids = $this->get_attached_media_ids( $this->post_id ) ) {
				$media_ids = array_unique( array_values( array_merge( $media_ids, $attached_media_ids ) ) );
			}

		}

		return Fns::filter( Post::get(), apply_filters( 'wpml_ids_of_media_used_in_post', $media_ids, $this->post_id ) );
	}

	/**
	 * @param array $media_array
	 *
	 * @return array
	 */
	private function _get_ids_from_media_array( $media_array ) {
		$media_ids = array();
		foreach ( $media_array as $media ) {
			if ( isset( $media['attachment_id'] ) ) {
				$media_ids[] = $media['attachment_id'];
			} else {
				$attachment_by_url = $this->attachment_by_url_factory->create( $media['attributes']['src'], wpml_get_current_language() );
				if ( $attachment_id = $attachment_by_url->get_id() ) {
					$media_ids[] = $attachment_id;
				}

			}
		}

		return $media_ids;
	}

	/**
	 * @param string $post_content
	 *
	 * @return array
	 */
	private function get_gallery_media_ids( $post_content ) {

		$galleries_media_ids    = array();
		$gallery_shortcode_regex = '/\[gallery [^[]*ids=["\']([0-9,\s]+)["\'][^[]*\]/m';
		if ( preg_match_all( $gallery_shortcode_regex, $post_content, $matches ) ) {
			foreach ( $matches[1] as $gallery_ids_string ) {
				$media_ids_array = explode( ',', $gallery_ids_string );
				$media_ids_array = Fns::map( Fns::unary( 'intval' ), $media_ids_array );

				foreach ( $media_ids_array as $media_id ) {
					if ( 'attachment' === get_post_type ( $media_id ) ) {
						$galleries_media_ids[] = $media_id;
					}

				}
			}
		}

		return $galleries_media_ids;
	}

	/**
	 * @param $languages
	 *
	 * @return array
	 */
	public function get_untranslated_media( $languages ) {

		$untranslated_media = array();

		$post_media = $this->get_media_ids();

		foreach ( $post_media as $attachment_id ) {

			$post_element = new WPML_Post_Element( $attachment_id, $this->sitepress );
			foreach ( $languages as $language ) {
				$translation = $post_element->get_translation( $language );
				if ( null === $translation || ! $this->media_file_is_translated( $attachment_id, $translation->get_id() ) ) {
					$untranslated_media[] = $attachment_id;
					break;
				}
			}

		}

		return $untranslated_media;
	}

	private function media_file_is_translated( $attachment_id, $translated_attachment_id ) {
		return get_post_meta( $attachment_id, '_wp_attached_file', true )
		       !== get_post_meta( $translated_attachment_id, '_wp_attached_file', true );
	}

	private function get_content_in_translatable_custom_fields() {
		$content = '';

		$post_meta = get_metadata( 'post', $this->post_id );

		if ( is_array( $post_meta ) ) {
			foreach ( $post_meta as $meta_key => $meta_value ) {
				$setting         = $this->cf_settings_factory->post_meta_setting( $meta_key );
				$is_translatable = $this->sitepress->get_wp_api()
				                                   ->constant( 'WPML_TRANSLATE_CUSTOM_FIELD' ) === $setting->status();
				if ( is_string( $meta_value[0] ) && $is_translatable ) {
					$content .= $meta_value[0];
				}
			}
		}

		return $content;
	}

	private function get_attached_media_ids( $post_id ) {
		$attachments = get_children(
			array(
				'post_parent' => $post_id,
				'post_status' => 'inherit',
				'post_type'   => 'attachment',
			)
		);
		return array_keys( $attachments );
	}
}
April 30, 2021 at 10:06 am #8661707

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link

Please, let me know if you need any additional details. Have a nice day.

April 30, 2021 at 6:26 pm #8664743

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi Brent,

Thanks for providing your credentials.

We've just checked your website, and we could send the translation jobs to the Translation Basket, which displayed without problems. We tried it with a new test page and another old one, both worked. Please check: hidden link

Have you managed to solve the issue in the meantime? If you haven't, can you please tell us the exact steps to take in order to reproduce the problem?

Keep us posted. Best,
Mateus.

May 1, 2021 at 9:47 am #8667159

Brent

I still dont see a basket in the menu. check attached screenshot

1.jpg
May 1, 2021 at 1:53 pm #8667955

Brent

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

It seems to be a problem with my user rights maybe?
I just logged in with the wp credentials i sent you and i now see the basket.

I ALSO SEE THAT A BIG NUMBER OF PAGES HAVE BEEN SENT TO A TRANSLATION COMPANY AND ARE IN TRANSLATION PROGRESS!

I DID NOT AUTHORIZE THAT!

I have tried to contact the translation company to cancel, but it is weekend.

This whole service is a disaster. 🙁

May 3, 2021 at 9:13 am #8673919

Brent

OK, I managed to stop the translation Service until further notice.
The problem was that the user account i was using wasnt registered as a "Translation Manager" .... quite an easy solution that you should really have considered first.

I still do need assisstance though. There are a number of pages under "translation jobs" with the status "In Progress".
The translation company tells me they cannot change this status, only download the files for translation at the moment.
I also cannot change the status of these jobs.
How can I reset everything back to normal (delete all jobs in progress) so I can select the translations i really need?

I would appreciate a response asap as I need to move on with the translations, wasted too much time already

Many Thanks

May 3, 2021 at 12:32 pm #8676313

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello Brent,

I’m glad you were able to cancel those jobs with the translation service and I sincerely apologize for the inconvenience you’ve faced with this.

If you wish to remove all translation jobs, you can go to WPML-> Support -> Troubleshooting -> Reset professional translation state. Note: Please make sure you have a complete backup of your site before proceeding. Use this feature when you want to reset all your translation processes. All your existing translations will remain unchanged. Any translation work that is currently in progress will be stopped. Just select this option if you have no pending jobs.

Another alternative, if you want to cancel only specific jobs, would be following these instructions:

- Go to WPML -> Translation Management -> Translation Role, and add yourself as a translator
- Go to the Translation Dashboard, and select the posts that you want to cancel, and send them to the basket
- In the basket, assign these job to your local translator and send them
- Now, in the Translation Jobs tab, select these local jobs that you want to cancel, and from the bulk action, choose to cancel and click ok

Could you please try these steps in order to cancel the desired jobs and tell us the results? Thanks for your patience, and sorry again about the slips. We are looking forward to your reply.

Best,
Mateus.

May 6, 2021 at 6:15 am #8700273

Brent

My issue is resolved now. Thank you!