I want to give a user edit capabilities for specific games
-
Hi,
I have some custom fields on the user’s profiles:
Each of those returns an array with the id’s of the games/teams/players picked.
For example, the ‘game_edit_capabilities’ field returns an array of the ids different chosen games.
I want to give that user, the capability to edit and publish that game. How can I achieve that?
I tried this but it gives the user access to edit all games instead of just the ones chosen
? ? ? ? function add_specific_user_capabilities( $user_id ) { ? ? ? ? ? ? $custom_events ? ?= get_field( 'game_edit_capabilities', 'user_' . $user_id ); ? ? ? ? ? ? $user ? ? ? ? ? ?= new WP_User( $user_id ); ? ? ? ? ? ? if ( $custom_events ) { ? ? ? ? ? ? ? ? foreach ( $custom_events as $event_id ) { ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'edit_event', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'edit_events', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'edit_others_events', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'edit_published_events', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'manage_event_terms', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'edit_event_terms', $event_id ); ? ? ? ? ? ? ? ? ? ? $user->add_cap( 'assign_event_terms', $event_id ); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? add_action( 'profile_update', 'add_specific_user_capabilities' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘I want to give a user edit capabilities for specific games’ is closed to new replies.