=== PCP Linkflow Engine ===
Contributors: phoolchandcms, pcprajapat
Tags: permalink, slug, seo, url, woocommerce
Requires at least: 5.8
Tested up to: 6.9
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Full URL control for every post type and taxonomy. Customize slugs, remove bases, and define permalink structures - all from a clean admin interface.

== Description ==

**PCP Linkflow Engine** gives you complete control over every URL on your WordPress site. Whether you need to remove the `/product/` prefix from WooCommerce products, add a custom base to a taxonomy, or restructure your page URLs — this plugin handles it all from a clean, modern admin interface.

No code required. Changes take effect immediately with automatic rewrite rule flushing.

### 🔑 Key Features:

**Post Type URL Control**
- ✏️ Set a **custom slug** for any public post type (e.g. `/shop/` instead of `/product/`)
- 🗑️ **Remove the slug entirely** — serve products, posts, or CPTs at root level (e.g. `/jacket/` instead of `/product/jacket/`)
- 📄 Full support for **hierarchical post types** like Pages (e.g. `/pages/about/team/`)
- 🛒 **WooCommerce compatible** — works correctly with the shop page, product archives, `is_product()`, and all WooCommerce template hooks

**Taxonomy URL Control**
- ✏️ Set a **custom base** for any public taxonomy (e.g. `/topics/` instead of `/category/`)
- 🗑️ **Remove the base entirely** — serve term archives at root level (e.g. `/clothing/` instead of `/product-category/clothing/`)
- 🌳 Full support for **hierarchical taxonomies** — sub-terms work correctly (e.g. `/clothing/accessories/`)
- ✅ Correct `is_tax()`, admin bar links, and taxonomy templates when base is removed

**Developer Friendly**
- 🔌 Filter hooks: `pcplfe_post_type_slug`, `pcplfe_taxonomy_slug`, `pcplfe_permalink_structure`, `pcplfe_remove_post_type_slug`, `pcplfe_remove_taxonomy_slug`
- 🌐 **REST API** — read and write settings via `/wp-json/pcplfe/v1/`
- 📦 **Import / Export** — back up and restore all settings as JSON
- 🧩 **PSR-4 autoloaded** OOP architecture under the `PCPLFE\` namespace

**Modern Admin UI**
- 🎨 Clean, Tailwind-inspired design with toggle switches
- 📑 Tabbed settings for Post Types and Taxonomies
- 🔄 POST → Redirect → GET pattern — no duplicate saves on refresh
- 💾 Active tab preserved across saves and page refreshes

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/`, or install it via **Plugins → Add New** in WordPress.
2. Activate the plugin through the **Plugins** menu.
3. Navigate to **Linkflow Engine** in the WordPress admin sidebar.
4. Enable the post types or taxonomies you want to customise, enter your desired slugs, and click **Save Settings**.
5. That's it — rewrite rules are flushed automatically on save.

**Requirements:**
- WordPress 5.8 or higher
- PHP 7.4 or higher
- WooCommerce 5.0+ (optional, for product/taxonomy URL features)

== Frequently Asked Questions ==

= Will this break my existing URLs? =
No. The plugin only modifies URLs for post types and taxonomies you explicitly enable. All other URLs remain untouched. If you change a slug, existing URLs will still be handled by WordPress's built-in redirect logic.

= Does Remove Slug work with WooCommerce products? =
Yes. When Remove Slug is enabled for Products, product detail pages load at `/product-name/` and WooCommerce's `is_product()`, template hierarchy, cart, and checkout all work correctly.

= Does the WooCommerce shop page still work after setting a custom slug for Pages? =
Yes. The plugin automatically resolves page IDs so WooCommerce's `pre_get_posts` hook correctly detects the shop page and displays the product archive regardless of the page URL prefix.

= Do sub-category URLs work with Remove Base? =
Yes. Hierarchical taxonomy terms are fully supported. For example, `/clothing/accessories/` resolves correctly when Remove Base is enabled for the `product_cat` taxonomy.

= Can I use a multi-segment custom slug? =
Yes. You can enter a path like `product/test` as the Custom Slug for a post type. The plugin sanitises each segment individually, so the slash is preserved and the correct rewrite rules are generated.

= Does it work with WordPress default taxonomies (category, post_tag)? =
Yes. The plugin correctly uses each taxonomy's native WordPress query variable (`category_name` for category, `tag` for post_tag) so custom base slugs work without any additional configuration.

= Can I export my settings to use on another site? =
Yes. Use the **Import / Export** page under the Linkflow Engine menu to download a JSON backup of all settings and custom permalinks, and re-import them on any other site.

= Is it translation-ready? =
Yes. All strings are wrapped in standard WordPress i18n functions using the `pcp-linkflow-engine` text domain.

== REST API ==

PCP Linkflow Engine exposes a REST API under the `pcplfe/v1` namespace. All endpoints require the `manage_options` capability.

**Authentication**

Use WordPress Application Passwords (WordPress 5.6+). Generate one at **Users → Your Profile → Application Passwords**, then pass it with every request:

    -u "your-username:xxxx xxxx xxxx xxxx xxxx xxxx"

= Endpoints =

**GET /wp-json/pcplfe/v1/settings**

Returns all saved post type and taxonomy settings.

    curl -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
      https://yoursite.com/wp-json/pcplfe/v1/settings

Example response:

    {
      "post_type_settings": {
        "post": { "enabled": true, "custom_slug": "articles", "remove_slug": false }
      },
      "taxonomy_settings": {
        "category": { "enabled": true, "custom_base": "topics", "remove_base": false }
      }
    }

**POST /wp-json/pcplfe/v1/settings**

Save post type and taxonomy settings from a JSON body.

    curl -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
      -X POST \
      -H "Content-Type: application/json" \
      -d '{
        "post_type_settings": {
          "post": { "enabled": true, "custom_slug": "articles", "remove_slug": false }
        },
        "taxonomy_settings": {
          "category": { "enabled": true, "custom_base": "topics", "remove_base": false }
        }
      }' \
      https://yoursite.com/wp-json/pcplfe/v1/settings

**GET /wp-json/pcplfe/v1/permalink?post_id=X**

Returns the custom permalink record for a given post ID.

    curl -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
      "https://yoursite.com/wp-json/pcplfe/v1/permalink?post_id=123"

Example response:

    {
      "post_id": 123,
      "post_type": "post",
      "default_permalink": "https://yoursite.com/articles/hello-world/",
      "custom_permalink": "https://yoursite.com/my-custom-slug/",
      "record": { "permalink": "my-custom-slug" }
    }

**POST /wp-json/pcplfe/v1/permalink**

Save a custom permalink for a specific post. Send an empty `permalink` value to remove the override.

    curl -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
      -X POST \
      -H "Content-Type: application/json" \
      -d '{
        "post_id": 123,
        "post_type": "post",
        "permalink": "my-custom-slug"
      }' \
      https://yoursite.com/wp-json/pcplfe/v1/permalink

To remove a custom permalink override:

    curl -u "admin:xxxx xxxx xxxx xxxx xxxx xxxx" \
      -X POST \
      -H "Content-Type: application/json" \
      -d '{
        "post_id": 123,
        "post_type": "post",
        "permalink": ""
      }' \
      https://yoursite.com/wp-json/pcplfe/v1/permalink

== Screenshots ==

1. Post Types tab — enable post types, set custom slugs, or remove slugs entirely using toggle switches.
2. Taxonomies tab — enable taxonomies, set custom bases, or remove bases with a single toggle.
3. Import / Export page — back up and restore all settings as a JSON file.
4. REST API page — view all available endpoints, parameters, and example curl requests.

== Changelog ==

= 1.0.0 =
* Initial release of PCP Linkflow Engine.
* Custom slug support for all public post types.
* Remove Slug support with WooCommerce product template compatibility.
* Custom base and Remove Base support for all public taxonomies.
* Hierarchical taxonomy sub-term URL resolution.
* WooCommerce shop page compatibility (page_id normalization).
* Multi-segment custom slug support (e.g. `product/test`).
* Modern admin UI with toggle switches and tabbed settings.
* POST → Redirect → GET for reliable settings saves.
* Import / Export settings as JSON.
* REST API endpoints under `/wp-json/pcplfe/v1/`.
* Developer filter hooks for all major permalink values.

== Upgrade Notice ==

= 1.0.0 =
Initial stable release.
