How to load wordpress environment without loading the template?

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.

Topic wp-blog-header.php wp-load.php outside-wordpress Wordpress

Category Web


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


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.


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");

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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.