> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/features/plugin-lifecycle.md). Agents can also search and read this documentation through its [MCP server](https://whoisandywhite.gitbook.io/porterwp/~gitbook/mcp).

# Plugin and rewrite lifecycle

PorterWP 1.4.95 coordinates activation, runtime rewrite changes, scheduled past-status work, optional ACF integration, and deactivation without flushing rewrite rules repeatedly or leaving theme-owned cron hooks behind.

## Runtime bootstrap

When WordPress loads the plugin, PorterWP:

1. registers translation loading for `init` priority 1;
2. initializes the main plugin and its helper classes once;
3. loads the active theme's Porter configuration and PHP integrations on their documented hooks;
4. loads premium features only when the current Freemius entitlement allows premium code;
5. registers activation and deactivation callbacks.

`PORTER_VERSION`, `PORTER_PATH`, and `PORTER_URL` are defined during main plugin initialization. In 1.4.95, `PORTER_VERSION` is `1.4.95`.

## Activation

Activation calls `porter_reset_rewrite_config_signature()`. This deletes the stored combined rewrite signature; it does not flush immediately while the activation request is still assembling plugin state.

On the next eligible browser request, all active rewrite providers register their current component signatures and PorterWP performs one coordinated soft flush.

Activation does not alter post content or delete theme configuration.

## Coordinated rewrite rules

Three built-in providers contribute to the combined signature:

* custom post types from `posttypes.json`;
* custom taxonomies from `taxonomies.json`;
* each instantiated `Porter_PastStatusUpdater` rule.

Post type and taxonomy signatures include active-theme and resolved config-file context. A past-status signature includes its post type, status, permalink slug, regex, and query target.

Providers call `porter_register_rewrite_config_signature()`. At `wp_loaded` priority 999, PorterWP sorts the component map, hashes the combined value, and compares it with the `porter_rewrite_config_signature` option.

If the value changed, PorterWP calls:

```php
flush_rewrite_rules( false );
```

The `false` argument is a soft flush: WordPress regenerates its rewrite option without rewriting web-server configuration files.

### Requests that defer flushing

PorterWP does not flush during:

* AJAX requests;
* WP-Cron;
* REST requests;
* WP-CLI commands.

The stored signature remains unchanged in those contexts. A later ordinary browser request sees the same mismatch and safely performs the flush after all providers are ready.

This means a deployment or activation does not need to make a special front-end request synchronously. It also avoids doing expensive rewrite work in background and API traffic.

## Past-status scheduled events

Every instantiated `Porter_PastStatusUpdater` ensures its hourly event exists and records the hook name in `porter_past_status_cron_hooks`. The persistent registry is intentionally separate from the active theme so cleanup can find a hook even after the theme file that created it is unavailable.

* A theme switch asks each currently instantiated updater to unschedule its event.
* Plugin deactivation clears every hook found in the current request and the persistent registry, then deletes the registry.
* Subclasses can call their public `schedule_event()` and `unschedule_event()` methods from a theme-specific lifecycle if needed.

See [`Porter_PastStatusUpdater`](https://whoisandywhite.gitbook.io/porterwp/developer-api/porter-past-status-updater.md) for batching, save timing, and manual operations.

## ACF PRO dependency lifecycle

PorterWP checks for the ACF class and the PRO APIs it uses after plugins have loaded. Complete integration requires:

* `acf_add_local_field_group()`;
* `acf_add_options_page()`;
* `acf_render_block_callback()`.

When those APIs are available, ACF-backed custom blocks load after the dependency check. When they are missing, PorterWP remains active and skips features that depend on them. Users who can activate plugins, including appropriate network administrators, receive a warning explaining that ACF PRO is required for the complete integration.

Core Porter configuration and features that do not call unavailable ACF APIs continue to load. Registration methods also guard their individual ACF function calls, so a missing dependency does not become a front-end fatal error.

After activating ACF PRO, use a new request so WordPress runs the normal plugin bootstrap with the dependency available. PorterWP does not require its own reactivation.

## Login error privacy

PorterWP filters WordPress login errors to the translated message `Oops! Incorrect input.`. This applies to every failed login handled through the normal `login_errors` filter and avoids revealing whether a submitted username or email address exists.

Themes or authentication plugins that intentionally present different login guidance must add their own `login_errors` callback at a later priority. Keep any replacement generic unless disclosing account state is a deliberate security decision.

## Deactivation

Deactivation calls `porter_deactivate_rewrite_rules()`, which:

1. clears all known Porter past-status scheduled hooks;
2. deletes `porter_past_status_cron_hooks`;
3. deletes `porter_rewrite_config_signature`;
4. deletes WordPress's `rewrite_rules` option.

PorterWP deliberately does not call `flush_rewrite_rules()` while its callbacks are still loaded in the deactivation request. Deleting the option lets WordPress regenerate a clean rule set on the next request without persisting Porter-owned callbacks.

Deactivation does not delete posts, terms, theme JSON, compiled theme assets, license records, or all Porter cache entries. The plugin's uninstall and commercial account lifecycle are separate from deactivation.

## Theme switching

Theme and file identities are included in Porter cache and rewrite signatures. After a switch, the new stylesheet receives its own configuration context and the combined rewrite signature changes as required. The ordinary safe-request process handles the resulting soft flush.

Theme PHP include caches are also validated against the newly resolved `porter/inc` root, so files from the previous theme are not trusted merely because their paths remain in an option.

## Operational guidance

* Do not call `flush_rewrite_rules()` on every `init` request.
* Do not add a routine “visit Permalinks and click Save” deployment step for PorterWP.
* After changing post type, taxonomy, or past-status rewrite configuration, allow one ordinary browser request to complete.
* If background-only traffic follows a deployment, a rewrite flush can remain intentionally deferred until that browser request.
* Use **Settings → PorterWP → Clear PorterWP Cache** to invalidate Porter's theme caches and rewrite signature while troubleshooting. See [Caching and environments](https://whoisandywhite.gitbook.io/porterwp/features/caching.md).

## Compatibility notes for 1.4.95

* Post type, taxonomy, and `Porter_PastStatusUpdater` APIs remain compatible with existing theme configuration and subclasses.
* Rewrite flushing is now coordinated. Remove custom activation or request hooks whose only purpose was to flush Porter rules repeatedly.
* Deactivation now removes orphaned Porter past-status cron hooks using the persistent registry.
* Missing ACF PRO now disables dependent features gracefully instead of requiring every Porter request to assume those APIs exist.
