• Resolved nick2395

    (@nick2395)


    Peter,

    On my school project, i have a db table with some projects. The projects in this list, can be viewed by al users (admin, subscriber etc.). Is it possible to only let admin and author users edit the projects in the table, so that subscribers can only view the table?

    I hope you can help me out.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Nick,

    Yes, that is possible. You can even make all your school project users subscribers to give them the lowest possible privileges in your dashboard and allow them to edit their profile only.

    Suppose you have three user groups:
    (1) admin
    (2) teacher
    (3) student

    This admin user is responsible for school management administration. This is NOT your WordPress admin! Presume we would give these users the following roles:
    (1) admin – subscriber + app_admin
    (2) teacher – subscriber + app_teacher
    (3) student – subscriber + app_student

    If you add these roles to your project pages and make sure the right users are having the right roles, users will be able to only see your app and their profile in the dashboard. There is no need to give any app user admin privileges.

    You just need a WP role management tool to give users multiple roles. You can use another plugin to do that or use the build-in role manager.

    Does this help? Is there anything missing?

    Best regards,
    Peter

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Nick,

    You might want to have a look at this video:
    https://wpdataaccess.com/docs/documentation/data-projects/advanced-lookups/

    Have a nice weekend,
    Peter

    Thread Starter nick2395

    (@nick2395)

    Hi Peter,

    Thanks for your answers. Let me explain my school project a bit further, because i think we don’t speak of the same ‘projects’. I have to make a project management system for. So i created a db table with the following table rows: Project id, project number, project name, customer name, coach, student 1, student 2, student 3, initiation leader. In my db, it looks like this:

    https://webnv.nl/testwebsite/project-overzicht-2/

    I have created a page of this table on the front end of my website, using your plugin. Edit is enebled, but i don’t want students to be able to edit or add another row to this table. Is that possible? So only users with the coach role can edit or add a row in this table. I hope you understand my question a bit better now.

    Thanks in advance

    • This reply was modified 4 years, 9 months ago by nick2395. Reason: Edited table
    • This reply was modified 4 years, 9 months ago by nick2395.
    • This reply was modified 4 years, 9 months ago by nick2395.
    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Nick,

    That is possible, but you cannot cover this functionality on one page. First you need to create two user groups: coaches and students. You then need to create two Data Project pages, one for each group. Finally, you need to add the shortcode for the coaches page to a page available for coaches only, and a shortcode for students to a student page.

    Does that make sense?

    Best regards,
    Peter

    Thread Starter nick2395

    (@nick2395)

    Hi Peter,

    Thank you for your reply. That makes a lot of sense. That was my initial solution in fact, but my coach wanted me to make 1 page out of the 2 pages, using the ‘if_user_can’ wp function. That is how i managed to make 1 page out of 2. First, i created a new capability for the student role and named it: ‘is_student’. Than i created a template wordpress page with html and php. I pasted the ‘if_user_can’ function in the template page and added the ‘do_shortcode’ function. I added the shortcode for the non-student in the else statement, and the student shortcode in the if ((if_user_can) ‘is_student’) statement. When wordpress now loads the page, it will either show the student or non-student crud, depending on the capability ‘is_student’ of the user that is currently logged in. (example below).

    <?php if( current_user_can('edit_project')) :
                         echo do_shortcode('[wpdadiehard project_id="1" page_id="1"]');
                    elseif( current_user_can('is_student')) :
                        echo do_shortcode('[wpdadiehard project_id="1" page_id="8"]');
                    else :
                        wp_die("<h2>Je moet ingelogd zijn om deze pagina te mogen bekijken!</h2>");
                    endif;
                    ?>

    I hope this solution will help others in the future. Thanks again for your kindness and your help. Always a pleasure!

    Kind regards, Nick

    • This reply was modified 4 years, 9 months ago by nick2395. Reason: pasted code inside post
    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Great Nick! ??

    Thank you very much for sharing your solution,
    Peter

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP data acces edit table only with specific capability or role’ is closed to new replies.