Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Set User Role based on age result from Facebook Log-In – WordPress

This assumes that what you said about only needing to check for the minimum value is true. These conditional statements work for this array.

Facebook’s Min Age Array will be either 13, 18 or 21.

$age_range = array( 13, 18, 21); // I don't know what actual data you have here.

if( min( $age_range ) == 13 ) {
    $age_range="under18";
}
elseif( min( $age_range ) >= 18 ) {
    $age_range="over18";
}
else {
    // Unset $age_role if no required values found in $age_range.
    unset( $age_role );
}


if( isset( $age_role ) ) {
    // Here you can assign the role $age_role to the user.
}

Related Posts:

  1. Set user role based on invitation code
  2. allow editors to edit menus?
  3. How to change a user’s role?
  4. Is there way to rename user role name without plugin?
  5. How to create a clone role in wordpress
  6. How to add a Capability to a User Role?
  7. How can I get a list of users by their role?
  8. How to get role of user
  9. How to allow editor to edit privacy page / settings only?
  10. How do I make a draft post accessible to everyone?
  11. Reset default roles and capabilities
  12. How do I programmatically set default role for new users?
  13. add_role() run only once?
  14. What do unfiltered_html and unfiltered_upload actually filter?
  15. wp_update_user not updating
  16. Temporary capability for current_user_can()
  17. Create custom user role (client) that can create another custom user role (employee) of that client
  18. Is it possible to add new user Roles?
  19. Allow roles below admin to add subscribers only
  20. Temporarily give ‘manage_options’ capability
  21. REST API, get user role?
  22. Is WordPress’ is_user_logged_in() secure?
  23. How to force listing contributors in authors dropdown menu
  24. Hide specific admin users’ posts
  25. Allow authors to edit only certain users
  26. How do I allow a specific Role in WordPress 3+ to only see certain plugins?
  27. How to update role capabilities
  28. Allow editors access to added plugins
  29. Temporarily disable user role login and replace with message
  30. How to filter the role selector?
  31. How to loop through each user id?
  32. Code needed to only show users own posts in a multi-user account
  33. How can I change a user role upon visiting a page?
  34. How to let the Contributor role preview unpublished posts?
  35. Change role after the user has read all the posts in a category
  36. Do custom user roles have any default capabilities?
  37. Filter available WooCommerce payment gateways by role [closed]
  38. Ordering users of a specific role by last name
  39. How to programmatically add a user to a role?
  40. Restrict Author to pick from media library, but not upload media
  41. Can i copy administrator role to another user?
  42. how to add custom user capabilities using add_user_meta or something else?
  43. Assign Subscriber capabilities to a custom user role
  44. How to change role of all users with a specific role to another role?
  45. Allow user to Publish, but not Edit or Delete
  46. Roles at registration (classipress)
  47. How to allow registered users to change their user role through frontend?
  48. Remove Ability for Administrators to Delete Administrators
  49. Order users by custom user meta
  50. how to change user roles for users who doesn’t have any. (about 8000 users)
  51. List total number of users that are authors
  52. Email notification for editors only
  53. Shold I manually add ‘cap’ to admin role ?
  54. Custom Post Type’s Capabilities map_meta_cap issues
  55. I need to assign a role to visitors/guests
  56. Contributors missing from author dropdown
  57. How to make an author archive only for certain user role and show related CPT
  58. Getting a user role from the user login name
  59. Allow users to publish child pages of the pages they have access to edit
  60. Auto Delete Users (auto_delete_users)
  61. New Roles and Capabilities in WordPress
  62. Why is wp-login redirecting to the home page when I use this function?
  63. Is there a way to set the user Role based on email domain
  64. Allow contributor to view own scheduled post
  65. Editor and contributor roles not correct after adding function
  66. Adding multiple user roles dynamically
  67. WordPress Super Admin
  68. pre_get_posts Remove posts based on meta value with ‘post__not_in’
  69. How to add author role as a custom field to custom post type in wordpress?
  70. How to prevent users with “edit_others_posts” capability from editing admin posts
  71. How are roles stored in the database?
  72. Author Role – Allow editing of Gallery images
  73. How do I allow anyone to edit a post — but not access dashboard
  74. What is the difference between “create_users” and “add_users” capabilities?
  75. How to delete user roles?
  76. Access on specific pages in wordpress for a specific user
  77. How to get all users with Author role capabilities?
  78. How to display user role
  79. Change the user role after x days
  80. Get (echo) all role names assigned to user
  81. How to ‘unpublish’ or ‘hide’ posts when user role changes?
  82. Can’t manage to make translate_user_role() work
  83. Add Role inherits?
  84. similar to Editor can create any new user except administrator
  85. Conditional Tags for Membership Levels when using Wishlist Member Plugin?
  86. How to check if a role has a specific capability
  87. I am adding a new class to my body tag if the logged in user is subscriber, need help
  88. Expire a user’s secondary role after X days from it being allocated
  89. Locking Down WordPress Application Password Permissions / Capabilities
  90. How to Orderby User Role?
  91. Users Role and Access
  92. Prevent custom user role to add new pages
  93. Allow user to edit specific user with meta key using map_meta_cap
  94. How to remove sticky post capability for a specific user role?
  95. Can a user with admin role get ‘Sorry, you are not allowed to move this item to the Trash’ error when trashing a post?
  96. Hide Specific User Page
  97. Making shortcode of filtered number of comments by user role
  98. Let new user role to ‘edit_others_posts’ of other user role, not of its own type
  99. How to stop contributors editing post type but allowing them to edit a custom post type?
  100. How can I have different groups of editors only allowed to edit certain parent+subpages?
Categories user-roles Tags signup, user-roles
WP CLI – Pass Query / URL Variable to Cron?
How do I check to see if a specific child term has shared posts with another set of child terms within the same taxonomy?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress