Allow PHP
-
How can i allow PHP code in the div? I have tryed most php plugins.
-
This topic was modified 7 years, 8 months ago by
autox420.
-
This topic was modified 7 years, 8 months ago by
-
Hi,
It isn’t possible currently, the php code is immediately commented by WP.
<?php echo “Today is ” . date(“d/m/Y”); ?>
becomes
<!–?php echo “Today is ” . date(“d/m/Y”); ?–>
I will take a look if I can find a way to allow PHP code in the WP textarea and come back to you.
Sorry for the inconvenience,
Best Regards,
PluginlySpeakingSh*t little bit disapointed. Hope you will make it possible.
-
This reply was modified 7 years, 8 months ago by
autox420.
Isnt it possible to make the post inside the .php directly?
pluginlyspeaking-floatingdiv.php
Hi,
I found something that could work, it requires to edit the php file.
Are you familiar with editing the file via your FTP client ?
Or would you prefer to get a new php file and simply upload it ?Let me how you would like to proceed.
Best Regards,
PluginlySpeakingYes i can edit files im not a total noob π
Both ways work. Just let me know what code i need to insert or just upload the complete new .php it doesnt matter.
Thanks hope it will work.
Ok, so you have to add the following code at the end of the
pluginlyspeaking-floatingdiv.php
file (just before the ” ?> “) :add_shortcode( 'psfd_php', 'psfd_shortcode_php' ); function psfd_shortcode_php($atts, $content = null) { ob_start(); eval($content); $output = ob_get_clean(); ob_end_clean(); return $output; }
It will create a shortcode that you can use like that :
[psfd_php] any php code [/psfd_php]
For example, the following shortcode :
[psfd_php] echo βToday is β . date(βd/m/Yβ); [/psfd_php]
will display :Today is 02/11/17
Testing.
Am i doing something wrong?
Yes i added the function already to the .php[psfd_php]<?php if ( 0 != get_current_user_id() ) { the_author_meta( 'user_description', get_current_user_id() ); } else { echo 'Not logged in user'; } ?>[/psfd_php]
[psfd_php] if ( 0 != get_current_user_id() ) { the_author_meta( 'user_description', get_current_user_id() ); } else { echo 'Not logged in user'; } [/psfd_php]
-
This reply was modified 7 years, 8 months ago by
autox420.
What is the output of the shortcode ?
Best Regards,
PluginlySpeakingI did some tests on my side and it’s working.
I used the same shortcode as you :
[psfd_php] if ( 0 != get_current_user_id() ) { the_author_meta( 'user_description', get_current_user_id() ); } else { echo 'Not logged in user'; } [/psfd_php]
Firstly, it didn’t display anything. The reason was simple, my personnal user’s description was empty.
I put some stuff in it and then the description was displayed in the floating div.
Best Regards,
PluginlySpeakingWhen i use my php code in a widget.
When not logged in.
When logged in.
When i use your code in floating div.-
This reply was modified 7 years, 8 months ago by
autox420.
Well the php codes works but its another problem i have i think.
I dont know if you can help with this but im trying to use it like this.
Only then i get that error.<iframe width="362" height="395" src="http://something.com/[psfd_php] if ( 0 != get_current_user_id() ) { the_author_meta( 'user_description', get_current_user_id() ); } else { echo 'Not logged in user'; } [/psfd_php]" frameborder="0"></iframe>
?
Hi,
Sorry for the late answer, which error do you get with this code ? Is it the error in the last of the three screenshots you sent me ?
Best Regards,
PluginlySpeakingThis one: https://i.imgur.com/OyGRTj2.png
I asked in stackoverflow also: https://stackoverflow.com/questions/47096994/php-is-not-loaded-in-the-iframe
I think i need to use php code all the way.
Do you know the correct code for this example?
I think the solution is like this.[psfd_php] iframe echo www.website.comm/PHP.CODE.HERE; [/psfd_php]
-
This reply was modified 7 years, 8 months ago by
- The topic ‘Allow PHP’ is closed to new replies.