Recent comments

To prevent comments from protected pages from appearing in “Recent comments” widget, open up “/wp-includes/widgets.php” and replace the function “wordpress_wp_widget_recent_comments” with this code:

function wordpress_wp_widget_recent_comments($args) {
global $wpdb, $comments, $comment, $current_user;
extract($args, EXTR_SKIP);
$options = get_option(’widget_recent_comments’);
$title = empty($options['title']) ? __(’Recent Comments’) : apply_filters(’widget_title’, $options['title']);
if ( !$number = (int) $options['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;

if ( !$comments = wordpress_wp_cache_get( ‘recent_comments’, ‘widget’ ) ) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = ‘1′ AND comment_post_ID NOT IN (SELECT post_id FROM " . $wpdb->prefix . "named_users WHERE (user_id <> " . $current_user->ID . " OR group_id NOT IN (SELECT group_id FROM " . $wpdb->prefix . "named_users_groups_relations WHERE user_id = " . $current_user->ID . "))) ORDER BY comment_date_gmt DESC LIMIT $number");
wordpress_wp_cache_add( ‘recent_comments’, $comments, ‘widget’ );
}
?>

<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<ul id="recentcomments"><?php
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo<li class="recentcomments">. sprintf(__(%1$s on %2$s), get_comment_author_link(),<a href="’. get_comment_link($comment->comment_ID) . ‘">. get_the_title($comment->comment_post_ID) .</a>) .</li>;
endforeach; endif;?></ul>
<?php echo $after_widget; ?>
<?php
}
This entry was posted in wpNamedUsers. Bookmark the permalink.

29 Responses to Recent comments

  1. luis says:

    hey, fantastic, i put in my blog and now it’s ok, thank you its a great plugin… you are a genius.

  2. skipr says:

    Great plugin, but one issue: if I protect one page with content “bla bla” and then search for “bla bla” with unprivileged user, the content (also article’s title and id) is revealed as part of search result. Any ideas how to avoid that leak?

    Thank you,
    skipr

    • Andrias Sundskarð says:

      I will try to fix it as soon as possible.

      • Andrias Sundskarð says:

        Are you sure that this error exists? I have a protected page on this site with the title “Protected page” and contents “This is a protected page.”. Try searching for it!

  3. Gobi says:

    Hi,
    This is a great plugin, thank you !

    I just want to allow user accounts with “Editor” privileges to manage access / rights to Posts / Pages with your plugin because only “Admin” can access the rights management panel. Where is the rights filter ?

    Thanx,

  4. Danny says:

    GROUPS allows me to create new groups and assign users to that group, thats cool BUT i need groups to also show the pre-existing ROLES and give people designated a certain ROLE access as if say Editor, Subscriber, GOLD member, Silver Member, etc (some of my ROLES) were groups can you either add it or tell me what code to change to read from the current list of roles instead of the GROUPS list used by this addon?

    i currently have several ROLES assigned to users depending usually on their membership status, these include
    Administrator | Editor | Subscriber | Bronze Member | Silver Member | Gold Member

    so i really need these ROLES to show up as groups or something like that last thing i want to do is have 2 download a new (membership creation via paypal plugin) that is specifically designed to be compatible with the creation of GROUPS used in this plugin, please tell me what code variables to change or add it to the code, this is the closest plugin ive found for some of the things im trying to do ( mostly displaying / not displaying specific content on pages and specific menus on the menu bar depending on user ROLE level ) please reply also to email if possible thanks…

  5. I have installed the plugin and it looks to be a great plugin. Will help me a lot. The only thing is that I cant see any sign in box. Is this pugin supposed to work in conjunction with another plugin? In my Members pages in the link in the side bar. The only page that appears on the page tabs accross the top is the one page that I have cleared permisions for and want as a public page. The rest I have set up for members. I have aded one user and group but there is nowhere for him to sign in. I’m probably just missing wher to find a setting or something. I have posted relentlesly in forums, searched forums, searched google, and can find no help. Would appreciate anything you could do.

  6. fanta78 says:

    Great extension, it’s a must to use, very professional. I’m setting up a professional WordPress site, and this is exactly the services I was looking for. One (little) complain : the un-installation of the extension need a manual drop of the database tables. On the occasion, a nice link to do it for the admin should be nice ;-)
    Thanks,
    fanta78

  7. Hi, your plugin looks great! Wouldn’t it be better though to override the recent comments widget in functions.php than editing widgets.php? Such as detailed here: http://www.yoursiteisvalid.com/validnews/override-wordpress-default-widgets-307.html

    I haven’t tried it with that specific widget though, so I can’t say if it should work or not. It just seems more sensible as it wouldn’t break with a WordPress upgrade.

  8. Jou says:

    Hi

    How you can set right’s so that nobody else than adminstrator can see and change settings?

  9. Viagra says:

    I think the idea is good but you need to modify it a little.

  10. blogindir says:

    Great plugin, but one issue: if I protect one page with content “bla bla” and then search for “bla bla” with unprivileged user, the content (also article’s title and id) is revealed as part of search result. Any ideas how to avoid that leak?

    Thank you,

  11. fanta78 says:

    Hi Andrias,
    Is there a (simple) way to add automaticaly any new user into one of the wpnamedusers’s group ?

    I have already a great number of pages assigned to permissions through one group.

    Each time a new user goes through the subscribtion process, I wish to have his account automaticaly put in this group, as he is set up direclty into the default WP “Contributor” role.

    Thanks

  12. madbadcat says:

    i want to show a list of posts for the logged in user

    i would guess it some combination of this but….

    is_user_logged_in() )

    $wpNamedUsers_posts

  13. madbadcat says:

    BTW- this is the most perfect project asset manger plugin out there. it is perfect to use to share files with clients, etc… thank you.

  14. Jean Sudarovich says:

    I upgrated WordPress to Version 3.0. I looked for wordpress_wp_widget_recent_comments function and I was unable to find it. Have you a solution to prevent comments of non authorized visitors if i set the Recent Comment widget ?

  15. Bjarke says:

    Hello! I have used and set up your plugin on my test site and it works perfectly, but when i wanted to move it to the live site i copied the plugin via ftp – and forgot to disable it first. Now it doesnt work on the livesite. The “settings” page is empty, and when I activate the plugin i get “The plugin generated 3227 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.”.

    I guess this is because I copied the plugin while it was activated, but where would I look for those 3227 characters that are left from my test server activation? I need this to work on my livesite.

    Thank you!

    • Andrias Sundskarð says:

      I have never seen that error message before, and I don’t think that my plugin generates it. Please check if you have other plugins, that might generate it.

      • Bjarke says:

        I went into my phpMyAdmin and deleted the tables for
        named_users
        named_users_groups
        named_users_groups_relations
        and now it doesn’t say that thing about the 3227 unexpected characters. However the wpNamedUsers Permissions page is still blank and the pages i protect with the plugin gets a 404 not found error.
        I am sure it is because i copied the active plugin via ftp so I created a faluty SQL database … but does your plugin use other tables than these three:
        named_users
        named_users_groups
        named_users_groups_relations

        • Andrias Sundskarð says:

          The plugin uses only those three tables. I’ve just read something about this issue in WP 3. I will do some testing to see if I can reproduce the error.

          • Andrias Sundskarð says:

            I’ve just deactivated the plugin, dropped tables in DB, and reactivated the plugin, but I get no errors.

          • Bjarke says:

            Is it possible for you to add me on msn? If you have time

  16. Bjarke says:

    I dont get any errors when I activate the plugin. I just have a blank settings page and 404 errors on pages using the plugin to restrict control :-(

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>