pre_fields` * keeps working. A meta box's `$post_id` is the real post id — * preserveProData($data, $post_id) reads get_post_meta((int) $post_id), which * silently did nothing when it was given the storage key (review 3.3). * * The bridge is PERMANENT, not a coexistence measure: after Stage C retires * Codestar, `csf_{unique}_save` is still the filter the free plugin uses to * protect Pro keys during a licence lapse (3.2), so one method keeps serving * both. * * @package BFields */ if (!defined('ABSPATH')) { exit; } if (!function_exists('bfields_bridge_csf_hooks')) { /** * Mirror a screen's bfields_* save hooks onto their csf_* twins. * * Called by the compatibility layer for every key it registers, so a host * that registers natively does not pay for a bridge it does not use. * * @param string $unique Storage key. */ function bfields_bridge_csf_hooks($unique) { static $bridged = array(); if (isset($bridged[$unique])) { return; } $bridged[$unique] = true; // The kind is read when the hook FIRES, not now: createSection() may // run before createMetabox() (Registry::section() makes a placeholder // options screen until then). $csf_args = static function ($data, array $context) use ($unique): array { $instance = \BFields\Compat\Instance::for_key($unique); if ('metabox' === $instance->kind) { return array($data, isset($context[0]) ? (int) $context[0] : 0, $instance); } return array($data, $instance); }; add_filter("bfields_{$unique}_save", static function ($data, ...$context) use ($unique, $csf_args) { return apply_filters_ref_array("csf_{$unique}_save", $csf_args($data, $context)); }, 10, 3); foreach (array('save_before', 'saved', 'save_after') as $event) { add_action("bfields_{$unique}_{$event}", static function ($data, ...$context) use ($unique, $event, $csf_args) { do_action_ref_array("csf_{$unique}_{$event}", $csf_args($data, $context)); }, 10, 3); } } }