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.
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
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.
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
alexanderA
Let's say WPML is not installed. What will this return:
apply_filters( 'wpml_object_id', $id_con, 'post', FALSE, 'en' );
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
alexanderA
OK thanks for that. We can consider this resolved.
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?
Rohan Sadanandan
Hello,
It will always be returning the 2nd parameter.
In your latest code, it's NULL.
Thanks,
Rohan
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?
Rohan Sadanandan
Hello,
Yes, it will return the value of $post_id
Thanks,
Rohan
alexanderA
My issue is resolved now. Thank you!