[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/blocks/ -> comment-edit-link.php (source)

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/comment-edit-link` block.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Renders the `core/comment-edit-link` block on the server.
  10   *
  11   * @param array    $attributes Block attributes.
  12   * @param string   $content    Block default content.
  13   * @param WP_Block $block      Block instance.
  14   *
  15   * @return string Return the post comment's date.
  16   */
  17  function render_block_core_comment_edit_link( $attributes, $content, $block ) {
  18      if ( ! isset( $block->context['commentId'] ) || ! current_user_can( 'edit_comment', $block->context['commentId'] ) ) {
  19          return '';
  20      }
  21  
  22      $edit_comment_link = get_edit_comment_link( $block->context['commentId'] );
  23  
  24      $link_atts = '';
  25  
  26      if ( ! empty( $attributes['linkTarget'] ) ) {
  27          $link_atts .= sprintf( 'target="%s"', esc_attr( $attributes['linkTarget'] ) );
  28      }
  29  
  30      $classes = '';
  31      if ( isset( $attributes['textAlign'] ) ) {
  32          $classes .= 'has-text-align-' . $attributes['textAlign'];
  33      }
  34  
  35      $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
  36  
  37      return sprintf(
  38          '<div %1$s><a href="%2$s" %3$s>%4$s</a></div>',
  39          $wrapper_attributes,
  40          esc_url( $edit_comment_link ),
  41          $link_atts,
  42          esc_html__( 'Edit' )
  43      );
  44  }
  45  
  46  /**
  47   * Registers the `core/comment-edit-link` block on the server.
  48   */
  49  function register_block_core_comment_edit_link() {
  50      register_block_type_from_metadata(
  51          __DIR__ . '/comment-edit-link',
  52          array(
  53              'render_callback' => 'render_block_core_comment_edit_link',
  54          )
  55      );
  56  }
  57  
  58  add_action( 'init', 'register_block_core_comment_edit_link' );


Generated: Thu Jul 25 01:00:02 2024 Cross-referenced by PHPXref 0.7.1