WordPress.org

Ready to get started?Download WordPress

Forums

Comments Form Advanced Coding (php) (11 posts)

  1. Tech.Inno
    Member
    Posted 2 years ago #

    I'm trying to alter the comment form in my WordPress blog. My goal is to let only my phpBB users comment on the posts. I use the phpBB login system for my entire site. So here's my plan. I'm going to put an 'if statement' around the comment form in WordPress. Basically like this:

    At the top of the file:

    <php?
    //include phpBB stuff
    ?>

    Then around the comment form:

    If user->registered
    {
         Show comment form
    }
    else
    {
       Show message with link to login
    }

    Then I'm going to alter the variables sent to the database. I plan on hiding all but the comments box and then filling the other variables manually. Something like this:

    $comment_author = $user->data['username']
    $comment_author_email =$user->data['user_email']
    $comment_author_url = the url to the users porfile
    $comment_content = no change here

    But I'm running into an issue. What file is the comment form in? Is it even a php file? Before I waste time, does anyone think this is going to be possible?

    *Edit*
    Forgot to mention, I'm going to have it set so anyone can comment in the WordPress settings. I think that's the only way I'll be able to make this work.

  2. Tech.Inno
    Member
    Posted 2 years ago #

    It looks like this is going to be possible. Anyone with experience in php, please give me your opinion! This is an example of how to limit comments to only those who are members of your website. In this example I'm going to use phpBB members as they're integrated throughout my site. I haven't tested it yet, but this is what I've got so far.

    *Note* If you're going to test this, back up every file you before you touch it. Like I said, I don't know if it will work. I will test it and post the result later.

    This is the comment_form() function. From what I understand, it's called to display the comment form at the bottom of blog posts. It's located in wp-includes/comment-template.php on line 1509. Some changes will need to be made to it later.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    It looks like two files need to be changed in order to allow only the members of your site to comment. These two files are as follows:

    1. wp-content/themes/ {Your Theme Name Here} /comments.php
    2. wp-includes/comment-template.php

    First things first, add the following to the top of comments.php. This is for phpBB users. If you use your own login system, include the proper files instead.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    It will need to be changed to this:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Next up is comment-template.php. I don't think it's necessary, but go ahead and include the php for session management at the top of this file too. Then make the following changes to comment_form() (line 1509).

    Find:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Replace with:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    These changes insert your users info into form. It also makes them hidden so changes cannot be made. If you want them to make changes, change type="hidden" to type="text". Also, a link is displayed in the value of the url field. This is a link to the users profile. You may need to change it depending on the location of profiles.

    But, I've no idea if this will work. Just ideas. If anyone has experience with this, please comment on my idea! I would love the input/advice!

    References for information:
    http://codex.wordpress.org/Function_Reference/comment_form
    http://devpress.com/blog/using-the-wordpress-comment-form/

  3. Tech.Inno
    Member
    Posted 2 years ago #

    Errors found so far:

    Error 1:
    Fatal error: Cannot redeclare make_clickable()
    Fix:
    http://www.phpbb.com/community/viewtopic.php?f=46&t=2100992

    Error 2:
    Fatal error: Call to a member function sql_query() on a non-object in cache.php
    Fix:
    http://www.phpbb.com/community/viewtopic.php?f=71&t=1016345

  4. Tech.Inno
    Member
    Posted 2 years ago #

    Okay, got it all working. Only minor changes to what I had above. There are probably better and more secure ways of doing this, but I don't know enough to implement them. Anyway, onto the changes!

    In file common.php

    Place this at the top of the page:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Then find:
    <?php comment_form(); ?>

    Replace with:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    Then in comment-template.php

    Find:
    [Code moderated as per the Forum Rules. Please use the pastebin]

    That's it. Now only users logged into your site can comment. This example assumes you use phpBB to handle your members, but only minor changes would need to be made if you use your own member system. I will be making some small changes after a few tests. I'm going to make the name, email, and url items hidden. Very simple to do. Then only the comments box will show.

  5. chadrew
    Member
    Posted 2 years ago #

    Very interesting, I was just looking for a way to make forum users able to comment on WordPress posts, without messing with duplicate databases and bridge plugins. Does this work by checking for PHPBB cookie?

    I'll definitely be trying this :)

  6. Tech.Inno
    Member
    Posted 2 years ago #

    Yes, it checks user->data to see if the user is registered/logged in. Here's a significant change I've made.

    *EDIT*
    I had some significant changes, however, a moderator decided to delete them...
    Changes are as follows:
    -Makes the input boxes hidden so users can't edit data
    -Displays a message to logged in users (just like WP does)

    If you want these simple changes, email me at tech.inno@ymail.com.

  7. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Do NOT edit core WordPress files!

  8. Tech.Inno
    Member
    Posted 2 years ago #

    Actually, this doesn't hurt a thing. WP overrides it when a WP user is logged in. So if you're logged into WordPress, it all works as normal. Really, editing is fine. Just BACKUP ANY FILE BEFORE YOU TOUCH IT. This is a "Hack" forum after all.

  9. Tech.Inno
    Member
    Posted 2 years ago #

    May I ask why all of my code has been removed? Most of it was less than 10 lines.

  10. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    I checked. They were all over 10 lines.

  11. Tech.Inno
    Member
    Posted 2 years ago #

    Well, now 6 days after I posted this hack, all the code has been removed. I'm not going back to edit every post. If you want this code, check in the official phpBB forum @ http://www.phpbb.com/community/. Because this hack was designed to integrate phpBB and WP, it will be posted there soon. Sorry to all those who checked here. Alternatively you can email me at tech.inno@ymail.com.

Topic Closed

This topic has been closed to new replies.

About this Topic