私のfunctions.phpには、公開時にスクリプトを実行する次のコードがあります。
function save_new_post($post_ID) {
$site_root = '/home/forexmag/public_html/directory2';
$post = get_post($post_ID);
$title = $post->post_title;
$breaking_news = false;
$categories = get_the_category($post_ID);
if (is_array($categories) && !empty($categories))
{
foreach ($categories as $cat_det)
{
//this is the id for the breaking (bad) news
if (5668 == $cat_det->cat_ID)
{
$breaking_news = true;
break;
}
}
}
$exec_code = "/usr/local/bin/php
$site_root
/crons/cron_notify.php '$title' $post_ID 2 " . intval($breaking_news);
exec(
$exec_code
);
} add_action('draft_to_publish', 'save_new_post', 10, 1);
新しい投稿を公開すると、次のエラーが発生し続けます。
Catchable fatal error: Object of class WP_Post could not be converted to string in /home/forexmag/public_html/wp-content/themes/forex_magnates/functions.php on line 712
この行は、変数を設定する場所です$exec_code
。ただし、ご覧のとおり、var_dumpで確認したように、$title
変数は文字列です。私は何が欠けていますか?
編集:さらに奇妙なのは、var_dump$exec_code
してスクリプトを強制終了すると、完全な文字列が得られることです。
string(121) "/usr/local/bin/php /home/forexmag/public_html/directory2/crons/cron_notify.php '2011 Free Forex Report' 9934 2 0"