WP People the next generation

Well, I’ve been working on updating the WP People hack to a WP 2.0 plugin.
Last night I was trying to get the links working. The biggest issue I had was pointing to the correct directory for the JavaScript and php files that creates the popup layer. Since not everyone has their blog on the root directory or as in my case, one level down, I can’t just go to the root and go from there. Also, not everyone named their blog directory “blog” or “wordpress”.

So, in the plugin part was easy, sort of

get_option('siteurl')

That got me the root and then I just went up from there, since everyone who uses 2.0 has to use the correct file structure. The next problem after that was putting it into the header. After searching through the codex stuff, I finally figure out how to do that.


function ibox_wp_head($unused)
{
$blogSiteURL = get_option('siteurl');
echo "<script type=\"text/javascript\" src=\"" . $blogSiteURL . "/wp-content/plugins/wp-people/ibox.js\"></script>";
echo "<link rel=\"stylesheet\" href=\"" . $blogSiteURL . "/wp-content/plugins/wp-people/ibox.css\" type=\"text/css\" media=\"screen\" />";
}
add_action('wp_head', 'ibox_wp_head');

By creating a function to insert the JavaScript and Style sheet links and then adding that function to the “wp_head” hook, I can place my code in the header area without breaking the site.

In the popup file, I had to be a little more creative. Since the popup file isn’t part of the blog structure, I can’t use the function to determine where the site root was.
$uriPieces = explode("/",$_SERVER['PHP_SELF']);
$key = array_search('wp-content', $uriPieces);
$blogRoot = "/wp-blog-header.php";
if($key > 0)
{
$blogRoot = "/" . $uriPieces[$key - 1] . $blogRoot;
}
require($_SERVER['DOCUMENT_ROOT'] . $blogRoot);

So, I found the current location of the page, split it up into an array, and then checked to see where the “wp-content” file was. From there, I just went down one level to get the blog root.

In the JavaScript I had to determine where the root image directory was.
var thisDomain = document.domain;
This gives me the document domain and from there I get the image directory.

About DeanLogic
Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.

About DeanLogic

Dean has been playing around with programming ever since his family got an IBM PC back in the early 80's. Things have changed since BASICA and Dean has dabbled in HTML, JavaScript, Action Script, Flex, Flash, PHP, C#, C++, J2ME and SQL. On this site Dean likes to share his adventures in coding. And since programming isn't enough of a time killer, Dean has also picked up the hobby of short film creation.