wp_get_current_commenter example


function render_block_core_comment_author_name( $attributes$content$block ) {
    if ( ! isset( $block->context['commentId'] ) ) {
        return '';
    }

    $comment            = get_comment( $block->context['commentId'] );
    $commenter          = wp_get_current_commenter();
    $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    if ( empty( $comment ) ) {
        return '';
    }

    $classes = array();
    if ( isset( $attributes['textAlign'] ) ) {
        $classes[] = 'has-text-align-' . $attributes['textAlign'];
    }
    if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
        $classes[] = 'has-link-color';
    }

function render_block_core_comment_content( $attributes$content$block ) {
    if ( ! isset( $block->context['commentId'] ) ) {
        return '';
    }

    $comment            = get_comment( $block->context['commentId'] );
    $commenter          = wp_get_current_commenter();
    $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    if ( empty( $comment ) ) {
        return '';
    }

    $args         = array();
    $comment_text = get_comment_text( $comment$args );
    if ( ! $comment_text ) {
        return '';
    }

    
if ( $comment && hash_equals( $_GET['moderation-hash']wp_hash( $comment->comment_date_gmt ) ) ) {
            // The comment will only be viewable by the comment author for 10 minutes.             $comment_preview_expires = strtotime( $comment->comment_date_gmt . '+10 minutes' );

            if ( time() < $comment_preview_expires ) {
                $commenter_email = $comment->comment_author_email;
            }
        }
    }

    if ( ! $commenter_email ) {
        $commenter       = wp_get_current_commenter();
        $commenter_email = $commenter['comment_author_email'];
    }

    return $commenter_email;
}

/** * Inserts a comment into the database. * * @since 2.0.0 * @since 4.4.0 Introduced the `$comment_meta` argument. * @since 5.5.0 Default value for `$comment_type` argument changed to `comment`. * * @global wpdb $wpdb WordPress database abstraction object. * * @param array $commentdata { * Array of arguments for inserting a new comment. * * @type string $comment_agent The HTTP user agent of the `$comment_author` when * the comment was submitted. Default empty. * @type int|string $comment_approved Whether the comment has been approved. Default 1. * @type string $comment_author The name of the author of the comment. Default empty. * @type string $comment_author_email The email address of the `$comment_author`. Default empty. * @type string $comment_author_IP The IP address of the `$comment_author`. Default empty. * @type string $comment_author_url The URL address of the `$comment_author`. Default empty. * @type string $comment_content The content of the comment. Default empty. * @type string $comment_date The date the comment was submitted. To set the date * manually, `$comment_date_gmt` must also be specified. * Default is the current time. * @type string $comment_date_gmt The date the comment was submitted in the GMT timezone. * Default is `$comment_date` in the site's GMT timezone. * @type int $comment_karma The karma of the comment. Default 0. * @type int $comment_parent ID of this comment's parent, if any. Default 0. * @type int $comment_post_ID ID of the post that relates to the comment, if any. * Default 0. * @type string $comment_type Comment type. Default 'comment'. * @type array $comment_meta Optional. Array of key/value pairs to be stored in commentmeta for the * new comment. * @type int $user_id ID of the user who submitted the comment. Default 0. * } * @return int|false The new comment's ID on success, false on failure. */

    public function filter_comment_text( $comment_text$comment ) {
        $commenter          = wp_get_current_commenter();
        $show_pending_links = ! empty( $commenter['comment_author'] );

        if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) {
            $comment_text = wp_kses( $comment_text, array() );
        }

        return $comment_text;
    }

    /** * Outputs a single comment. * * @since 3.6.0 * * @see wp_list_comments() * * @param WP_Comment $comment Comment to display. * @param int $depth Depth of the current comment. * @param array $args An array of arguments. */


    if ( empty( $file ) ) {
        $file = '/comments.php';
    }

    $req = get_option( 'require_name_email' );

    /* * Comment author information fetched from the comment cookies. */
    $commenter = wp_get_current_commenter();

    /* * The name of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */
    $comment_author = $commenter['comment_author'];

    /* * The email address of the current comment author escaped for use in attributes. * Escaped by sanitize_comment_cookies(). */
    
Home | Imprint | This part of the site doesn't use cookies.