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.

This topic contains 13 replies, has 2 voices.

Last updated by vilnisZ 1 year ago.

Assigned support staff: Diego Pereira.

Author Posts
October 1, 2018 at 9:49 am

vilnisZ

Hello,

There was this ticket opened( https://wpml.org/forums/topic/hooks-worsens-cpu-usage/ ):

----------------------------------------------------------------------------------

Hello,

I added these hooks:

https://wpml.org/wpml-hook/wpml_make_post_duplicates/

https://wpml.org/wpml-hook/wpml_admin_make_post_duplicates/

But they are really slowing down my site. Actually to a point when it is not usable. And The CPU Time Usage "goes through roof".

What can I do in this situation?

PS: The duplicator site without the edited functions.php file.

------------------------------------------------------------------------------------------------

Hi there,

It seems that the issue is only related to the first function. It is attached to in the "WP_footer", which means that it is triggered every time you access any page of the website.

Could you just remove only the first function and see if that solves the issue?

Regards,
Diego

----------------------------------------------------------------------------------------------------

I deleted the first function. It got a little bit better, but still it was over the top.

October 1, 2018 at 8:24 pm #2779446

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hello @vilnisz, welcome!

Please take a look at this guide to see how to improve the performance of your website with WPML: https://wpml.org/2012/01/can-your-site-run-faster/

Please let me know if it worked for you.

All the best,
Diego

October 2, 2018 at 8:20 am #2780663

vilnisZ

I already have all kind of caches. And the site is working perfect till I add those hooks.

October 2, 2018 at 5:49 pm #2782433

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

If you remove the snippet, does the site work normally, right?

Please send us the content of your functions.php file. You can use a service like this to send the content: https://pastebin.com/

I will check with my team if there is any improvement that we can suggest.

Regards,
Diego

October 4, 2018 at 8:05 am #2786613

vilnisZ

Yes, without it works normally. The last two are the hooks.

https://pastebin.com/pf6EGEFs

October 4, 2018 at 6:47 pm #2788621

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

Thanks, I sent the code snippet to my team and will send you a feedback soon.

Regards,
Diego

October 5, 2018 at 2:11 pm #2791072

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

I got a feedback. According to your functions.php code, the hooks at line 340 and below are called on wp_footer -> every time the footer is loaded. That is definitely not the proper hook for these functions. Probably this is the cause, could you please check?

Regards,
Diego

October 8, 2018 at 7:44 am #2794953

vilnisZ

I checked. And the first function that is ment for admin vorks for vendors too. I think "Yith vendors" plugin is working that they are copying same funcitons form backend.

So was this hook all right?

----------------------------------------------------------------------------------------------------

add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publish( $post_id ) {
global $post;
// don't save for autosave
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// dont save for revisions
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}

// we need this to avoid recursion see add_action at the end
remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );

// make duplicates if the post being saved
// #1. itself is not a duplicate of another or
// #2. does not already have translations

$is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );

if ( !$is_translated ) {
do_action( 'wpml_admin_make_post_duplicates', $post_id );
}

// must hook again - see remove_action further up
add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
}

October 8, 2018 at 7:18 pm #2797138

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

The second part seems ok at first...The function only runs on "wp_insert_post", so it should not affect performance on the site navigation.

Regards,
Diego

October 9, 2018 at 1:10 pm #2800093

vilnisZ

OK, that works and how can I get that when vendor edits product that edit applies to all translations of that product?

October 9, 2018 at 8:42 pm #2802097

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

You will have to develop a customized code to achieve this goal. Unfortunately custom code is not part of our support policy: https://wpml.org/purchase/support-policy/

I recommend you take a look at our coding API and our list of hooks available:
- https://wpml.org/documentation/support/wpml-coding-api/
- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

We also have a list of experienced contractors available here: https://wpml.org/contractors/

Regards,
Diego

October 10, 2018 at 6:48 am #2803126
vilnisZ

But there is said that "YITH WOOCOMMERCE MULTI VENDOR" is 100% compatible. Then it's not compatible it's just unfinished. There must be some other people with this same problem.

If vendor wants to edit product he has to go back and forth in other languages and edit every each translation. That is not a good interface.

And other problem I found - when product goes "Bestseller" it is only for one translation.

New threads created by Diego Pereira and linked to this one are listed below:

https://wpml.org/forums/topic/split-yith-woocommerce-multi-vendor-workflow/

October 10, 2018 at 4:40 pm #2805230

Diego Pereira
Supporter

Languages: English (English ) Spanish (Español ) Portuguese (Brazil) (Português )

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

Hi there,

This seems to be a different issue, so I will open a new ticket for this new one.

I will reply in the new ticket.

Regards,
Diego

October 12, 2018 at 10:45 am #2811653

vilnisZ

My issue is resolved now. Thank you!