0

Please let me first try to explain what I want to accomplish:

I am building a wordpress website for a small, local, but public swimming pool. The pool is only open when the weather is 'fine'. The lifeguard decides in the morning whether the pool will be open or not. This information should be easily maintained and be visible on the website.

I created a widget that displays whether the pool is open or not. The widget recieves the data from a custom table in de wordpress database. The background of the widget will be green when open, red when closed and orange if the lifeguard has not made a decission yet.

So far no problem. For the lifeguard I made an useraccount to login. The only thing he should be able to set/modify, is whether the pool is open today. He should not be allowed to edit/publish pages/posts or see anything else on the dashboard.

So my thoughts are to make the lifeguard a 'subscriber'. But now I am struggling how he can access an settingspage for the 'open or not option'. And where to make this settingspage?

First idea: Make it availaible in backend, but how can I assure it's available for a subcriber?

Second idea: Make it availaible in the frontend. But then, how can I do this?

Has anyone done such a thing? Can anyone point me to a solution for this?

Thanks! Luc

Luc
  • 95
  • 1
  • 7

3 Answers3

1

To make things as clean as possible, I'd register a new custom lifeguard role and an open_pool capability that gets assigned to that role. You would give all your lifeguards the lifeguard role.

You could then add a dialog to either the front or back end using:

if (current_user_can ( 'open_pool' ) {
   print $pool_open_close_form;
}

To get you started, take a look at this WPSE thread and the Roles and Capabilities section of the Codex.

Community
  • 1
  • 1
cpilko
  • 11,792
  • 2
  • 31
  • 45
  • Thanks, great suggestion. I was not aware that it's also possible to create new capabilities. Will use this also. – Luc Jun 03 '14 at 21:41
0

Instead of basing this off a subscription, you could base if off a single log in using wp_get_current_user();

For example, in your functions.php file you could place the following.

$current_user = wp_get_current_user();
if($current_user->user_login == 'User1') {

    function example_add_dashboard_widgets() {

    wp_add_dashboard_widget(
            'example_dashboard_widget',         // Widget slug.
            'Example Dashboard Widget',         // Title.
            'example_dashboard_widget_function' // Display function.
        );  
    }
    add_action( 'wp_dashboard_setup', 'example_add_dashboard_widgets' );

    function example_dashboard_widget_function() {

        // Display whatever it is you want to show.
        echo "Hello World, I'm a great Dashboard Widget";
    } 
}

This would check the username matches 'User1', then would add a dashboard widget, meaning it would be the first thing the lifeguard sees when they log in. Of course this does mean potentially having a shared log if there are multiple lifeguards.

Sources:

http://codex.wordpress.org/Function_Reference/wp_get_current_user http://codex.wordpress.org/Dashboard_Widgets_API

terrorfall
  • 1,121
  • 3
  • 16
  • 33
  • Good suggestion. Since there are no advanced settings, it's a great idea to set this trough a dashboard widget. I will dig further into this in combination with custom user role and capabilities as mentioned by 'cpilko' in other reply. – Luc Jun 03 '14 at 21:45
0

You could use a plugin like Adminimize (https://wordpress.org/plugins/adminimize/) to only display the lifeguard some menu function to change the status for the pool and remove all other posts/pages related menu items.

Tate83
  • 274
  • 1
  • 7
  • 21