-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding/removing user roles #50
base: master
Are you sure you want to change the base?
Conversation
Thanks for the PR! I thought about adding this in the past but when you add a role to WordPress, it saves it to the database. This means we need some kind of conditional to wrap Ref: https://developer.wordpress.org/reference/functions/add_role/#comment-3194 |
You are right, doesn't makes sense to do a DB operation on every page load. And if we use the update_option to keep track of the currently deployed database version? add_action('update_option_deploy','poet_user_roles', 10, 2);
add_action('update_site_option_deploy','poet_user_roles', 10, 2); //For multisite installations
function poet_user_roles($oldValue, $newValue){
if ($oldValue == $newValue) {
return;
}
// Add or remove user roles here
add_role('librarian', 'Librarian');
} And add the following to Trellis: - name: Update deploy option
tags:
- wordpress:deploy
command: "wp option update deploy {{ deploy_helper.new_release_path | basename }} --url={{ item }}"
become: true
become_user: "{{ web_user }}"
args:
chdir: "{{ deploy_helper.new_release_path }}"
changed_when:
- "'Success: Updated ' in wp_options_update.stdout"
register: wp_options_update
loop: "{{ wordpress_sites.values() | map(attribute='site_hosts') | flatten | map(attribute='canonical') | flatten }}" PS: I know that it's getting out of scope here. But it also brings some advantages besides knowing which current version is deployed using the DB, we could also use this option when restoring a database to a previous state using a backup, where we could know exactly which code version was running at the time. |
Added reference link about database query on every request
@Log1x I added a condition using the wp_roles()->is_role($slug) function - which avoids an unnecessary database query. Tested using Query Monitor with a logged in and non logged in user. WP_Roles is initialised by WordPress here. Let me know what you think. PS: Forget my last comment |
Make it easy to add and remove user roles.