[英]How can I disable plugings for wordpress when doing posts with PHP?
I load wordpress with my php code like this to do actions: 我用我的PHP代码加载wordpress来执行以下操作:
define( 'WP_USE_THEMES', false ); // Don't load theme support functionality
require( './wp-load.php' );
How could I also disable plugins temporarily when I want to add posts, etc? 当我要添加帖子等时,如何临时禁用插件? This would be to use less server resources... 这将使用更少的服务器资源...
I don't believe there's actually a good way to do this. 我不认为实际上有个好方法。 The best way is probably to run your function before plugins are loaded. 最好的方法可能是在加载插件之前运行您的函数。 Otherwise you're looking at programatically renaming the /plugins
folder or WP_PLUGIN_[DIR/URL]
constants which just screams "error prone" 否则,您正在查看以编程方式重命名/plugins
文件夹或WP_PLUGIN_[DIR/URL]
常量,它们只会发出“容易出错”的提示
Effectively you can hook into the first action hook available, which is muplugins_loaded
: Source . 实际上,您可以插入第一个可用的动作钩子,即muplugins_loaded
: Source 。 Especially if you have no mu-plugins
to be run, it should be run almost instantaneously: 特别是如果您没有要运行的mu-plugins
,则应几乎立即运行它:
add_action( 'muplugins_loaded', 'run_before_plugins_load' );
function run_before_plugins_load(){
if( condition == met ){
// Insert your post here
if( $post_id = wp_insert_post( $my_post ) ){
exit(); // Post inserted, stop processing anything.
} else {
wp_die( 'Post not inserted' );
}
}
}
From there you'll have inserted a post and stopped any further propagation. 从那里您将插入一个帖子并停止任何进一步的传播。 Of course, you can replace exit
and wp_die
with whatever you want - it's just the fastest way I can see to run a WP function without actually loading plugins. 当然,您可以使用wp_die
的任何值替换exit
和wp_die
这是我看到的无需实际加载插件即可运行WP函数的最快方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.