accept to delete topics by anonymous user.

This commit is contained in:
CBS Information System 2020-12-17 18:57:18 +09:00
parent e4773eb254
commit cde2c85825
2 changed files with 51 additions and 0 deletions

View File

@ -507,6 +507,44 @@ function cbsonline_wpforo_edit_topic_data_filter($args)
return $args;
}
// - accept to delete topics by anonymous user
add_action('wp_ajax_nopriv_wpforo_delete_ajax', 'cbsonline_wpforo_nopriv_delete');
function cbsonline_wpforo_nopriv_delete()
{
if (is_user_logged_in()) {
return;
}
$resp = [];
$return = 0;
if ('topic' === $_POST['status']) {
if (WPF()->topic->delete(intval($_POST['postid']))) {
$forumid = (int) wpfval($_POST, 'forumid');
$resp = [
'postid' => intval($_POST['postid']),
'location' => $forumid ? WPF()->forum->get_forum_url($forumid) : wpforo_home_url(),
];
$return = 1;
}
} elseif ('reply' === $_POST['status']) {
$root = WPF()->post->get_root($_POST['postid']);
if (WPF()->post->delete(intval($_POST['postid']))) {
$root_replies_count = WPF()->post->get_root_replies_count($root);
$resp = [
'postid' => intval($_POST['postid']),
'root' => intval($root),
'root_count' => intval($root_replies_count),
];
$return = 1;
}
}
$resp['stat'] = $return;
$resp['notice'] = WPF()->notice->get_notices();
echo json_encode($resp);
exit();
}
// - set hostname if annoymous user add topic data
add_filter('wpforo_add_topic_data_filter', 'cbsonline_wpforo_add_topic_data_filter');
function cbsonline_wpforo_add_topic_data_filter($args)

View File

@ -34,6 +34,19 @@
$buttons = array( 'solved', 'sticky', 'private', 'close', 'report', 'delete', 'link' );
}else{
$buttons = array( 'report', 'delete', 'link' );
}
if (!is_user_logged_in()) {
$forumid = (isset($forum['forumid'])) ? $forum['forumid'] : 0;
$topicid = (isset($topic['topicid'])) ? $topic['topicid'] : 0;
$is_topic = (bool) wpfval($post, 'is_first_post');
$diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
if (WPF()->perm->forum_can(($is_topic ? 'dt' : 'dr' ), $forumid)
&& (WPF()->perm->forum_can( ($is_topic ? 'dot' : 'dor'), $forumid)
|| $diff < WPF()->post->options[($is_topic ? 'dot' : 'dor').'_durr'])) {
$a = ( $is_topic ) ? 'wpftopicdelete' : 'wpfreplydelete';
$b = ( $is_topic ) ? $topicid : $postid;
echo '<span wpf-tooltip="'.esc_attr(wpforo_phrase('Delete', false)).'" id="'.esc_attr($a.$b).'" class="wpf-action wpforo-delete"><i class="fas fa-trash-alt wpfsx"></i><span class="wpf-button-text">'.wpforo_phrase('Delete', false).'</span></span>';
}
}
wpforo_post_buttons( 'icon-text', $buttons, $forum, $topic, $post );
?>