get_comment example



/** * Retrieves the edit comment link. * * @since 2.3.0 * * @param int|WP_Comment $comment_id Optional. Comment ID or WP_Comment object. * @return string|void The edit comment link URL for the given comment. */
function get_edit_comment_link( $comment_id = 0 ) {
    $comment = get_comment( $comment_id );

    if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
        return;
    }

    $location = admin_url( 'comment.php?action=editcomment&c=' ) . $comment->comment_ID;

    /** * Filters the comment edit link. * * @since 2.3.0 * * @param string $location The edit link. */


/** * Returns a WP_Comment object based on comment ID. * * @since 2.0.0 * * @param int $id ID of comment to retrieve. * @return WP_Comment|false Comment if found. False on failure. */
function get_comment_to_edit( $id ) {
    $comment = get_comment( $id );
    if ( ! $comment ) {
        return false;
    }

    $comment->comment_ID      = (int) $comment->comment_ID;
    $comment->comment_post_ID = (int) $comment->comment_post_ID;

    $comment->comment_content = format_to_edit( $comment->comment_content );
    /** * Filters the comment content before editing. * * @since 2.0.0 * * @param string $comment_content Comment content. */

function get_comment_author( $comment_id = 0 ) {
    $comment = get_comment( $comment_id );

    $comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_id;

    if ( empty( $comment->comment_author ) ) {
        $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
        if ( $user ) {
            $comment_author = $user->display_name;
        } else {
            $comment_author = __( 'Anonymous' );
        }
    } else {
        

function get_commentdata( $comment_id$no_cache = 0, $include_unapproved = false ) {
    _deprecated_function( __FUNCTION__, '2.7.0', 'get_comment()' );
    return get_comment($comment_id, ARRAY_A);
}

/** * Retrieve the category name by the category ID. * * @since 0.71 * @deprecated 2.8.0 Use get_cat_name() * @see get_cat_name() * * @param int $cat_id Category ID * @return string category name */
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
            $label = '';
            if ( '_blank' === $attributes['linkTarget'] ) {
                // translators: %s is the Author name.                 $label = 'aria-label="' . sprintf( esc_attr__( '(%s author archive, opens in a new tab)' )$author_name ) . '"';
            }
            // translators: %1$s: Author archive link. %2$s: Link target. %3$s Aria label. %4$s Avatar image.             $avatar_block = sprintf( '<a href="%1$s" target="%2$s" %3$s class="wp-block-avatar__link">%4$s</a>', esc_url( get_author_posts_url( $author_id ) )esc_attr( $attributes['linkTarget'] )$label$avatar_block );
        }
        return sprintf( '<div %1s>%2s</div>', $wrapper_attributes$avatar_block );
    }
    $comment = get_comment( $block->context['commentId'] );
    if ( ! $comment ) {
        return '';
    }
    /* translators: %s is the Comment Author name */
    $alt          = sprintf( __( '%s Avatar' )$comment->comment_author );
    $avatar_block = get_avatar(
        $comment,
        $size,
        '',
        $alt,
        array(
            

    function wp_notify_postauthor( $comment_id$deprecated = null ) {
        if ( null !== $deprecated ) {
            _deprecated_argument( __FUNCTION__, '3.8.0' );
        }

        $comment = get_comment( $comment_id );
        if ( empty( $comment ) || empty( $comment->comment_post_ID ) ) {
            return false;
        }

        $post   = get_post( $comment->comment_post_ID );
        $author = get_userdata( $post->post_author );

        // Who to notify? By default, just the post author, but others can be added.         $emails = array();
        if ( $author ) {
            $emails[] = $author->user_email;
        }


/** * Retrieves the feed GUID for the current comment. * * @since 2.5.0 * * @param int|WP_Comment $comment_id Optional comment object or ID. Defaults to global comment object. * @return string|false GUID for comment on success, false on failure. */
function get_comment_guid( $comment_id = null ) {
    $comment = get_comment( $comment_id );

    if ( ! is_object( $comment ) ) {
        return false;
    }

    return get_the_guid( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
}

/** * Displays the link to the comments. * * @since 1.5.0 * @since 4.4.0 Introduced the `$comment` argument. * * @param int|WP_Comment $comment Optional. Comment object or ID. Defaults to global comment object. */
$error = new WP_Error(
            'rest_comment_invalid_id',
            __( 'Invalid comment ID.' ),
            array( 'status' => 404 )
        );

        if ( (int) $id <= 0 ) {
            return $error;
        }

        $id      = (int) $id;
        $comment = get_comment( $id );
        if ( empty( $comment ) ) {
            return $error;
        }

        if ( ! empty( $comment->comment_post_ID ) ) {
            $post = get_post( (int) $comment->comment_post_ID );

            if ( empty( $post ) ) {
                return new WP_Error(
                    'rest_post_invalid_id',
                    __( 'Invalid post ID.' ),
                    

    }

    $comments_to_delete = $wpdb->get_results( $wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < %d", $delete_timestamp ), ARRAY_A );

    foreach ( (array) $comments_to_delete as $comment ) {
        $comment_id = (int) $comment['comment_id'];
        if ( ! $comment_id ) {
            continue;
        }

        $del_comment = get_comment( $comment_id );

        if ( ! $del_comment || 'trash' !== $del_comment->comment_approved ) {
            delete_comment_meta( $comment_id, '_wp_trash_meta_time' );
            delete_comment_meta( $comment_id, '_wp_trash_meta_status' );
        } else {
            wp_delete_comment( $del_comment );
        }
    }
}

/** * Retrieves metadata from a file. * * Searches for metadata in the first 8 KB of a file, such as a plugin or theme. * Each piece of metadata must be on its own line. Fields can not span multiple * lines, the value will get cut at the end of the first line. * * If the file data is not within that first 8 KB, then the author should correct * their plugin file and move the data headers to the top. * * @link https://codex.wordpress.org/File_Header * * @since 2.9.0 * * @param string $file Absolute path to the file. * @param array $default_headers List of headers, in the format `array( 'HeaderKey' => 'Header Name' )`. * @param string $context Optional. If specified adds filter hook {@see 'extra_$context_headers'}. * Default empty string. * @return string[] Array of file header values keyed by header name. */
_doing_it_wrong(
                    __FUNCTION__,
                    sprintf( $message, '<code>' . $cap . '</code>' ),
                    '6.1.0'
                );

                $caps[] = 'do_not_allow';
                break;
            }

            $comment = get_comment( $args[0] );
            if ( ! $comment ) {
                $caps[] = 'do_not_allow';
                break;
            }

            $post = get_post( $comment->comment_post_ID );

            /* * If the post doesn't exist, we have an orphaned comment. * Fall back to the edit_posts capability, instead. */
            
$edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
    }

    $tab_index_attribute = '';
    if ( (int) $tab_index > 0 ) {
        $tab_index_attribute = " tabindex=\"$tab_index\"";
    }

    // @todo Remove this?     // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
    $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
    $jj        = ( $edit ) ? mysql2date( 'd', $post_date, false ) : current_time( 'd' );
    $mm        = ( $edit ) ? mysql2date( 'm', $post_date, false ) : current_time( 'm' );
    $aa        = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : current_time( 'Y' );
    $hh        = ( $edit ) ? mysql2date( 'H', $post_date, false ) : current_time( 'H' );
    $mn        = ( $edit ) ? mysql2date( 'i', $post_date, false ) : current_time( 'i' );
    $ss        = ( $edit ) ? mysql2date( 's', $post_date, false ) : current_time( 's' );

    $cur_jj = current_time( 'd' );
    $cur_mm = current_time( 'm' );
    $cur_aa = current_time( 'Y' );
    $cur_hh = current_time( 'H' );
    


        if ( $deleted > 0 ) {
            $messages[] = sprintf(
                /* translators: %s: Number of comments. */
                _n( '%s comment permanently deleted.', '%s comments permanently deleted.', $deleted ),
                $deleted
            );
        }

        if ( $same > 0 ) {
            $comment = get_comment( $same );
            if ( $comment ) {
                switch ( $comment->comment_approved ) {
                    case '1':
                        $messages[] = __( 'This comment is already approved.' ) . sprintf(
                            ' <a href="%1$s">%2$s</a>',
                            esc_url( admin_url( "comment.php?action=editcomment&c=$same) ),
                            __( 'Edit comment' )
                        );
                        break;
                    case 'trash':
                        $messages[] = __( 'This comment is already in the Trash.' ) . sprintf(
                            
if ( 'ids' === $this->query_vars['fields'] ) {
            $this->comments = $comment_ids;
            return $this->comments;
        }

        _prime_comment_caches( $comment_ids, false );

        // Fetch full comment objects from the primed cache.         $_comments = array();
        foreach ( $comment_ids as $comment_id ) {
            $_comment = get_comment( $comment_id );
            if ( $_comment ) {
                $_comments[] = $_comment;
            }
        }

        // Prime comment post caches.         if ( $this->query_vars['update_comment_post_cache'] ) {
            $comment_post_ids = array();
            foreach ( $_comments as $_comment ) {
                $comment_post_ids[] = $_comment->comment_post_ID;
            }

            

function get_page_of_comment( $comment_id$args = array() ) {
    global $wpdb;

    $page = null;

    $comment = get_comment( $comment_id );
    if ( ! $comment ) {
        return;
    }

    $defaults      = array(
        'type'      => 'all',
        'page'      => '',
        'per_page'  => '',
        'max_depth' => '',
    );
    $args          = wp_parse_args( $args$defaults );
    
case 'term':
            $term = get_term( $object_id );
            if ( ! $term instanceof WP_Term ) {
                break;
            }

            $object_subtype = $term->taxonomy;
            break;

        case 'comment':
            $comment = get_comment( $object_id );
            if ( ! $comment ) {
                break;
            }

            $object_subtype = 'comment';
            break;

        case 'user':
            $user = get_user_by( 'id', $object_id );
            if ( ! $user ) {
                break;
            }
Home | Imprint | This part of the site doesn't use cookies.