Как получить пользователя из профиля автора Wordpress и отобразить контент как для вошедших, так и для вышедших из системы пользователей? - PullRequest
0 голосов
/ 25 марта 2019

Как мне изменить прикрепленный код, чтобы он брал пользователя с текущей страницы профиля Wordpress, отображал содержимое как для вошедших, так и для вышедших пользователей и получал все комментарии без ограничений?

Я попытался изменить is_user_logged_in () на! Is_user_logged_in () и изменить $ current_user-> ID на user-> ID, но это не сработало.

<?php

add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' );

function show_recent_comments_handler( $atts, $content = null )
{
    extract( shortcode_atts( array( 
        "count" => 10,
        "pretty_permalink" => 0
        ), $atts ));

    $output = ''; // this holds the output

    if ( is_user_logged_in() )
    {
        global $current_user;
        get_currentuserinfo();

        $args = array(
            'user_id' => $current_user->ID,
            'number' => $count, // how many comments to retrieve
            'status' => 'approve'
            );

        $comments = get_comments( $args );
        if ( $comments )
        {
            $output.= "<ul>\n";
            foreach ( $comments as $c )
            {
            $output.= '<li>';
            if ( $pretty_permalink ) // uses a lot more queries (not recommended)
                $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
            else
                $output.= '<a href="'.get_settings('siteurl').'/?p='.$c->comment_post_ID.'#comment-'.$c->comment_ID.'">';         
            $output.= $c->comment_content;
            $output.= '</a>';
            $output.= "</li>\n";
            }
            $output.= '</ul>';
        }
    }
    else
    {
        $output.= "<h2>You should be logged in to see your comments. Make sense?</h2>";
        $output.= '<h2><a href="'.get_settings('siteurl').'/wp-login.php?redirect_to='.get_permalink().'">Login Now &rarr;</a></h2>';
    }
    return $output;
}
?>

С упомянутыми моими изменениями япросто получить цикл текста: действие завершено, действие запущено и т. д.

Источник кода: Показать последние комментарии конкретного пользователя в WordPress

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...