prefix . 'advausro_custom_roles'; $caps_table = $wpdb->prefix . 'advausro_role_capabilities'; foreach ($data as $role_data) { if (!is_array($role_data)) { $invalid++; $invalid_roles[] = __('Unknown role entry', 'advanced-use-role-management'); continue; } $slug = sanitize_title($role_data['role_slug'] ?? ''); $name = sanitize_text_field($role_data['role_name'] ?? ''); $display = sanitize_text_field($role_data['display_name'] ?? ''); $type = isset($role_data['type']) ? sanitize_key($role_data['type']) : 'default'; $caps = isset($role_data['capabilities']) && is_array($role_data['capabilities']) ? $role_manager->advausro_normalize_capabilities($role_data['capabilities']) : []; if (empty($slug) || empty($display)) { $invalid++; $invalid_roles[] = !empty($display) ? $display : __('Unknown role entry', 'advanced-use-role-management'); continue; } // Sync with WordPress (works for both default and custom) $existing_role = get_role($slug); if ($existing_role) { $skipped++; $skipped_roles[] = $display; continue; } else { $wp_caps_array = array_fill_keys($caps, true); $wp_caps_array['read'] = true; $created_role = add_role($slug, $display, $wp_caps_array); if (!$created_role) { $invalid++; $invalid_roles[] = $display; continue; } // For custom roles, insert in our tables if ('custom' === $type) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name is built from the local WordPress prefix. $existing_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$roles_table} WHERE role_slug = %s", $slug)); if (!$existing_id) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Required write for role import. $wpdb->insert($roles_table, [ 'role_slug' => $slug, 'role_name' => $name, 'display_name' => $display, 'created_at' => current_time('mysql') ]); $role_id = $wpdb->insert_id; foreach ($caps as $cap) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Required write for capability import. $wpdb->insert($caps_table, ['role_id' => (int) $role_id, 'capability' => $cap]); } } } } $count++; } $notice_parts = []; if ($count > 0) { $notice_parts[] = sprintf( /* translators: %d: Imported role count. */ _n('%d role imported successfully.', '%d roles imported successfully.', $count, 'advanced-use-role-management'), $count ); } if ($skipped > 0) { $notice_parts[] = sprintf( /* translators: 1: Skipped role count. 2: Role names. */ __('%1$d existing roles were skipped: %2$s', 'advanced-use-role-management'), $skipped, implode(', ', array_map('sanitize_text_field', $skipped_roles)) ); } if ($invalid > 0) { $notice_parts[] = sprintf( /* translators: 1: Invalid role count. 2: Role names. */ __('%1$d invalid entries were ignored: %2$s', 'advanced-use-role-management'), $invalid, implode(', ', array_map('sanitize_text_field', $invalid_roles)) ); } if (empty($notice_parts)) { $notice_parts[] = __('No roles were imported.', 'advanced-use-role-management'); } $advausro_import_notice = implode(' ', $notice_parts); $advausro_import_notice_type = $count > 0 ? 'success' : ($invalid > 0 ? 'error' : 'warning'); } } $wp_roles_obj = get_editable_roles(); ?>

Export Roles

Select roles to export as JSON

0 selected
$details): $cap_count = count($details['capabilities']); ?>

Import Roles

Upload a JSON file to import roles and capabilities

Drag & drop JSON file or click to upload

Only .json files accepted

Existing roles are skipped during import. Only new roles from the JSON file will be created.