Tell us what you are trying to do?
The following PHP script is added to a content template. The only output is "test2" which is from the echo statement that is outside of the function. The function pmpro_hasMembershipLevel is used successfully in other script. Input on why this is not working?
function conditional_role() {
$return = 0;
$current_user = wp_get_current_user();
if (pmpro_hasMembershipLevel('Elite', $current_user))
{
$return = 1;
}
To clarify, I added the PHP script to a snippets plugin and used the shortcode to call the script. The shortcode is in the content template - [conditional_roles2]. I believe the script runs, because it echos "test2", which is outside the function. However, none of the echo statements inside the function execute, and I believe that they should.
I plan to use this in a conditional statement, so should echo 0 or 1 for $return.
Can you please share admin access details and link where you added the shortcode and where you are displaying it on frontend.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I checked first the URLs you shared:
The PHP script is added in the Code Snippets plugin here: hidden link
Notice it is set to run everywhere.
In Woody Snippets, the PHP script is here: hidden link
This is only set to run where the shortcode [wbcr_php_snippet id="26203"] is used.
When I checked both of the links above I see you are using the same function name and same shrotcode with both the snippet.
The function and shortcode name should be unique. Can you please correct that first.
Also, with the Woody Snippets, the PHP script is here: hidden link
==>
I do not have rights to update the snippet I can not able to edit and update the snippet.
Also, I'm not sure why you are using other snippet plugins where Toolset offers the "Custom Code" section to add custom snippet.
What if you try to add sample shortcode to "Custom code" snippet:
function func_print_hello_world($atts) {
return 'Hello World';
}
add_shortcode('printhello', 'func_print_hello_world');
And to content template add the following shortcode:
[printhello]
Is it working, if yes, then what if you try to add delete the above shortcode from "Custom Code" section and then try to add it to the place where you want and do you see it working?
I added the PHP script for [printhello] to the Toolset Custom Code section. When I add the shortcode to the content template, the output is:
Hello World
It looks like it works there. I did not remember the Toolset Custom Code area. I will add the PHP script for the conditional_roles function to the Toolset Custom Code to see if it works.
Please make sure to remove the code snippet elsewhere as you can not add same function with same shortcode multiple times as communicated before it should be unique.