私のブログに このチュートリアル を適用しようとしています。私はWoothemes ' Bueno Theme を使っています。
このコードを私のテーマのfunctions.phpファイルに追加します。
function ymc_add_meta_settings($comment_id) {
add_comment_meta(
$comment_id,
'mailchimp_subscribe',
$_POST['mailchimp_subscribe'],
true
);
}
add_action('comment_post', 'ymc_add_meta_settings', 1);
function ymc_subscription_add( $cid, $comment ) {
$cid = (int) $cid;
if ( !is_object($comment) )
$comment = get_comment($cid);
if ( $comment->comment_karma == 0 ) {
$subscribe = get_comment_meta($cid, 'mailchimp_subscribe', true);
if ( $subscribe == 'on' ) {
update_comment_meta($cid, 'mailchimp_subscribe', 'off');
/////////////////////////////////////
///////MailChimp////////////////////
///////////////////////////////////
$apikey = 'MYAPIKEY-us2';
$listid = 'MYLISTID';
$endpoint = 'http://us2.api.mailchimp.com/1.3/?output=php';
$request = array(
'apikey' => $apikey,
'id' => $listid,
'email_address' => strtolower( $comment->comment_author_email ),
'double_optin' => true,
'merge_vars' => array(
' <merge tag for name> ' => $comment->comment_author,
'OPTIN_IP' => $comment->comment_author_IP,
)
);
$result = wp_remote_post(
$endpoint.'&method=listSubscribe',
array( 'body' => json_encode($request) )
);
/////////////////////////////////////
///////MailChimp Ended////////////////////
///////////////////////////////////
}
}
}
add_action('comment_approved_','ymc_subscription_add',10,1);
add_action('comment_post', 'ymc_subscription_add', 60,1);
また、このコードはテーマのcomments.phpファイルに追加されました(</form>
の下):
<input style="width: auto;" type="checkbox" name="mailchimp_subscribe" id="mailchimp_subscribe"/>
<label for="mailchimp_subscribe">
Subscribe
</label>
</p>
しかし、コメントを送信しようとすると、このエラーが発生します。
Warning: Missing argument 2 for ymc_subscription_add() in /home/content/blabla/themes/bueno/functions.php on line 36
Warning: Cannot modify header information - headers already sent by (output started at /home/content/blabla/themes/bueno/functions.php:36) in /home/blabla/html/wp-comments-post.php on line 95
Warning: Cannot modify header information - headers already sent by (output started at /home/blabla/html/wp-content/themes/bueno/functions.php:36) in /home/content/blabla/wp-comments-post.php on line 96
Warning: Cannot modify header information - headers already sent by (output started at /home/blabla/html/wp-content/themes/bueno/functions.php:36) in /home/content/blabla/wp-comments-post.php on line 97
Warning: Cannot modify header information - headers already sent by (output started at /home/contentblabla/html/wp-content/themes/bueno/functions.php:36) in /home/content/blabla/wp-includes/pluggable.php on line 897
最後の2つのフックは、2の許容引数を指定します。1ではなく。
add_action('comment_approved_','ymc_subscription_add', 10, 2);
add_action('comment_post', 'ymc_subscription_add', 60, 2);