Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Hej
    Hej is offline
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If statement for get_the_author (Wordpress)

    I want to allow only authors of which the own posts they have created to be able to reply to the comments posted on their posts.

    My plan on doing this is to edit the "Reply" link visible in each post by editing this file (wp-includes/comment-template.php).

    Here is the conditional tag of which I will use to edit the file:
    get_the_author

    This is the original look of the part I wish to edit:
    PHP Code:
    function comment_reply_link($args = array(), $comment null$post null) {
        echo 
    get_comment_reply_link($args$comment$post);

    PHP Code:
    function comment_reply_link($args = array(), $comment null$post null) {
        
    $author get_the_author();
        
        if(
    $author==1) {
            echo 
    get_comment_reply_link($args$comment$post);
        }

    So far it's not working. I would really appreciate some help.
    Last edited by Hej; 05-09-2013 at 04:24 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    You shouldn't modify the core files. If you do your changes can be wiped out on upgrade or they can break your WordPress install in ways that make it hard to debug. The easiest way to do this would be to alter your theme's comments.php file. This is the top of the twentytwelve comments.php file with an example of how it could work:

    PHP Code:
    <?php
    /**
     * The template for displaying Comments.
     *
     * The area of the page that contains both current comments
     * and the comment form. The actual display of comments is
     * handled by a callback to twentytwelve_comment() which is
     * located in the functions.php file.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */

    /*
     * If the current post is protected by a password and
     * the visitor has not yet entered the password we will
     * return early without loading the comments.
     */
    if ( post_password_required() )
        return;

    // == You should be able to do something like: ==
    $current_user wp_get_current_user();
    $current_post get_post();

    if( 
    $current_user->ID != $current_post->post_author )
        return;

    ?>
    Not tested; just an example.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •