• Kratzy

    (@kratzy)


    I’m trying to write a script that uses the following WordPress functions: wp_insert_post(), wp_create_user() and username_exists().

    The script is located outside the WordPress root directory, so I need to manually include the files where these functions are defined. Using trial and error and looking up the source file for each function on the Codex, I came up with this:

    include("../wp-includes/plugin.php");
    include("../wp-includes/pluggable.php");
    include("../wp-includes/post.php");
    include("../wp-includes/user.php");
    include("../wp-includes/registration.php");
    include("../wp-includes/formatting.php");

    But even this isn’t enough. I still get a weird cache class error.

    Is there a better way to do what I’m doing? This way just seems very hacky.

    Thanks.

Viewing 1 replies (of 1 total)
  • Marion Dorsett

    (@figmentthinking)

    So if your wordpress is installed in your webroot and you’re trying to access it from a subfolder, you want to do the following:

    Include wp-load.php first, and then include the other files you’re looking for. Wp-load.php will setup everything the other files need for you to access the functions properly.

    include_once(‘../wp-load.php’);

    If you find you still can’t access what you’re looking for, then include the file with the missing functions.

    include_once(ABSPATH . WPINC . ‘/plugin.php’);

Viewing 1 replies (of 1 total)
  • The topic ‘Problems with included files when using WordPress functions’ is closed to new replies.