1. Home
  2. Docs
  3. Index
  4. Data Projects
  5. User roles and WHERE clauses

User roles and WHERE clauses

A Data Project consists of one or more data administration and/or static pages. Use the role attribute to define which users should have access to a page. Use the $$USER$$ or $$USERID$$ environment variables to get access to the current user. $$USER$$ is related to database column wp_user.user_login. $$USERID$$ is related to database column wp_user.user_id.

In a student administration system for example, you might need a page to inform students about their personal results. Suppose student results are stored in table STUDENT_RESULTS which has a column STUDENT_NAME that holds the WordPress username of the student (or STUDENT_ID that holds the WordPress userid of the student).

You can restrict the information shown as follows:

  1. Give students a WordPress role (subscriber for example)
  2. Add the following WHERE clause to the student result page: STUDENT_NAME = $$USER$$ (or STUDENT_ID = $$USERID$$)

Students will see their own results only. If you have users who need to see all results, you might need a second student result page available to their role.

 

NOTES

  • You can set the default value of a table column to the WordPress username using the $$USER$$ environment variable:
    Data Projects > Manage Table Options > select your table > set “Default value” to $$USER$$
  • If you set the WHERE clause to “your_column_name=$$USER$$” and the default value for your_column_name to $$USER$$, users will be able to see and edit their personal data only.
  • If you use the $$USERID$$ environment variable, make sure your column is numeric.

 

Demonstration Video

Was this article helpful to you? Yes No 1

2 Replies to “User roles and WHERE clauses

  1. I’ve spent many hours trying to make this work with mostly frustration to show. The directions above were confusing. The term “WordPress username” appears ambiguous. If I use column user_login in wp_users, adding a record does produce the desired user_login value in the data entry form. However, if I include the WHERE clause in my project page, I get no records.

  2. Hi Ben,

    I added a short video that shows the steps needed to get your where clause to work with the $$USER$$ environment variable. I hope this helps. Let me know if you need more assistance.

    Best regards,
    Peter

Leave a Reply to Peter Schulz Cancel reply

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