Skip to content

Instantly share code, notes, and snippets.

@PCianes
Created July 8, 2017 15:42
Show Gist options
  • Save PCianes/881b3ceb97db114880df3a58a8d1026d to your computer and use it in GitHub Desktop.
Save PCianes/881b3ceb97db114880df3a58a8d1026d to your computer and use it in GitHub Desktop.
Add capability to user or role
<?php
// Example 1
function add_cap_upload_files_to_user_id() {
$user = new WP_User( $user_id );
$user->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'add_cap_upload_files_to_user_id');
// Example 2
function allow_contrib_upload() {
$contrib = get_role( 'contributor' );
$contrib->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'allow_contrib_upload', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment