Integrating WordPress into another application.

14 views
Skip to first unread message

philipnorton42

unread,
Oct 6, 2011, 1:09:52 PM10/6/11
to Manchester WordPress User Group
Ok, ok, I can see some of you cringing about this, but lets say I
wanted to include and bootstrap WordPress so that I can call some of
the WordPress functions. A typical example might be to print out a
list of posts on a page on another (locally hosted) site.

In my situation I had a Zend Framework application sat next to a
WordPress install. I managed to figure out how to share user details
across the systems, so that when a user logs into one they are logged
into both, but I had one small stumbling block.

When a user logged out of the ZF application I wanted it to also log
the user out of the WordPress application. I thought it might be a
good idea to do the following (which is detailed on the WP site[1])
and then use the WordPress functions to logout:

define('WP_USE_THEMES', false);
require('../wp-blog-header.php');

But what happened was that WordPress tried to look up an option from
the options table, but somehow lost the table prefix we had, which
meant that it couldn't see the tables. This meant it redirected the
user to the install page. So I tried to force the prefixes to be put
in place like this.

global $table_prefix;
$table_prefix = 'wp_';
define('WP_USE_THEMES', false);
require('../wp-blog-header.php');

This made the application work, but ended up causing an infinite loop
to occur as the system bounced back and forth between the
authentication states of WordPress and my application.

I may have just answered my own question here (I'll post this anyway),
but has anyone else done anything like this. Is there any way of
bootstrapping WordPress just enough to get access to the API
functions? I fixed the above problem in a different way, but I thought
that this should be possible.

Answers on a postcard I guess :)

Thanks!

Phil


[1] http://codex.wordpress.org/User:Jalenack/Integrating_Wordpress_into_an_Existing_Site

Mike Little

unread,
Oct 6, 2011, 1:27:38 PM10/6/11
to manchester-word...@googlegroups.com
On Thu, Oct 6, 2011 at 18:09, philipnorton42 <philipn...@gmail.com> wrote:
Ok, ok, I can see some of you cringing about this, but lets say I
wanted to include and bootstrap WordPress so that I can call some of
the WordPress functions. A typical example might be to print out a
list of posts on a page on another (locally hosted) site.



Funnily enough, this came up on the wp-hackers mailing list in the last two days  http://lists.automattic.com/pipermail/wp-hackers/2011-October/040931.html

The key thing useful to you is this 
"If you don't plan on doing something that visually themed like your site, you can just include wp-load.php"

Now, the other thing sparked by the problems you say you had, sounded like WordPress couldn't find wp-config.php. Crucial to that is that the current directory of the executing script must be the same directory that contains wp-load.php (wp-config.php can be one directory nearer to root (to keep it out of document root).

Hope that helps,




Mike

--
Mike Little


Reply all
Reply to author
Forward
0 new messages