add_filter("comment_post", "email_project_designer");
function email_project_designer(){
wp_mail( '[email protected]' , 'subject', 'message' );
}
That works great. But I really need the email address to be populated using a custom meta value from the post that is receiving the new comment. The code below is as far as I got, with no luck. My feeling is the action has no idea what post to associate the function with.
If it makes a difference, This function is being included with a plugin that uses custom post types. The meta value comes from the custom post type included with the plugin.
add_filter("comment_post", "email_project_designer");
function email_project_designer(){
$p_designer_email = get_post_meta( $post->id, 'project_designer_email', true );
wp_mail( $p_designer_email , 'subject', 'message' );
}
Thanks in advance for any help.
Ray
]]>comment_form_after_fields
, then save it via comment_post
.
My two code snippets are below;
add_action( 'comment_form_logged_in_after', 'plugin_additional_fields' );
add_action( 'comment_form_after_fields', 'plugin_additional_fields' );
function plugin_additional_fields() {
echo '<p class="comment-form-cost">'.
'<label for="cost">' . __( 'Project cost' ) . '<span class="required">*</span></label>'.
'<input id="cost" name="cost" type="text" size="30" tabindex="5" /></p>';
}
add_action( 'comment_post', 'plugin_save_comment_meta_data' );
function plugin_save_comment_meta_data( $comment_id ) {
if ( ( isset( $_POST['cost'] ) ) && ( $_POST['cost'] != '') ) {
$cost = wp_filter_nohtml_kses($_POST['cost']);
add_comment_meta( $comment_id, 'cost', $cost );
}
}
I’ve changed the function names for now, so ignore inconsistencies there if there are any.
This successfully renders the additional field in the comment box (although not with Jetpack )
If I submit a comment, it doesn’t automatically appear below as I’d normally expect it to. When I check in the backend I see the two following issues;
Notice: Trying to get property of non-object in /home/sites/DOMAIN.co.uk/public_html/wp-includes/capabilities.php on line 1180
Notice: Trying to get property of non-object in /home/sites/DOMAIN.co.uk/public_html/wp-admin/includes/class-wp-comments-list-table.php on line 484
The line numbers differ (there are perhaps 20 errors in total).
I’ve disabled all plugins and removed all custom functions.php file contents, so I think it’s down to my script above. The issue only persists when I’ve got a comment in the pending queue – so it must be an issue of reading in the custom meta?
Any help would be appreciated!
Aaron
]]>But I’m not sure how to add a hook/action command after the comment is submitted to execute the code.
I think it has something to do with preprocess_comment or comment_post. But I really am not sure what to do. I’d really appreciate any help. Thanks.
My fields I added to the comment form are as follows
<input type="hidden" name="fbtoken" id="fbtoken" value="..." />
<input type="hidden" name="fburl" id="fburl" value="https://graph.facebook.com/136789689670650_141764672506485/comments" />
And the code to post to my facebook fan page is as follows
<?php $access_tkn= $_POST['fbtoken'];?>
<?php $message = trim($_POST['comment']); ?>
<?php $fburl = $_POST['fburl']); ?>
<?php $fbargs = array('access_token' => $access_tkn, 'message' => $message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fburl);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fbargs);
$data = curl_exec($ch);
curl_close($ch);?>
]]>Anyone know if there is an action hook that check before you post a comment or if there is a plugin out there that lets you limit one comment per user per post?
]]>Is there an easy way to test it?
function myfunction($comment_ID) {
update_option('test_respsonse', 'This should be saved');
}
add_action('comment_post', 'myfunction');
Technically shouldn’t myfunction() get executed when someone submits a comment?
On the admin page for the plugin I have something to this effect:
echo "Repsonse: ". get_option('test_response');
But it does not show any changes so I am assuming my add_action() hook isn’t executing properly.
What am I doing wrong?
]]>