Skip to content

Feat/import export roles#209

Open
omaraelhawary wants to merge 18 commits intodevelopfrom
feat/import-export-roles
Open

Feat/import export roles#209
omaraelhawary wants to merge 18 commits intodevelopfrom
feat/import-export-roles

Conversation

@omaraelhawary
Copy link
Copy Markdown
Collaborator

Related to #115

- Replace empty output with disabled checkboxes for roles that cannot
  be selected for bulk actions (default role, user's own role,
  non-editable roles)
- Add title attributes explaining why each checkbox is disabled

Made-with: Cursor
- Add Role_Export class that generates JSON export files containing
  roles, capabilities, and plugin settings
- Support full export via admin-post action and selective export for
  bulk actions with a filtered set of role slugs
- Include site metadata (URL, WP version, export date) in the export

Made-with: Cursor
- Add Role_Import class with a two-step import flow: upload/preview
  followed by confirm/apply
- Validate uploaded JSON files for structure, size, and format
- Detect conflicts with existing roles and support skip, overwrite,
  and rename actions per role during confirmation
- Sanitize capabilities and import plugin settings optionally

Made-with: Cursor
- Add Export bulk action to the roles list table
- Add Export All and Import buttons to the roles page header
- Add bulk export handler that delegates to Role_Export
- Add import form with file upload and settings checkbox
- Add import preview page with conflict resolution UI (skip,
  overwrite, rename) and bulk conflict action selector
- Add inline styles and scripts for the import preview interactions
- Add import/export help tab
- Require the new Role_Export and Role_Import classes in members.php

Made-with: Cursor
@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements role import and export features, enabling the transfer of roles and settings via JSON. It adds dedicated classes for these operations, a preview-based import workflow, and updates the admin UI to support bulk exports and provide clearer status for non-editable roles. Feedback identifies a potential data loss bug in the settings import logic, redundant code in role updates, and a need for more robust sanitization of imported settings.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a role import and export system for the Members plugin, enabling the transfer of roles and settings via JSON files. It introduces new classes for handling these processes, adds bulk export functionality to the roles list table, and provides a two-step import interface with conflict resolution options. Technical feedback identifies redundant manual updates to the global roles object and recommends more robust sanitization for imported settings using map_deep to handle complex data structures.

@omaraelhawary omaraelhawary self-assigned this Mar 31, 2026
@cartpauj
Copy link
Copy Markdown
Contributor

cartpauj commented Mar 31, 2026

@omaraelhawary will you feed the Gemini feedback into Claude or Cursor (whichever you're using)?

I find it's helpful to tell it

Below is some feedback from Gemini AI code review in github. Please look through the code and assess if these feedback items really need to be addressed/resolved or not. Please let me know what you've decided before you fix these issues and we'll make a plan together.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a role import and export system for the Members plugin, enabling JSON-based migration of roles and settings. It features a two-step import process with conflict resolution and updates the admin UI with bulk export actions and improved feedback for non-editable roles. Feedback identifies several technical improvements: preventing accidental lockouts by restricting role overwrites, ensuring administrative dependencies are loaded, adding data validation for imported roles, and maintaining consistency with the plugin's internal role registry.

- Add check to ensure 'roles' is an array during import validation
- Prevent overwriting the current user's role or the default role to avoid lockout issues
- Register and track newly created roles during the import process
@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces role export and import functionality to the Members plugin, allowing users to transfer roles and settings between sites via JSON files. Key additions include the Role_Export and Role_Import classes, a two-step import workflow with a preview stage, and updates to the roles list table to support bulk export actions and improved UI for non-editable roles. The review feedback suggests hardening the singleton implementation by making constructors private, ensuring required WordPress admin files are explicitly loaded before calling get_plugin_data, and adding a safety check during the final import step to verify role existence and prevent accidental overwrites of roles created between the preview and confirmation phases.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive role export and import functionality, enabling the transfer of roles and plugin settings via JSON files. It adds dedicated classes for export and import logic, a preview-based import workflow with conflict resolution, and UI enhancements to the roles list table for bulk actions and role status visibility. A performance optimization was suggested for the import confirmation process to avoid redundant function calls within a loop.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive role import and export system, allowing users to transfer roles and plugin settings between sites via JSON files. The implementation includes a two-step import workflow with conflict detection and bulk export functionality. Key feedback includes strengthening security by preventing the overwrite of uneditable roles during import, improving data validation for settings to avoid PHP notices, and optimizing performance in the role list table by using cached properties instead of repeated option lookups.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces role import and export functionality to the Members plugin, allowing users to transfer roles and settings between sites via JSON files. Key additions include new Role_Export and Role_Import classes, a two-step import workflow with conflict detection, and updates to the roles list table to support bulk export actions. Review feedback suggests strengthening security by explicitly protecting the 'administrator' role from being overwritten, refining the settings import logic to ensure data integrity, and moving large inline scripts to a dedicated file for improved maintainability.

- Update role overwrite prevention logic to include checks for the 'administrator' role
- Mark roles as protected based on user roles and default role to prevent accidental overwrites
- Add is_uploaded_file() check before reading uploaded JSON file
- Use get_role() fallback alongside members_role_exists() for conflict
  detection to catch roles from other plugins (e.g. WooCommerce)
- Bound suggested slug generation loop with a numeric counter (max 100)
- Filter imported settings to known default keys before storing in transient
- Omit plugin settings from selective/bulk role exports

Made-with: Cursor
@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces functionality to export and import user roles and plugin settings via JSON files. The changes include new classes for handling export and import logic, updates to the roles list table to support bulk export, and UI enhancements for managing imports. My feedback suggests optimizing the plugin version retrieval to avoid expensive file parsing and moving the newly added inline CSS and JavaScript into external files to improve maintainability and performance.

- Enqueue new import/export script for role management
- Add styles for import/export status indicators in admin CSS
- Register the import/export script with versioning based on file modification time
@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive role import and export functionality to the Members plugin, allowing users to transfer roles and settings between WordPress sites via JSON files. The implementation includes a new export class, a two-step import process with preview and conflict resolution, and UI updates to the roles management page. I have reviewed the code and identified two areas for improvement: adding type casting for the role label to prevent potential PHP warnings, and centralizing the protection logic for critical roles to ensure they cannot be inadvertently modified during any import action.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a role import and export system, allowing users to transfer roles and settings via JSON files. It features a two-step import process with conflict detection, selective bulk exports, and updated UI components including a preview page and help tabs. The review feedback suggests enhancing the robustness of the import logic by checking file read results and using standard boolean validation for capabilities, as well as improving translation strings by separating HTML from translatable text.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a robust role import and export system, allowing users to transfer roles and plugin settings between sites via JSON files. Key additions include the Role_Export and Role_Import classes, a two-step import workflow with conflict detection, and UI enhancements to the roles list table for bulk actions and protected role visibility. Review feedback suggests tightening the enforcement of protected roles during the import process and adding error handling to the role overwrite logic to ensure system consistency if role creation fails.

@omaraelhawary
Copy link
Copy Markdown
Collaborator Author

@ThemeGravity Ready to review. Thanks in advance. Here's a description about it:

Import / Export Roles — Feature Summary

Overview

This feature adds the ability to export and import WordPress roles (and optionally plugin settings) via JSON files on the Members plugin Roles admin screen (Members > Roles). It enables transferring role configurations between WordPress sites.

Export

  • "Export All" button in the page header downloads a JSON file containing all roles, their capabilities, and Members plugin settings. Requires list_roles capability.
  • Bulk "Export" action in the list table lets the user select specific roles via checkboxes. The exported file includes only the selected roles and omits plugin settings.
  • The JSON file includes a meta block (plugin, version, export_date, site_url, wp_version), a roles map, and a settings object (full export only).

Import (Two-Step Flow)

Step 1 — Upload & Preview

  • User clicks "Import" to reveal a slide-down panel with a file input and an optional "Also import Members plugin settings" checkbox.
  • On submit, the file is validated (must be .json, under 2 MB, valid JSON, correct meta.plugin marker, at least one valid role).
  • Role slugs are sanitized; duplicates caused by sanitization are detected and counted.
  • Each role is checked against existing roles for conflict detection.
  • Parsed data is stored in a user-specific transient (30 min TTL) and the user is redirected to a preview page.

Step 2 — Preview & Confirm

  • Preview page shows a table with each role's name, slug, capability count (expandable), status ("New" / "Exists"), and an action dropdown.
  • For new roles: Import or Skip.
  • For existing (conflicting) roles: Skip, Overwrite, or Import as new (rename).
  • For protected roles (administrator, current user's role, default role, non-editable): forced to Skip.
  • A "Set all conflicts to" bulk dropdown applies Skip or Overwrite to all conflict rows at once.
  • On confirm, the transient is consumed, roles are created/overwritten/renamed per selection, capabilities are sanitized, and settings are optionally merged.
  • A summary message is shown (e.g., "3 roles imported. 2 roles skipped. Plugin settings imported.").

Security

  • All forms use nonce verification.
  • Export requires list_roles; import requires edit_roles.
  • Capabilities are sanitized via members_sanitize_cap(); role slugs via members_sanitize_role().
  • Imported settings are filtered against known default keys only — no arbitrary options can be injected.
  • Protected roles (administrator, current user's own role, site default role) cannot be overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants