=== Rozmuar Classic Block Editing for Advanced Custom Fields ===
Contributors: Shaadan
Tags: acf, advanced-custom-fields, block-editor, gutenberg, blocks
Requires at least: 6.8
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 4.5.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Restores ACF's classic Edit/Preview block toggle, hidden whenever WordPress iframes the block-editor canvas.

== Description ==

On some WordPress builds the block-editor canvas is always rendered inside
`<iframe name="editor-canvas">`, instead of only for block themes, non-desktop
previews, or apiVersion 3+ blocks as it used to be. Advanced Custom Fields
(ACF) itself contains a check for that iframe and, whenever it finds one,
unconditionally forces every ACF block into read-only Preview mode and hides
the classic "Switch to Edit / Switch to Preview" toolbar button — regardless
of the block's own `acf_block_version`.

This plugin restores that classic toggle without modifying any ACF or
WordPress core file on disk, using three independent, individually toggleable
fixes:

1. **Patch ACF's iframe detection at runtime.** Serves a runtime-patched copy
   of ACF's own block-editing script (generated on demand, cached in the
   uploads directory, auto-regenerated whenever ACF is updated) with the
   iframe-detection function neutralized.
2. **Cap ACF's own "Block Version 3" down to 2.** Separately, ACF's own
   "Block Version 3" ("Open Expanded Editor" modal) replaces the classic
   toggle with a different UI entirely; this optionally downgrades blocks
   back to Version 2 so they use the (now fixed) classic component.
3. **Cross-document companion fixes.** Once the ACF field form renders inside
   the canvas iframe again, several things that only worked because the
   canvas and the rest of wp-admin used to be one document need bridging:
   repeater/flexible-content row tooltips, select2 dropdown positioning, and
   the WYSIWYG (TinyMCE/Quicktags) field, plus loading ACF's own admin styles
   into the canvas so the form isn't left unstyled.

All three fixes are configurable under Settings → Classic Block Editing for ACF,
and every fallback path is safe: if the expected code can't be located inside
ACF's script (for example after an ACF update changes its build), the plugin
leaves the original script untouched and shows an admin notice instead of
silently mis-patching anything.

The iframe-detection patch and companion cross-document fixes are adapted
from the open-source plugin
[Block Edit Mode for ACF](https://github.com/cosmoc0der/block-edit-mode-for-acf)
by Bakhodir Sharipov (GPLv2 or later), which solves the identical problem.

= Why does this need to patch ACF's script instead of using a filter? =

The iframe-detection function lives entirely inside ACF's own compiled,
minified JavaScript bundle with no PHP-side filter or JS hook exposed for it.
The only way to change its behavior is to modify the JavaScript itself, which
this plugin does at runtime, on a cached copy, without ever touching ACF's
files on disk.

== Installation ==

1. Upload the plugin files to the `/wp-content/plugins/rozmuar-classic-block-editing-for-acf`
   directory, or install the plugin through the WordPress plugins screen
   directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Optionally configure the three fixes under Settings → Classic Block
   Editing for ACF (all three are enabled by default).

== Frequently Asked Questions ==

= Does this modify ACF's plugin files? =

No. It reads ACF's currently-registered script, writes a patched copy to
`wp-content/uploads/acf-classic-block-editing/`, and serves that copy instead
via the `script_loader_src` filter. ACF's own files are never written to.

= What happens when ACF releases an update? =

The cached patched copy is keyed by the source file's path, modification
time and size, so it is regenerated automatically the next time the editor
loads after an ACF update.

= What if the patch can't find the expected code? =

The plugin leaves the original ACF script completely untouched and displays
an admin notice, rather than guessing or applying a partial/incorrect patch.

== Changelog ==

= 4.5.0 =
* Renamed to "Rozmuar Classic Block Editing for Advanced Custom Fields" and
  changed the slug/text domain to `rozmuar-classic-block-editing-for-acf`,
  per the WordPress.org review team's note that a third-party integration
  needs a distinctive name of its own ahead of "... for Advanced Custom
  Fields" — "Classic Block Editing for Advanced Custom Fields" (4.4.0) still
  led with the ACF name once "for" was dropped. This is the permalink to be
  assigned for the plugin's WordPress.org listing. No functional changes.

= 4.4.1 =
* Corrected 4.4.0: the slug/text domain is `acf-classic-block-editing`,
  already assigned by WordPress.org, and was never meant to change — an
  in-progress edit briefly changed it to `classic-block-editing-for-acf`
  before this release. Reverted the Text Domain header, every
  `__()`/`esc_html_e()` domain argument, the cache directory, and the
  enqueued script/style handle names back to `acf-classic-block-editing`.
  The display name introduced in 4.4.0 is unaffected.

= 4.4.0 =
* Renamed the displayed plugin name from "ACF Classic Block Editing" to
  "Classic Block Editing for Advanced Custom Fields", per the WordPress.org
  review team's trademark note on the "ACF"-first name. The slug/text domain
  (`acf-classic-block-editing`), already assigned by WordPress.org, is
  unchanged. No functional changes.

= 4.3.0 =
* FIX 1b: type-guard ACF's block `.form` value in the runtime JS patch. ACF
  PRO ships `.form` as a boolean while its own bundle treats it as a string,
  which crashed every ACF block ("This block has encountered an error") and
  printed a stray "true" in the block sidebar once the iframe detection was
  neutralized. The mismatched value is now coerced to an empty string.
* FIX 2b: force `mode = 'edit'` when a block is capped to the classic UI, so
  the Edit/Preview toolbar button reappears (it is hidden whenever `mode`
  resolves to `"auto"`). Overridable via the
  `acf_classic_block_editing_forced_mode` filter.
* FIX 2c: also cap `api_version` for PHP block registrations, and move that
  adjustment out from behind an `acf_block_version >= 3` check that never
  passed for JSON-registered blocks.
* FIX 2d: cap `acf.blockVersion` / `acf.mode` in the raw `block.json`
  metadata (`block_type_metadata`, priority 5) before ACF reads it, so the
  client-side editor and the server agree and the classic toggle component
  is mounted instead of the Block Version 3 "Expanded Editor".
* The patched-script cache key now includes a patch-revision constant so
  plugin logic changes force a rebuild of the cached copy.
* The failed-patch admin notice now distinguishes Fix 1 from Fix 1b, and a
  partially patched copy is served when at least one patch applied.

= 4.0.1 =
* Shortened the readme short description to fit the 150-character limit.
* Removed "Compat" from the plugin name so the slug matches the already-used
  `acf-classic-block-editing` text domain (fixes a TextDomainMismatch check).

= 4.0.0 =
* Added cross-document companion fixes (repeater/flexible-content tooltips,
  select2 positioning, WYSIWYG/TinyMCE field, canvas styling) adapted from
  Block Edit Mode for ACF by Bakhodir Sharipov.
* Hardened the iframe-detection regex to tolerate different quoting styles.

= 3.0.0 =
* Switched the primary fix to a runtime patch of ACF's own iframe-detection
  function, which is the actual mechanism hiding the Edit/Preview toggle.

= 2.0.0 =
* Added capping of ACF's Block Version 3 down to Version 2.

= 1.0.0 =
* Initial release: block-editor canvas iframe compatibility bridge.

== Upgrade Notice ==

= 4.5.0 =
Renamed to "Rozmuar Classic Block Editing for Advanced Custom Fields"
(slug: rozmuar-classic-block-editing-for-acf) per WordPress.org's naming
review. No functional changes.

= 4.4.1 =
Corrects an in-progress 4.4.0 edit that briefly changed the slug/text domain;
it is back to acf-classic-block-editing, matching the assigned WordPress.org
slug. No action needed.

= 4.4.0 =
Displayed plugin name updated to comply with the ACF trademark. No
functional changes; the slug/folder name is unchanged.

= 4.3.0 =
Fixes a crash of all ACF blocks and restores the missing Edit/Preview toggle
by keeping the client-side block version in sync with the server.

= 4.0.0 =
Adds the companion fixes needed for repeater/flexible-content fields,
select2, and WYSIWYG editing to fully work inside the canvas iframe.
