How to call WordPress functions in a custom PHP script

后端 未结 7 466
小蘑菇
小蘑菇 2020-12-07 16:52

I have a PHP script I want to use for creating a new blog in WPMU. I am having trouble calling WordPress functions like wpmu_create_user and wpmu_create_blog.

My hop

相关标签:
7条回答
  • 2020-12-07 17:40

    I've got a universal solution that will work in any PHP file inside the wp-content folder without any adjustments or needing to know what is mysterious 'path/to/wordpress'

    require_once(explode("wp-content", __FILE__)[0] . "wp-load.php");
    

    It just automatically goes up to root of WordPress and loads wp-load.php.

    You can just paste it anywhere, no matter if it's a plugin or theme file, and it will work.

    I think stuff like ../../../.. looks extremely bad and when you modify the structure of your folders of a theme or plugin you can get crazy.


    Note: This solution assumes you didn't rename your wp-content folder.

    0 讨论(0)
提交回复
热议问题