post_type && !current_user_can( 'edit_posts', $post_id ) ) return; /* Only allow users that can edit the current page to submit data. */ elseif ( 'page' == $post->post_type && !current_user_can( 'edit_pages', $post_id ) ) return; /* Don't save if the post is only a revision. */ if ( 'revision' == $post->post_type ) return; /* Loop through each of the site's available roles. */ if(!empty($rpg_groups)) { foreach ( $rpg_groups as $group => $details ){ /* Get post metadata for the custom field key 'group'. */ $meta = (array)get_post_meta( $post_id, '_private_group', false ); /* Check if the group was selected. */ if ( $_POST[$group] ) { /* If selected and already saved, continue looping through the roles and do nothing for this role. */ if ( in_array( $group, $meta ) ) continue; /* If the group was selected and not already saved, add the group as a new value to the 'group' custom field. */ else add_post_meta( $post_id, '_private_group', $group, false ); } /* If role not selected, delete. */ else delete_post_meta( $post_id, '_private_group', $group ); } // End loop through site's groups. } } ?>