您必须加载WP-load函数才能这样做,您需要WP-load文件,因此,如果您的自定义文件位于主题中,它应该看起来像这样:
$wp_load = \'../../../../../wp-load.php\';
if ( file_exists( $wp_load ) ) {
require_once( $wp_load );
}else{
die(\'no-load\');
}
您还可以将const SHORTINIT设置为true以最小化WP负载。。。如果你不需要完整的WP垃圾等,这是很有帮助的,但是你可以加载WP元素。。。取决于您的需要
function wp_load_utils ( ) {
require( ABSPATH . WPINC . \'/class-wp-walker.php\' );
require( ABSPATH . WPINC . \'/l10n.php\' );
require( ABSPATH . \'wp-admin/includes/admin.php\' );
require( ABSPATH . WPINC . \'/formatting.php\' );
require( ABSPATH . WPINC . \'/pluggable.php\' );
require( ABSPATH . WPINC . \'/script-loader.php\' );
require( ABSPATH . WPINC . \'/general-template.php\' );
require( ABSPATH . WPINC . \'/link-template.php\' );
//require( ABSPATH . WPINC . \'/shortcodes.php\' );
wp_functionality_constants();
}
function wp_load_session ( ) {
require( ABSPATH . WPINC . \'/capabilities.php\' );
require( ABSPATH . WPINC . \'/user.php\' );
require( ABSPATH . WPINC . \'/meta.php\' );
require( ABSPATH . WPINC . \'/post.php\');
require( ABSPATH . WPINC . \'/class-wp-user.php\' );
require( ABSPATH . WPINC . \'/class-wp-roles.php\' );
require( ABSPATH . WPINC . \'/class-wp-role.php\' );
require( ABSPATH . WPINC . \'/session.php\' );
wp_cookie_constants();
}
下面是处理ajax请求而不是管理ajax的自定义ajax文件。php,速度快得多。。。像standard一样,需要大约200-400ms才能命中admin。php输出,仅使用shortint即可在50ms内完成
https://gist.github.com/isuke01/a4d22fc19240928597a0dfed1af791e8