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.

This topic contains 11 replies, has 2 voices.

Last updated by alexanderA 11 months ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
October 17, 2019 at 6:58 am #4770499

alexanderA

Hello. On my site I have added a custom PHP function which uses two WPML filters:

$id_con_en = apply_filters( 'wpml_object_id', $id_con, 'post', FALSE, 'en' );
$trid_con = apply_filters( 'wpml_element_trid', NULL, $id_con_en, 'post_page' );

1. If WPML is deactivated, what exactly will occur when those PHP lines are processed?

2. If WPML is not installed, what exactly will occur when those PHP lines are processed?

For example, will a PHP fatal error occur on either?

Thanks.

October 17, 2019 at 10:36 am #4772527

Rohan Sadanandan

Hello,

Thank you for contacting WPML Support.

As mentioned by Raja, if you disable or uninstall WPML then you may get PHP warnings & the resultant variables will not be having any values.

You will not get a PHP fatal error in any case.

If you have any more doubts please let me know.

Thanks,
Rohan

October 17, 2019 at 10:41 am #4772577

alexanderA

OK thanks. So in this case, how should I best implement error handling? For example, can I first test if WPML is activated, if it that test is true, then execute that PHP code?

Or is there perhaps a way to check if `apply_filters( 'wpml_object_id');` exists?

Thanks.

October 17, 2019 at 11:01 am #4772769

Rohan Sadanandan

Hello,

Sorry for the confusion.

In the case of filters, there will not be any PHP warnings. So there is no need to do any error handling in this case.

If you want to check whether WPML is active, you can use the function mentioned in this documentation: https://wpml.org/wpml-hook/wpml_setting/

Thanks,
Rohan

October 18, 2019 at 8:54 am #4779577

alexanderA

Let's say WPML is not installed. What will this return:

apply_filters( 'wpml_object_id', $id_con, 'post', FALSE, 'en' );

October 18, 2019 at 12:08 pm #4781765

Rohan Sadanandan

Hello,

The filters do not return any warnings/errors if it does not exist. So there is no need to do any error handling for the same.

I just checked your code & it will return the value of $id_con itself if WPML is not activated.

Thanks,
Rohan

October 19, 2019 at 6:27 am #4786765

alexanderA

OK thanks for that. We can consider this resolved.

October 19, 2019 at 6:33 am #4786771

alexanderA

Sorry, can I ask one more question. If WPML is not installed, what will this return:

apply_filters( 'wpml_element_trid', NULL, $post_id, 'post_page' );

Will that return the original value of $post_id?

October 20, 2019 at 12:34 pm #4789613

Rohan Sadanandan

Hello,

It will always be returning the 2nd parameter.
In your latest code, it's NULL.

Thanks,
Rohan

October 20, 2019 at 12:44 pm #4789623

alexanderA

Ah OK. So to be clear, let's say I have this code:

apply_filters( 'wpml_element_trid', $post_id, $post_id, 'post_page' );

If WPML is not installed, this will return the original value of $post_id. Is that correct?

October 20, 2019 at 1:41 pm #4789775

Rohan Sadanandan

Hello,

Yes, it will return the value of $post_id

Thanks,
Rohan

October 20, 2019 at 2:14 pm #4789799

alexanderA

My issue is resolved now. Thank you!