0

Basically I want to use wordpress functions for example wp_create_user() or wp_update_user() outside of wordpress (outside of wordpress directory).

I tried with all the below code snippets to load the wordpress environment, I am able to use the functions correctly in both the cases but the problem is that this also loads the wordpress template which I do not want.

First Method:

<?php
define('WP_USE_THEMES', false);
require ('../blog/wp-load.php');
?>

Second Method:

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

Directory Structure:

/blog
  |
  |_ Wordpress installed here
/admin
  |
  |_ admin.php (I want to use wp functions here)

Note: I am using Writr theme in my wordpress blog.

1
  • what is your filename and where it is located relative to your wordpress setup ?
    – Shazzad
    Commented Dec 21, 2013 at 8:32

4 Answers 4

2

If you place the file in the WP root directory, e.g. http://mysite.com/myscript.php

require( dirname(__FILE__) . '../blog/wp-load.php' );
if (function_exists('wp_create_user')) {
    echo "wp_create_user() found";
}

If you are in a different directory, just make sure you are loading wp-load.php from the proper location.

1
  • I have mentioned the directory structure in my question, you can give the answer accordingly.Thanks
    – Ram Patra
    Commented Dec 21, 2013 at 18:59
1

Yes and to do such a thing you can use something like this :

// load only basics
if ( SHORTINIT ) return false;

EDIT: I've found this constant. If set WordPress initializes to a minimum

4
  • tried, not working. The wp theme is being loaded.
    – Ram Patra
    Commented Dec 21, 2013 at 11:03
  • I've edited code.
    – JMau
    Commented Dec 21, 2013 at 13:34
  • still not working
    – Ram Patra
    Commented Dec 21, 2013 at 15:25
  • I've edited code again ^^
    – JMau
    Commented Dec 25, 2013 at 13:54
0

The functions.php of the theme was breaking the html of my other page. That's what I did and solved my problem:

define('STYLESHEETPATH', '');
define('TEMPLATEPATH', '');
require_once(RAIZ_WORDPRESS."/wp-load.php");
0

Well I don't know the reason how this worked but it did.

At first, I was loading the wp environment in the beginning of my file and it was loading the wp template(wp theme) which I didn't want.

But now I loaded the wp environment at the end of the file and it worked.

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.