• 3dpc

    (@3dpc)


    Hello guys,

    I want to modify my WordPress site to allow only authors to reply to comments posted in the post they have written. The way I plan on doing this is to edit this file and function: wp-includes/comment-template.php

    function comment_reply_link($args = array(), $comment = null, $post = null) {
    		echo get_comment_reply_link($args, $comment, $post);
    }

    This is what I’ve managed to edit so far:

    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);
    	}
    }

    At the moment it’s not really working but I think I’m on the right way, right? I’d really appreciate if someone could give me a hand with this.

    Thanks,
    John

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Please don’t edit core files. Remove your changes (or upload a fresh copy of wp-includes/comment-template.php) and try it with this in your theme’s functions.php file:

    add_filter( 'comment_reply_link', 'author_comment_reply', 10, 4 );
    function author_comment_reply( $link, $args, $comment, $post ) {
    	if ( isset( $post->post_author ) && $post->post_author ) {
    		$user_ID = get_current_user_id();
    		if ( $user_ID == $post->post_author ) {
    			return $link;
    		}
    	}
    	return '';
    }

    Thread Starter 3dpc

    (@3dpc)

    Alright, thanks that works. Is it any danger to changing the core files just to change words to suit my site better? Like instead of having “Post Comment” I use “Post Review”.

    Or should I always no matter what avoid changing the core files?

    Thread Starter 3dpc

    (@3dpc)

    When googling for different ways to achieve things it seems the majority seems to be changing the core files. Are they just too ignorant or is it not that big of a harm when just changing small things, like the example above?

    Moderator keesiemeijer

    (@keesiemeijer)

    Or should I always no matter what avoid changing the core files?

    Yes. You can break WordPress or introduce security vulnerabilities if you do. Also when you update WordPress all your edits are lost. Never ever edit core files. Most of the time there are alternative methods like editing your theme (create a child theme first, if you do) or by using filters as in the code above.

    Is the “Post Content” string a part of your theme (front end)?

    Thread Starter 3dpc

    (@3dpc)

    Alright. Then I’ll probably try stick to changing only the functions.php file. If you are referring to “Post Comment”, no, I think it’s a part of the WordPress core.

    I managed to change it though using something I found.

    function comment_reform ($arg) {
    $arg['label_submit'] = __('Post Review');
    $arg['title_reply'] = __('Submit a Review:');
    return $arg;
    }
    add_filter('comment_form_defaults','comment_reform');

    Works like a charm.

    Thanks for your help!

    Moderator keesiemeijer

    (@keesiemeijer)

    Ah yes, I meant “Post Comment”. I’m glad you’ve got it resolved.

    Thread Starter 3dpc

    (@3dpc)

    I’ve got one (probably last) change with the comments section I need done.

    Whenever at least one comment is posted on a post page “COMMENTS” shows up as a title. This is how the source code looks:
    <div class=”total-comments”>Comments</div>

    And here’s an image showing what part of the site I wish to edit.
    http://i.imgur.com/Hma23fW.jpg

    I’ve tried looking in comment-template.php to see what things I’ve got to use in the code in my most previous post in order to change it, but I can’t find anything. Any ideas?

    Moderator keesiemeijer

    (@keesiemeijer)

    What theme are are you using?

    Thread Starter 3dpc

    (@3dpc)

    Moderator keesiemeijer

    (@keesiemeijer)

    I’m sorry but this theme is behind a log in so I don’t have access to the files. Maybe you can ask for support at the themeshop.

    Or do a Search on all your theme files for ‘Comments’ and see where it’s located.

    Thread Starter 3dpc

    (@3dpc)

    Found the code to edit, thanks.

    New question. How do I change the Website label in the comment form using this function?:

    function comment_reform ($arg) {
    $arg['label_submit'] = __('Post Review');
    $arg['title_reply'] = __('Submit a Review:');
    return $arg;
    }
    add_filter('comment_form_defaults','comment_reform');

    I’ve looked here but I don’t get it:
    http://codex.ww.wp.xz.cn/Function_Reference/comment_form

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘if statement for get_the_author’ is closed to new replies.