【发布时间】:2016-10-27 14:19:06
【问题描述】:
我在将一些变量从一个函数传递到另一个函数时遇到困难。
我试图让它们全球化,但收效甚微。
我要传递的变量是从send_email_notifications 到send_email_notification_function 的变量。
function send_email_notifications($ID, $post) {
global $notificationTitle;
global $notificationPermalink;
$notificationTitle = $post->post_title;
$notificationPermalink = get_permalink($ID);
if(isset($_REQUEST['send_email_notification'])) {
date_default_timezone_set('Europe/London');
wp_schedule_single_event(time() + 10, 'send_email_notification_function_execute');
}
}
add_action('publish_Test_notifications', 'send_email_notifications', 10, 2);
function send_email_notification_function() {
global $notificationTitle;
global $notificationPermalink;
echo $notificationTitle;
echo $notificationPermalink;
$notificationEmail = 'test@test.com';
wp_mail($notificationEmail, $notificationSubject, $notificationContent);
}
add_action('send_email_notification_function_execute', 'send_email_notification_function');
【问题讨论】:
标签: php variables scope global-variables