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.
Tagged: Bug
This topic contains 4 replies, has 2 voices.
Last updated by anastasiyaS 1 year, 11 months ago.
Assisted by: Bruno Kos.
Author | Posts |
---|---|
July 5, 2023 at 6:06 am #13945697 | |
anastasiyaS |
Hello! I am developing our site and I have a problem. What am I doing? I need to create a request to the site's API using WP_JSON. In this request, an operation is performed to obtain the values of the custom fields of the post/page. I have a list of fields (about 100) like: title, description, _edit_last etc. I iterate over an array with a list of the names of these fields using a foreach loop and try to get the value using the get_post_meta () function. Here is a piece of code: <?php $postId = 100; $fields = ["title", "description", "_edit_last", ...]; foreach ($fields as $field) { $value = get_post_meta($postId, $field, true); ... } When I send a request through Postman, the request itself hangs, as if it is in some kind of recursion. After profiling, I managed to find out that the get_post_meta() function has a "get_post_metadata" hook, which is subscribed to by the "WPML Multilingual CMS" code. I even managed to find a problematic place. It is located in the file: plugins/sitepress-multilingual-cms/classes/custom-field-translation/class-wpml-translate-link-targets-in-custom-fields.php on line 57. There is this code snippet: $this->wp_api->remove_filter( 'get_post_metadata', array( $this, 'maybe_translate_link_targets' ), 10 ); $metadata_raw = maybe_unserialize( $this->wp_api->get_post_meta( $object_id, $meta_key, $single ) ); $this->wp_api->add_filter( 'get_post_metadata', array( $this, 'maybe_translate_link_targets' ), 10, 4 ); In which, if you comment out: "$this->wp_api->add_filter( 'get_post_metadata', array( $this, 'maybe_translate_link_targets' ), 10, 4 );", then the problem disappears. It seems that due to some conditions, this code loops, which breaks our request. Additionally, I noticed that my local Apache server is heavily CPU intensive at the time of the problem, sometimes reaching 100%, and this happens even if the API request is canceled. Only restarting the web server helps. I also recorded a video where the problem is clearly visible: hidden link We are currently using WPML Multilingual CMS 4.6.3 I look forward to your help in this matter, thanks! |
July 5, 2023 at 7:17 am #13946177 | |
Bruno Kos WPML Supporter since 12/2018
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+02:00) |
Hi, Thank you for contacting WPML support! Can you update WPML to 4.6.4, given it is our latest version? It fixed quite a lot of things, can you check if it makes any difference? String translation also has new version: Regards, |
July 5, 2023 at 11:49 am #13949839 | |
anastasiyaS |
Hello! Thanks for your reply! Unfortunately, updating the plugin did not help. I continued to inspect the code and found an interesting point in the file: sitepress-multilingual-cms/classes/translation-management/class-wpml-translation-management-filters-and-actions.php Code: public function __construct( $tm_instance, $sitepress ) { $this->sitepress = $sitepress; if ( ! is_admin() ) { $this->add_filters_for_translating_link_targets( $tm_instance ); } } Note that here, depending on the status of the is_admin() function, code is running: $this->add_filters_for_translating_link_targets( $tm_instance ); This causes a large number of callbacks (maybe_translate_link_targets) to be registered for the get_post_metadata hook, which probably leads to the problem I posted earlier. I managed to trick the is_admin() function and make WPML think that the code is currently being executed from the admin. To do this, it is enough, for example, to add the following code to WordPress index.php: define('WP_ADMIN', true); After that, the bug with endless loading disappears. Watch the video I posted below. I can demonstrate this visually with xDebug: hidden link Please help with this problem as WPML interferes with the development of our application 🙁 |
July 6, 2023 at 6:47 am #13955129 | |
Bruno Kos WPML Supporter since 12/2018
Languages: English (English ) German (Deutsch ) French (Français ) Timezone: Europe/Zagreb (GMT+02:00) |
Can you provide us with Duplicator package? https://wpml.org/faq/provide-supporters-copy-site/ Please exclude all the media files, etc, to keep the package minimal. We will need to debug this, also send us information on where and how can we reproduce, which calls we need to do to see the infinite loop. I marked your next reply private so you can safely add Duplicator link. |