Skip to content

Commit

Permalink
Add offensive/appropriate frontend mod menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrakern committed Nov 15, 2024
1 parent a349176 commit dd2d6b4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion css/comments.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/complete.css

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion includes/functions/comments/_comments_moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ function fictioneer_comment_mod_menu( $comment ) {
<?php if ( get_option( 'fictioneer_enable_ajax_comment_moderation' ) ) : ?>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="trash"><?php _e( 'Trash', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="spam"><?php _e( 'Spam', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="offensive"><?php _e( 'Offensive', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="appropriate"><?php _e( 'Appropriate', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="unapprove"><?php _e( 'Unapprove', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="approve"><?php _e( 'Approve', 'fictioneer' ); ?></button>
<button data-id="<?php echo $comment_id; ?>" data-click="ajax-mod-action" data-action="close"><?php _e( 'Close', 'fictioneer' ); ?></button>
Expand Down Expand Up @@ -533,7 +535,12 @@ function fictioneer_ajax_moderate_comment() {

$operation = sanitize_text_field( $_POST['operation'] );

if ( ! in_array( $operation, ['spam', 'trash', 'approve', 'unapprove', 'close', 'open', 'sticky', 'unsticky'] ) ) {
if (
! in_array(
$operation,
['spam', 'trash', 'offensive', 'appropriate', 'approve', 'unapprove', 'close', 'open', 'sticky', 'unsticky']
)
) {
wp_send_json_error( array( 'error' => 'Invalid operation.' ) );
}

Expand Down Expand Up @@ -562,6 +569,12 @@ function fictioneer_ajax_moderate_comment() {
case 'trash':
$result = wp_set_comment_status( $comment_id, 'trash' );
break;
case 'offensive':
$result = fictioneer_update_comment_meta( $comment_id, 'fictioneer_marked_offensive', true );
break;
case 'appropriate':
$result = fictioneer_update_comment_meta( $comment_id, 'fictioneer_marked_offensive', false );
break;
case 'approve':
$result = wp_set_comment_status( $comment_id, 'approve' );
break;
Expand Down
2 changes: 1 addition & 1 deletion js/comments.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/complete.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/js/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ function fcn_moderateComment(id, operation) {
case 'unsticky':
comment.classList.remove('_sticky');
break;
case 'offensive':
comment.classList.add('_offensive');
break;
case 'appropriate':
comment.classList.remove('_offensive');
break;
case 'approve':
comment.classList.remove('_unapproved');
break;
Expand Down
14 changes: 13 additions & 1 deletion src/scss/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
margin-top: 0;
}

button:is([data-action=sticky], [data-action=approve], [data-action=unapprove]) {
button:is([data-action=sticky], [data-action=approve], [data-action=unapprove], [data-action=offensive], [data-action=appropriate]) {
display: none;
}
}
Expand Down Expand Up @@ -362,6 +362,18 @@
}
}

&._offensive > .fictioneer-comment__container {
[data-action=offensive] {
display: none;
}
}

&:not(._offensive) > .fictioneer-comment__container {
:is([data-action=appropriate], .moderation-note-offensive) {
display: none;
}
}

&._sticky {
position: relative;

Expand Down

0 comments on commit dd2d6b4

Please sign in to comment.