Prepare post author comment moderation
The frontend AJAX moderation can now be shows for the post authors but they cannot yet actually use it.
This commit is contained in:
parent
41bc7c35f3
commit
37ccf428d1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -229,9 +229,17 @@ add_action( 'init', 'fictioneer_modify_allowed_tags', 20 );
|
||||
*/
|
||||
|
||||
function fictioneer_root_attributes() {
|
||||
global $post;
|
||||
|
||||
// Setup
|
||||
$post_author_id = ( $post instanceof WP_Post ) ? $post->post_author : 0;
|
||||
$output = [];
|
||||
$header_classes = [];
|
||||
|
||||
if ( is_archive() || is_search() || is_404() ) {
|
||||
$post_author_id = 0;
|
||||
}
|
||||
|
||||
// Add configuration classes
|
||||
if ( get_theme_mod( 'inset_header_image', false ) ) {
|
||||
$header_classes[] = 'inset-header-image';
|
||||
@ -263,6 +271,11 @@ function fictioneer_root_attributes() {
|
||||
}
|
||||
}
|
||||
|
||||
// Fingerprint
|
||||
if ( $post_author_id ) {
|
||||
$output['data-author-fingerprint'] = fictioneer_get_user_fingerprint( $post_author_id );
|
||||
}
|
||||
|
||||
// Filter output
|
||||
$output = apply_filters( 'fictioneer_filter_root_attributes', $output );
|
||||
|
||||
|
@ -376,6 +376,42 @@ if ( ! function_exists( 'fictioneer_get_comment_action_link' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// CHECK USER COMMENT MODERATION PERMISSION
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Checks whether an user can moderate a comment
|
||||
*
|
||||
* @since Fictioneer 5.7.3
|
||||
*
|
||||
* @param WP_Comment $comment Comment object.
|
||||
* @param int|null $user_id The user ID to check permission for. Defaults to
|
||||
* the current user ID.
|
||||
*
|
||||
* @return boolean True if the user can moderate the comment, false otherwise.
|
||||
*/
|
||||
|
||||
function fictioneer_user_can_moderate( $comment, $user_id = null ) {
|
||||
// Capability?
|
||||
$user_id = $user_id ? $user_id : get_current_user_id();
|
||||
|
||||
if ( user_can( $user_id, 'moderate_comments' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Post author?
|
||||
$post = get_post( $comment->comment_post_ID );
|
||||
$post_author_id = absint( $post->post_author );
|
||||
|
||||
if ( $post_author_id === get_current_user_id() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Nope!
|
||||
return false;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// RENDER COMMENT MODERATION MENU
|
||||
// =============================================================================
|
||||
@ -386,7 +422,7 @@ if ( ! function_exists( 'fictioneer_comment_mod_menu' ) ) {
|
||||
*
|
||||
* @since Fictioneer 4.7
|
||||
*
|
||||
* @param object $comment Comment object.
|
||||
* @param WP_Comment $comment Comment object.
|
||||
*/
|
||||
|
||||
function fictioneer_comment_mod_menu( $comment ) {
|
||||
@ -396,6 +432,7 @@ if ( ! function_exists( 'fictioneer_comment_mod_menu' ) ) {
|
||||
// Abort conditions...
|
||||
if (
|
||||
! current_user_can( 'moderate_comments' ) &&
|
||||
// TODO: ! fictioneer_user_can_moderate( $comment ) &&
|
||||
! get_option( 'fictioneer_enable_public_cache_compatibility' )
|
||||
) {
|
||||
return;
|
||||
|
@ -1,3 +1,13 @@
|
||||
// =============================================================================
|
||||
// CHECK IF USER IS POST AUTHOR (TODO)
|
||||
// =============================================================================
|
||||
|
||||
// document.addEventListener('fcnUserDataReady', () => {
|
||||
// if (fcn_getUserData().fingerprint == fcn_theRoot.dataset.authorFingerprint) {
|
||||
// fcn_theBody.classList.add('is-post-author');
|
||||
// }
|
||||
// });
|
||||
|
||||
// =============================================================================
|
||||
// THEME COMMENTS JS TRAP
|
||||
// =============================================================================
|
||||
@ -69,7 +79,7 @@ function fcn_moderateComment(id, operation) {
|
||||
'operation': operation,
|
||||
'id': id
|
||||
})
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (response.success) {
|
||||
// Server action succeeded
|
||||
switch (response.data.operation) {
|
||||
@ -111,7 +121,7 @@ function fcn_moderateComment(id, operation) {
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// Server action failed, mark comment with alert
|
||||
menuToggleIcon.classList = 'fa-solid fa-triangle-exclamation mod-menu-toggle-icon';
|
||||
menuToggleIcon.style.color = 'var(--warning)';
|
||||
@ -166,7 +176,10 @@ function fcn_addCommentMouseleaveEvents() {
|
||||
element.addEventListener(
|
||||
'mouseleave',
|
||||
e => {
|
||||
if ( fcn_lastClicked ) fcn_lastClicked.classList.remove('last-clicked');
|
||||
if (fcn_lastClicked) {
|
||||
fcn_lastClicked.classList.remove('last-clicked');
|
||||
}
|
||||
|
||||
fcn_lastClicked = null;
|
||||
e.stopPropagation();
|
||||
}
|
||||
@ -189,7 +202,9 @@ fcn_addCommentMouseleaveEvents();
|
||||
|
||||
function fcn_flagComment(source) {
|
||||
// Only if user is logged in
|
||||
if (!fcn_isLoggedIn) return;
|
||||
if (!fcn_isLoggedIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Setup
|
||||
const comment = source.closest('.fictioneer-comment'),
|
||||
@ -209,7 +224,7 @@ function fcn_flagComment(source) {
|
||||
'id': comment.dataset.id,
|
||||
'dubious': reportButton.classList.contains('_dubious')
|
||||
})
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
// Comment successfully reported?
|
||||
if (response.success) {
|
||||
reportButton.classList.toggle('on', response.data.flagged);
|
||||
@ -226,7 +241,7 @@ function fcn_flagComment(source) {
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
// Show server error
|
||||
if (error.status && error.statusText) {
|
||||
fcn_showNotification(`${error.status}: ${error.statusText}`, 5, 'warning');
|
||||
@ -267,7 +282,7 @@ function fcn_addCommentFormEvents() {
|
||||
event => {
|
||||
fcn_revealCommentFormInputs(event.currentTarget);
|
||||
},
|
||||
{once: true}
|
||||
{ once: true }
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ body:not(.is-admin) {
|
||||
}
|
||||
}
|
||||
|
||||
body:not(.is-moderator):not(.is-admin) {
|
||||
body:not(.is-moderator):not(.is-admin):not(.is-post-author) {
|
||||
.only-moderators {
|
||||
display: none;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user