[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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 = array();
  31      if ( isset( $attributes['textAlign'] ) ) {
  32          $classes[] = 'has-text-align-' . $attributes['textAlign'];
  33      }
  34      if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
  35          $classes[] = 'has-link-color';
  36      }
  37  
  38      $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
  39  
  40      return sprintf(
  41          '<div %1$s><a href="%2$s" %3$s>%4$s</a></div>',
  42          $wrapper_attributes,
  43          esc_url( $edit_comment_link ),
  44          $link_atts,
  45          esc_html__( 'Edit' )
  46      );
  47  }
  48  
  49  /**
  50   * Registers the `core/comment-edit-link` block on the server.
  51   */
  52  function register_block_core_comment_edit_link() {
  53      register_block_type_from_metadata(
  54          __DIR__ . '/comment-edit-link',
  55          array(
  56              'render_callback' => 'render_block_core_comment_edit_link',
  57          )
  58      );
  59  }
  60  
  61  add_action( 'init', 'register_block_core_comment_edit_link' );


Generated : Fri Apr 19 08:20:01 2024 Cross-referenced by PHPXref