Disable email notifications for custom post type when commenting
-
I am not sure of what your code is doing but don’t you have to declare your function before add_action(…) … like
function my_custom_commment($comment_id){ global $cache_settings; $comment = get_comment($comment_id); $post = get_post($comment->comment_post_ID); if ( $post->post_type=="my_custom_type" ) { $foo = get_settings('comments_notify'); // make sure it's cached $cache_settings->comments_notify = 0; } } add_action('comment_post', 'my_custom_commment');
Let me know if that works. If it does not I would have to really look at your code.
Also, my PHP is not that good but I suspect you need to look at the line
$cache_settings->comments_notify = 0;
Is this allowed in php? or should it be
$cache_settings->comments_notify(0);
Hi peter,
No sorry it is not working.$cache_settings->comments_notify = 0;
is correct because comments_notify is a variable and not a function.Thanks for your time
VatanThere is one other possibility in that you could have a spelling error in your function name:-
$comment = get_comment($comment_id);
should be :-
$comment = get_comments($comment_id);
The ‘s’ is missing in comments. I think this may be cause of all your problems … a typo error?
No I don’t get any php error. The function, get_comment(), is a valid function, see http://codex.wordpress.org/Function_Reference/get_comment
And it enters the if-statement:
if ( $post->post_type==”my_custom_type” )
so I don’t think there is any error in there.regards
VatanVery interesting both, get_comment() & get_comments(), are there in to documentation.
I checked and get_settings() has been deprecated. The doc, http://codex.wordpress.org/Function_Reference/get_settings, says use get_option($optionname) instead of get_settings(). Also do check get_bloginfo() at http://codex.wordpress.org/Function_Reference/get_bloginfo.
But non of them have ‘comments_notify’ as a parameter – its not a parameter in get_setting(). Unless it is defined in your options.php file see http://codex.wordpress.org/Function_Reference/get_settings,
“For a complete list of all options available through this function, go to
Thanks peter, I have missed that the function have been deprecated. I used get_option() instead and it works great. Thanks!
Vatan
- The topic ‘Disable email notifications for custom post type when commenting’ is closed to new replies.
(@vatanbytyqi)
9 years, 9 months ago
Hi,
I’m working on a plugin and have a custom post type and when someone makes a comment I don’t want to send an email to admin telling that a new comment need attention. But I don’t want to disable the notifications for all post type only for my custom type. I have tried some codes that I have found here on the forum but it is not working for me, I still get the notifications.
This is what I have tested so far:
Thanks in advance!
Vatan