admin管理员组文章数量:1390334
I have a "real" cron job that executes wp-cron.php every now or then. I collect the link in to a variable by $link = get_edit_post_link(ID);
It works flawlessly if I am logged in and execute cron manually with wp-cron.php but when it is executed by schedule it wont collect the link and leaves it empty. Striped down version of code:
foreach($published_posts as $post_to_private){
$user_data = get_userdata( $post_to_private->post_author);
$email = $user_data->user_email;
$link = get_edit_post_link( $post_to_private->ID);
$email = WP_Mail::init()
->to($email)
"X-Mailer: PHP/". phpversion(),
"Content-type: text/html; charset=utf-8",
])
->subject('test')
->template(plugin_dir_path( __DIR__ ) .'email-templates/expired-transit-email.php', [
'link' => $link,
]);
//for testing of email
return $email->send();
Any ideas?
I have a "real" cron job that executes wp-cron.php every now or then. I collect the link in to a variable by $link = get_edit_post_link(ID);
It works flawlessly if I am logged in and execute cron manually with wp-cron.php but when it is executed by schedule it wont collect the link and leaves it empty. Striped down version of code:
foreach($published_posts as $post_to_private){
$user_data = get_userdata( $post_to_private->post_author);
$email = $user_data->user_email;
$link = get_edit_post_link( $post_to_private->ID);
$email = WP_Mail::init()
->to($email)
"X-Mailer: PHP/". phpversion(),
"Content-type: text/html; charset=utf-8",
])
->subject('test')
->template(plugin_dir_path( __DIR__ ) .'email-templates/expired-transit-email.php', [
'link' => $link,
]);
//for testing of email
return $email->send();
Any ideas?
Share Improve this question asked Feb 16, 2020 at 7:36 kru-xkru-x 415 bronze badges 1 |1 Answer
Reset to default 3Solved by:
//Check and set/unset user to able the script to run as admin
wp_set_current_user(1);
$link = get_edit_post_link($post_to_private->ID);
wp_set_current_user(0);
Thanks Sally CJ,
本文标签: pluginsgeteditpostlink() not working on wpcron
版权声明:本文标题:plugins - get_edit_post_link() not working on wp-cron 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744742885a2622714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
get_edit_post_link()
checks if the current user has the permissions to edit the post. So you're getting the expected behavior. – Sally CJ Commented Feb 16, 2020 at 13:02