[英]WP is not loaded correctly when usingin external scripts
i have problem with using function/events of WP in external file. 我在外部文件中使用WP的功能/事件有问题。
Here is a code example: 这是一个代码示例:
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
define('THEME_ROOT', dirname(dirname(__FILE__)));
define ('WP_ROOT', dirname(dirname(dirname(THEME_ROOT))));
// Include WP
require( WP_ROOT . '/wp-blog-header.php' );
// Include Autoloader
require_once(THEME_ROOT . '/vendor/autoload.php');
function crazyLoaded() {
echo 'Hello WP';
}
add_action('wp_loaded', 'crazyLoaded');
$imagePost = media_handle_sideload(array('<siteroot>'.$data['Venue.image']),0);
Function crazyLoaded() is not calling at all and call media_handle_sideload() is leading to Fatal Error "Unknown Function" while wp_insert_post()/wp_insert_term() and other "wp_" functions are working correctly. 函数crazyLoaded()根本不调用,调用media_handle_sideload()导致致命错误“未知函数”,而wp_insert_post()/ wp_insert_term()和其他“wp_”函数正常工作。
What am i doing wrong? 我究竟做错了什么? Thanks.
谢谢。
Including 包含
include_once( ABSPATH . 'wp-admin/includes/admin.php' );
Saved the day. 节省了一天。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.