admin管理员组文章数量:1291008
I'm publishing post using an schedule event. The publish function uploads an image using media_sideload_image
and creates a post.
The issue is when this event triggers, it fails with the error media_sideload_image
as undefined.
I tried running both naturally and via wp crontrol plugin. Both seems to fail. Not sure what is the order when the cron functions are called.
Can someone please help here ?
[08-Jun-2021 19:57:19 UTC] PHP Fatal error: Uncaught Error: Call to undefined function media_sideload_image() in
Below is a skeleton code of how I'm scheduling the function
class Post_Scheduler{
public static function init(){
register_activation_hook( PLUGIN_FILE, array( __CLASS__, 'on_activate' ) );
add_action( 'publish_post_action', array( __CLASS__, 'publish_post_func' ) );
}
public static function on_activate(){
if( !wp_next_scheduled( 'publish_post_action' ) ){
wp_schedule_event( time(), 'daily', 'publish_post_action' );
}
}
public static function publish_post_func(){
my_function_to_create_post();
}
}
Post_Scheduler::init();
function my_function_to_create_post(){
// Some logic
wp_insert_post(); // This works. Post gets created.
media_sideload_image(); // But this fails with undefined
}
本文标签: uploadsCertain functions are not available when executed with wpscheduleevent
版权声明:本文标题:uploads - Certain functions are not available when executed with wp_schedule_event 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741515922a2382887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论