0

We have our own php system, now we want to have a blog function. Because wordpress are widely used, so we decided to use it. And now I want to invoke wordpress's function , for example wp_insert_user , how can I can do that ?

Suppose my system is A and installed on /var/www/A, and wordpress is WP and installed on /var/www/WP. I can put them together like this /var/www/A/WP, but I don't think that's a good idea.

If we use /var/www/A and /var/www/WP, how can I invoke wordpress's function from a php file that in project A? Using curl?

Edit:=======================================================

Now I put WP below A (/var/www/A/wordpress)

Here, in my project A , I have a logon.php, what I want to do is invoke 'wp_insert_user' function to create a new wordpress user when user logon our system (just a test purpose).

I put the following code at the beginning of my logon.php

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

Before I add the two line, when I visit my site, the url is :

http://localhost/myproject/www/logon.php

After I add it, the url become this:

http://localhost/myproject/www/logon.php/wp-admin/install.php

what worse, all the style of my logon.php are completely gone.

My requirement is simple:

when user logon our system, invoke wordpress function 'wp_insert_user' 
to create a user for wordpress. Just to create a new user, no more action.

2 Answers 2

3

You can add the following snippet at the start of your PHP file to load WordPress in it.

define( 'WP_USE_THEMES', false );
require('wp-blog-header.php'); // chage the path to match your WP directory
//the rest of your code here

EDIT: Alternatively, you could use wp-load.php instead of wp-blog-header.php.

define( 'WP_USE_THEMES', false );
require('wp-load.php'); // chage the path to match your WP directory
//the rest of your code here

This answer explains that:

It loads all of WordPress, but doesn't call wp() or invoke the template loader (used by themes). Method 2 will be a little lighter-weight, but should give you the same functionality.

5
  • I update my question, pls help me.
    – diligent
    Jun 17, 2013 at 7:23
  • Looks like you didn't install WordPress... Install it first.
    – RRikesh
    Jun 17, 2013 at 7:40
  • Oh, maybe, I install it before, so I just copy the installed file to /var/www/A. I reinstall it. Thanks
    – diligent
    Jun 17, 2013 at 7:59
  • After I install it, still got the problem.
    – diligent
    Jun 17, 2013 at 8:18
  • try to access it directly to confirm
    – RRikesh
    Jun 17, 2013 at 9:13
2

Like RRikesh said, including wp-blog-header.php will work but it also has lines of code that includes theme templates. You can take it one step further and just include wp-load.php so you have the bare bones, no extra frills or extra stuff to load.

1
  • 1
    The theme templates won't load if you're using define( 'WP_USE_THEMES', false );. This answer talks about the difference. Effectively, including wp-load should be lighter.
    – RRikesh
    Jun 17, 2013 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.