Thread Starter
agreda
(@agreda)
PS: I did get a simple PHP echo statement to work (without the open/close tags) but I can’t seem to figure out what’s going on with the code above. Nothing renders on the page, and no errors… :-\
Thread Starter
agreda
(@agreda)
FYI: The chat room renders and works fine when inserted via shortcode with block containing the following content:
require('/home/userx/public_html/chatroom/chat.php');
Any direction for including the if/else statement to only show it for logged in members is greatly appreciated.
Thanks again!
Thread Starter
agreda
(@agreda)
Fixed it! Sometimes you just need to work through these things out loud, even if no one is listening. 😉
For anyone curious, here is the conditional PHP code I used in the Content Block to render a chat room, only for logged in users…
if (is_user_logged_in()) {
require('/home/userx/public_html/chatroom/chat.php');
} else {
echo "<p>You must be logged in to join the chat.</p>";
}
Plugin Author
benz1
(@benz1)
Glad you got it working and thanks for the donation, much appreciated 🙂
Hello there,
Can you implement a change that would allow having php code inside HTML fragments?
All you need to do is replace the following block of code inside the “gcb” function:
if($entry['type']!="php") {
return apply_filters('gcb_block_output', do_shortcode($content));//make sure we also run the shortcodes in here
}
else
{
//execute the php code
ob_start();
$result = eval(" ".$content);
$output = ob_get_contents();
ob_end_clean();
return apply_filters('gcb_block_output', do_shortcode($output . $result));//run the shortcodes as well
} }
Replace with:
if($entry['type'] == "php") {
//execute the php code
ob_start();
$result = eval(" ".$content);
$output = ob_get_contents();
ob_end_clean();
return apply_filters('gcb_block_output', do_shortcode($output . $result));//run the shortcodes as well
}
elseif($entry['type'] == "html") { // alloyphoto: enable PHP code in < ?php ... ? > tags inside blocks
ob_start();
eval("?>$content<?php ");
$output = ob_get_contents();
ob_end_clean();
return apply_filters('gcb_block_output', do_shortcode($output));//run the shortcodes as well
}
else
{
return apply_filters('gcb_block_output', do_shortcode($content));//make sure we also run the shortcodes in here
}
Thank you!