=== RP xProfile Import Export ===
Contributors:      rahuliprajapati
Tags:               buddyboss, buddypress, xprofile, export, import
Requires at least: 5.8
Tested up to:      7.0
Requires PHP:      7.4
Stable tag:        1.0.0
License:           GPLv2 or later
License URI:       https://www.gnu.org/licenses/gpl-2.0.html

Export and import BuddyBoss/BuddyPress xProfile fields with the exact same Field IDs, types, and settings for safe site migrations.

== Description ==

**Stop rebuilding xProfile fields by hand every time you move a site.** RP xProfile Import Export exports every BuddyBoss (or BuddyPress) xProfile field group and field to a single JSON file, then re-imports it on another site with the **exact same Field IDs**, types, names, options, visibility levels, and meta settings intact. What used to be an hour of manually recreating dropdowns, checkboxes, and text fields on a new environment now takes two clicks.

**Why preserving Field IDs actually matters**

User profile data is stored in the `bp_xprofile_data` table and linked to fields purely by numeric ID — not by name. If you export/import fields with a generic tool (or recreate them by hand) and the IDs shift even slightly, existing profile data silently stops mapping to the right field. RP xProfile Import Export re-inserts every group and field with its original ID, so profile data — old or freshly synced — always lands in the correct place.

= Who Is This For? =

* **Agencies and freelancers** who clone a client's staging site to production (or vice versa) and need xProfile fields to match exactly.
* **Developers** setting up local/staging environments that mirror a live BuddyBoss community.
* **Site owners** migrating hosts or consolidating multiple BuddyBoss/BuddyPress installs.
* **Anyone** who has ever had to manually recreate 30 profile fields after a site migration.

= Key Features =

* **One-Click Export** — Download every xProfile group and field as a single, human-readable JSON file.
* **ID-Preserving Import** — Fields are re-inserted with their original database IDs, so existing profile data keeps mapping correctly after migration.
* **Two Import Modes** — *Overwrite* updates existing fields and creates new ones; *Skip* only creates fields that don't already exist, leaving the rest untouched.
* **Full Fidelity** — Field Types, Names, Descriptions, Options, Meta, Visibility levels, Required status, and Group order are all preserved exactly.
* **Detailed Import Log** — See precisely what was created, updated, or skipped after every import, expandable right on the admin page.
* **Field-Type Validation** — Only field types actually registered with BuddyBoss/BuddyPress are accepted on import, so a corrupted or hand-edited file can't insert bogus data.
* **Clean, Modern UI** — A drag-and-drop upload zone and a live preview of what will be exported, right inside your WordPress admin.
* **No Bloat** — Two admin-only screens, no widgets, no shortcodes, no frontend footprint whatsoever.

= How It Works =

**Step 1.** On the *source* site, open **RP xProfile Import Export** in the admin menu and click **Export JSON**. A file such as `xprofile-fields-export-2026-07-09-120000.json` downloads to your computer.

**Step 2.** Install and activate RP xProfile Import Export on the *destination* site.

**Step 3.** Open **RP xProfile Import Export**, choose **Overwrite** (replace + add) or **Skip** (add only new fields), drag the JSON file into the upload zone, and click **Import Fields**.

**Step 4.** Review the import log — it lists every group and field that was created, updated, or skipped, plus how many option rows were restored.

= Requirements =

* BuddyBoss Platform **or** BuddyPress, with the xProfile (Extended Profiles) component enabled. RP xProfile Import Export detects automatically which one you have and shows a clear admin notice if either is missing or the component is disabled.

== Security ==

* Both the Export and Import actions require the `manage_options` capability (administrator only) and are protected by a dedicated WordPress nonce — checked with `check_admin_referer()` on every request.
* Uploaded import files are validated with `is_uploaded_file()`, capped at 5 MB, and must parse as well-formed JSON before anything touches the database — malformed or oversized files are rejected with a clear error message.
* Every field `type` in an import file is checked against BuddyBoss/BuddyPress' own registered field-type list (`bp_xprofile_get_field_types()`); unrecognized types are skipped instead of being written to the database.
* All text fields (names, descriptions, meta keys) are sanitized with `sanitize_text_field()`, `wp_kses_post()`, or `sanitize_key()` before being saved.
* All database writes use `$wpdb->prepare()` / `$wpdb->insert()` / `$wpdb->update()` with parameterized placeholders — no raw SQL is built from user input.
* All admin-page output is escaped with `esc_html()`, `esc_attr()`, `esc_url()`, or `wp_kses_post()`.
* CSS and JavaScript are enqueued only on the plugin's own admin page — zero impact on the rest of your dashboard or your site's frontend.
* The plugin adds no REST routes, no shortcodes, and no public-facing endpoints. It only writes to BuddyBoss/BuddyPress' own xProfile tables — never to core WordPress tables.
* On uninstall, the plugin removes its own transient and leaves your xProfile data untouched — deleting the plugin never deletes your profile fields.

*RP xProfile Import Export is an independent utility and is not affiliated with, endorsed by, or sponsored by BuddyBoss or Automattic (BuddyPress).*

== Installation ==

1. Upload the `rp-xprofile-import-export` folder to the `/wp-content/plugins/` directory, **or** install directly from the WordPress plugin repository via **Plugins -> Add New** and search for "RP xProfile Import Export".
2. Activate the plugin through the **Plugins** screen in WordPress.
3. Make sure BuddyBoss Platform or BuddyPress is active with the xProfile component enabled.
4. Navigate to **RP xProfile Import Export** in the admin menu to export or import your fields.

== Frequently Asked Questions ==

= Does this plugin require BuddyBoss Platform? =

It requires either BuddyBoss Platform or BuddyPress, with the xProfile (Extended Profiles) component active. The plugin detects which one is installed and shows a clear notice if it can't find either, or if the xProfile component is disabled.

= Will importing overwrite my existing fields? =

Only if you choose the **Overwrite** import mode, which updates existing fields (matched by ID) and creates any that don't exist yet. The **Skip** mode only creates fields that are missing — anything that already exists on the destination site is left completely untouched.

= What exactly gets exported? =

Every xProfile group and field: Field IDs, Types, Names, Descriptions, Options (for dropdowns/checkboxes/radios), Meta settings, Visibility levels, Required status, and Group/Field order — as a single JSON file.

= Why do the Field IDs need to match exactly? =

Profile data is stored in the `bp_xprofile_data` table and linked to fields only by numeric ID. If IDs don't match after a migration, existing (or newly synced) profile answers stop mapping to the correct field. This plugin re-inserts fields with their original IDs specifically to prevent that.

= Is it safe to use on a live site? =

Yes, with the usual precaution: **always take a database backup before importing on a live site**, since importing writes directly to your xProfile tables. Exporting is completely read-only and safe to run anytime.

= What happens if I upload a corrupted or hand-edited JSON file? =

The file is validated before anything is written to the database. If it isn't valid JSON, contains no groups, or references a field type that isn't registered with BuddyBoss/BuddyPress, the affected entries are skipped and reported in the import log — they are never inserted.

= Does this plugin add anything to my site's frontend? =

No. RP xProfile Import Export is 100% admin-side. It adds one menu item, loads its CSS/JS only on its own settings page, and has no shortcodes, widgets, or public endpoints.

= What happens when I delete the plugin? =

Only the plugin's own temporary transient is removed. Your xProfile groups, fields, and profile data are never touched by uninstalling — they belong to BuddyBoss/BuddyPress, not to this plugin.

= What PHP version is required? =

PHP 7.4 or higher. PHP 8.0 through 8.4 are fully supported.

= Is this plugin translation-ready? =

Yes. All UI strings use WordPress internationalization functions with the `rp-xprofile-import-export` text domain.

== Screenshots ==

1. **Export / Import Dashboard** — Live stats (groups, fields, version), a preview of every group about to be exported, and a drag-and-drop import zone with Overwrite/Skip mode selection.
2. **Import Log** — An expandable, line-by-line log showing exactly which groups and fields were created, updated, or skipped after an import.

== Changelog ==

= 1.0.0 =
* Initial public release.
* Export all BuddyBoss/BuddyPress xProfile groups and fields to a single JSON file.
* ID-preserving import with Overwrite and Skip modes.
* Field-type validation against BuddyBoss/BuddyPress' registered field types.
* Detailed, expandable import log.
* 5 MB upload cap and JSON validation on import.
* Nonce-protected, `manage_options`-only admin actions.
* Clean, modern drag-and-drop admin UI with zero frontend footprint.
* WordPress coding standards compliant; all inputs sanitized, all outputs escaped.
* Translation-ready with the `rp-xprofile-import-export` text domain.

== Upgrade Notice ==

= 1.0.0 =
Initial release.
