I am getting ready to enhance my WordPress site using phpBB3 Sessions variables.
Of course, to do this I wanted a quick and easy way to add PHP code into WordPress Posts, Pages and Widgets. This would allow me to display or hide a number of things based on if a user was logged into my phpBB3 forum. It would also allow me to login to phpBB3 from inside of WordPress as well as use any of the phpBB3 user information in post, pages and widgets! Ultimately, I want people to use WordPress to register for my phpBB3 forum (and for the members only information in WordPress too)!
My goal is NOT complete WordPress phpBB3 integration. For example, logging into WordPress will NOT log you into phpBB3 or vice versa. I did NOT want this for security reasons. The forum is for member posting and the CMS / blog use of WordPress is restricted for just a few selected people to post.
As the phpBB3 sessions project develops, I will post below the links to it.
This post is about easy ways to include PHP code into the body of Posts, Pages, and Widgets.
PHP Code Widget
WARNING: BEFORE CONTINUING YOU MAY WANT TO READ
In Part Two I discuss why I may NOT be using the PHP Code widget plugin.
My first priority was to add PHP to a Widget. To my delight I found a plugin called PHP Code Widget!
It is super simple to install…
- Download the Widget Plugin
- Unpack it (unzip it)
- Upload execphp.php to the /wp-content/plugins/ directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
- Use the widget like any other widget.
It works just like the Text widget, but also allows working PHP code to be inserted. For example, if you put this in your PHP Code widget:[php] Testing
echo ‘Current date and time:<br />’;
echo date(‘l<b\r />dS \of F Y<b\r />h:i:s a’) . ‘ UTC’;
Would look something like this in your side column:
echo date(‘ldS \of F Yh:i:s a’) . ‘ UTC’;
Globals and Scope
You need to keep in mind that this is run inside of a function. Therefore before you use a global variable you need to declare it first. Something like this…[php] <?php
global $my_global_var ;
echo $my_global_var ;
That is enough for this Post. In Part Two I will deal with adding PHP into Pages and Posts.
This was tested with the Following:
Multisite Subdomain Configuration
WP Multi-Network Plugin Version 1.1
Executable PHP widget (PHP Code Widget Plugin Version 2.1)
I am now recommending Exec-PHP ~ Read Part Two!
Page Links To Plugin Version 2.4
SyntaxHighlighter Evolved Version 3.1.1
Information on adding phpBB3 Sessions to WordPress…
Still working on it…