• Resolved Rick Beckman

    (@brazenlygeek)


    I’m new to setting up sites using the FSE and have been enjoying the experience so far, but there’s one thing I’m stuck on.

    As an example, the comment edit link. This used to be output using edit_comment_link(), which was fully filterable and thus customizable. I generally add extra links using that filter, such as links to trash or mark as spam.

    However, in the FSE, the link is handled not by the same function but by the Comment Edit Link block… and as far as I can tell, it isn’t possible to really customize that block at all, outside of stylistically.

    Am I missing something? Is FSE replacing the ability to granularly control the output of a site in favor of a WYSIWIG experience?

    • This topic was modified 1 year, 3 months ago by Rick Beckman. Reason: tags
Viewing 8 replies - 1 through 8 (of 8 total)
  • Hey! In the site editor the Edit link is a block with its own style properties, yes. It can be styled locally (select it in the template and edit properties in the inspector), or it can be styled globally (go to global styles > Blocks > Comment Edit Link). The block should also be stylable through theme.json.

    Since it’s an entirely new block it does not share the same underlying function as the edit_comment_link.

    What in particular are you missing from the new block? We can always open a new issue to enhance the block further. Coming to mind for me is the ability to edit the text.

    Hey,

    It’s not possible to filter the Comment Edit Link block this way.

    Instead you can create dedicated blocks for trashing / marking comments as spam. This has the advantage of allowing you to place those blocks wherever you like.

    There’s a command line tool in Gutenberg for doing this. You can view a video walkthrough for that here. Or browse the source code here.

    James

    Thread Starter Rick Beckman

    (@brazenlygeek)

    I’m looking into the walkthrough you mentioned, James.

    Feels like a whoooole lot more work than posting a block of code in a dedicated plugins or theme functions file, though.

    This is the code I’m going to be attempting to adapt into a block…

    function shareable_add_comment_moderation_links( $moderation_links ) {
    	$comment_id = get_comment_id();
    	$nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment_id" ) );
    
    	# Mark comment as spam
    	$moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?action=spam&c=$comment_id" ) . '" title="mark this comment as spam">Spam</a>';
    	# Return comment to moderation queue
    	$moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?c=$comment_id&action=unapprovecomment&$nonce" ) . '" title="unapprove this comment">Unapprove</a>';
    	# Delete comment
    	$moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?action=trash&c=$comment_id" ) . '" title="trash this comment">Trash</a>';
    
    	return $moderation_links;
    }
    add_filter( 'edit_comment_link', 'shareable_add_comment_moderation_links', 1 );
    Thread Starter Rick Beckman

    (@brazenlygeek)

    I had no interest in installing a bunch of JavaScript tools on my computer, but I did eventually accomplish what I wanted, I think. I was able to use the plugin Lazy Blocks to create a block and use it in the FSE.

    Edit: False alarm. While it looks like the code was working — I get my moderation links output… they’re being output with a comment ID of 0. Evidently despite being in the comment block in the FSE, WordPress isn’t allowing it to see which comment is currently being rendered. The frustrations never end…

    Here’s my almost-working code I’m using in Lazy Blocks in the Frontend box for my block. Removing the get_comment() check at the top allows the links to load, but they point to comment #0, which of course doesn’t exist.

    <?php
    if ( current_user_can( 'moderate_comments' ) && get_comment() ) {
      $moderation_links = '';
      $comment_id = get_comment_id();
      $nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment_id" ) );
    
      $moderation_links .= '<div class="wp-block-comment-edit-link">' . "\n\t";
    
      # Mark comment as spam
      $moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?action=spam&c=$comment_id" ) . '" title="mark this comment as spam">Spam</a> | ';
      # Return comment to moderation queue
      $moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?c=$comment_id&action=unapprovecomment&$nonce" ) . '" title="unapprove this comment">Unapprove</a> | ';
      # Delete comment
      $moderation_links .= '<a target="_self" href="' . admin_url( "comment.php?action=trash&c=$comment_id" ) . '" title="trash this comment">Trash</a>';
    
      $moderation_links .= "\n</div>";
    
      echo $moderation_links;
    }
    ?>
    • This reply was modified 1 year, 3 months ago by Rick Beckman. Reason: my problem wasn't fixed

    Thanks for the followup, and sorry to hear you didn’t get it working. The moderation buttons to me seem valid to have part of the core offering. Would you be up for opening an issue in the githbub issue? Otherwise I’m happy to help: https://github.com/WordPress/gutenberg/issues

    I just remembered that a feature tentatively scheduled for 6.4 is very relevant here. You may be interested to check out this issue.

    Thread Starter Rick Beckman

    (@brazenlygeek)

    Went ahead and opened a ticket. Thanks!

    Thanks. I’m going to mark this one as resolved, but let me know if that was in error! Edit: you already did, nice!

    • This reply was modified 1 year, 3 months ago by Joen A..
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Possible to Filter FSE Blocks?’ is closed to new replies.