Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to create a read-only logged-in user?


  • demonboy
    Participant

    @demonboy

    I have a private intranet where only logged-in users can see and interact in the pages. However I need to create a ‘demo’ account which is read-only. Currently if I try this and create a profile with just ‘read’ status (like ‘subscriber’), they can still write and comment on various posts and pages. I assume this is because being a logged-in user automatically gives you certain capabilities above and beyond what I can see.

    I have User Role Editor installed and have tried to set the demo user to ‘subscriber’ with just ‘read’ status, but this doesn’t work. Something is over-riding this. There are certain capabilities that are greyed out, like delete_posts etc.

    Any clues?

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

  • Henry Wright
    Moderator

    @henrywright

    I think writing abilities become available only once a user has verified their email address. So a registered but unverified user sounds kind of like what you need. They get a profile page and can browse the site but can’t write.


    demonboy
    Participant

    @demonboy

    We don’t have a verification procedure on our website (it’s private) so I don’t think this would apply. If you think this is relevant and that I should put some kind of verification procedure in place in order to get this working, please let me know.


    Henry Wright
    Moderator

    @henrywright

    If your site is private then you don’t need a verification procedure. But my point was you should look at the verification procedure because the functionality is very close to what you’re trying to achieve.


    modemlooper
    Moderator

    @modemlooper

    function bp_keep_user_private( $user_login, $user ) {
    
    	global $wpdb;
    
    	if( 'username' === $user->user_login ) {
    
    		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user->ID ) );
    	}
    
    }
    add_action( 'wp_login', 'bp_keep_user_private', 10, 2 );

    you can try something like this that will set that account to inactive on every login. change username to the real username


    demonboy
    Participant

    @demonboy

    OK, this is getting close, I like it. Thank you@modemlooper, and apologies to @Henry for misunderstanding.

    Some features are disabled, which is great, but a read-only account can still comment, add files to the file repository (Multiverso plugin), add a calendar event, upload photos to the photo album and edit (but not create) wiki articles.

    Any clues there?


    Henry Wright
    Moderator

    @henrywright

    …but a read-only account can still comment, add files to the file repository (Multiverso plugin), add a calendar event, upload photos to the photo album and edit (but not create) wiki articles.

    You may need to add custom validation in each of these cases. There should be hooks available at the relevant points which you can attach your custom functions to.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to create a read-only logged-in user?’ is closed to new replies.
Skip to toolbar