I am trying to add a function to delete the comments (messages) from the front end.
This is a WordPress theme that uses the commenting ability to allow Users (Subscribers) to message each other. But there is no Delete function. Front end Users (Subscribers) can not delete messages.
There are 2 functions.php files. 1st in root/functions.php 2nd in root/framework/functions.php
1st in root/functions.php: I have not added additional code
//Define constants
define('SITE_URL', home_url().'/');
define('AJAX_URL', admin_url('admin-ajax.php'));
define('THEME_PATH', get_template_directory().'/');
define('CHILD_PATH', get_stylesheet_directory().'/');
define('THEMEX_PREFIX', 'themex_');
2nd in root/framework/functions.php Original code sample
function themex_get_string($key, $type, $default) {
$name=$key.'-'.$type;
$string=$default;
$strings=array();
include(THEMEX_PATH.'strings.php');
if(isset($strings[$name])) {
$string=$strings[$name];
}
return themex_stripslashes($string);
}
Code I added to 2nd in root/framework/functions.php Does Not Work! Creates a Server Error!
function custom_delete_post_comment() {
$comment_id = comment_ID();
wp_delete_comment( $comment_id, true )
}
if ( isset( $_POST['comment_delete_nonce'] ) ) {
if( wp_verify_nonce( $_POST['comment_remove_nonce'], 'comment-remove-nonce' ) ) {
set_query_var( 'commentid1', $_POST['commentid'] );
wp_delete_comment( get_query_var( 'commentid1'), true );
wp_safe_redirect( wp_get_referer() ); exit;
}
Could someone please look at my functions code and help me to code it correctly please.
Additional code that I have added to the template-messages.php between <form method .....</form>
<li>
<div class="listed-message">
<header class="message-header clearfix">
<h6 class="message-author"><a href="<?php echo get_author_posts_url($comment->user_id); ?>"><?php comment_author(); ?></a></h6>
<time class="message-date" datetime="<?php comment_time('Y-m-d'); ?>"><?php comment_time(get_option('date_format')); ?></time>
</header>
<?php comment_text(); ?>
</div>
<form method="POST" action="" class="delete-comment-form">
<input type="hidden" name="comment_remove_nonce" value="<?php echo wp_create_nonce('comment-remove-nonce'); ?>" />
<input type="hidden" name="commentid" value="<?php comment_ID() ?>" />
<input type="submit" value="Delete" title="Delete" id="submit-btn" class="btn" />
</form>
</li>