fix(pay): break enqueue cycle that exhausted memory on the post editor

aksrt_icon_picker_assets() registers the icon-picker script as depending on
the caller's handle, so passing 'aksrt-pay-meta-box' already creates the
edge aksrt-icon-picker -> aksrt-pay-meta-box. Declaring the reverse on the
script and style closed a cycle, and WP_Dependencies' recursive resolver
never terminated, taking down every post editor and edit.php request.

Drop the reverse edge so the picker depends on the pay-meta script, not the
other way round, and contract-lock the direction.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Sonnet 4.6 committed 2026-09-24 20:40:30 +08:00
1 parent b94c820361
commit 592bfb4fa2
2 files changed
+13 -2

No files matched your search

+4 -2
View File
@@ -43,15 +43,17 @@ class ResourceMetaBox {
wp_enqueue_media(); wp_enqueue_media();
if (function_exists('aksrt_icon_picker_assets')) { if (function_exists('aksrt_icon_picker_assets')) {
// Declares aksrt-icon-picker -> aksrt-pay-meta-box; the reverse edge
// must not be added here or WP's resolver recurses until OOM.
aksrt_icon_picker_assets(['aksrt-pay-meta-box']); aksrt_icon_picker_assets(['aksrt-pay-meta-box']);
} }
$css = AKSRT_DIR . '/assets/css/admin/pay-meta-box.css'; $css = AKSRT_DIR . '/assets/css/admin/pay-meta-box.css';
$js = AKSRT_DIR . '/assets/js/admin-pay-meta-box.js'; $js = AKSRT_DIR . '/assets/js/admin-pay-meta-box.js';
if (is_file($css)) { if (is_file($css)) {
wp_enqueue_style('aksrt-pay-meta-box', AKSRT_URI . '/assets/css/admin/pay-meta-box.css', ['aksrt-icon-picker'], (string) filemtime($css)); wp_enqueue_style('aksrt-pay-meta-box', AKSRT_URI . '/assets/css/admin/pay-meta-box.css', ['aksrt-font-awesome'], (string) filemtime($css));
} }
if (is_file($js)) { if (is_file($js)) {
wp_enqueue_script('aksrt-pay-meta-box', AKSRT_URI . '/assets/js/admin-pay-meta-box.js', ['aksrt-icon-picker'], (string) filemtime($js), true); wp_enqueue_script('aksrt-pay-meta-box', AKSRT_URI . '/assets/js/admin-pay-meta-box.js', [], (string) filemtime($js), true);
} }
wp_localize_script('aksrt-pay-meta-box', 'aksrtPayMetaBox', [ wp_localize_script('aksrt-pay-meta-box', 'aksrtPayMetaBox', [
'buttonClasses' => DomainModel::DOWNLOAD_BUTTON_CLASSES, 'buttonClasses' => DomainModel::DOWNLOAD_BUTTON_CLASSES,
@@ -148,6 +148,15 @@ test('the post editor resource row mirrors the reference seven fields with icon
assert.equal(reindex('downloads', 'aksrt_pay[video_episode][1][title]', 9), 'aksrt_pay[video_episode][1][title]'); assert.equal(reindex('downloads', 'aksrt_pay[video_episode][1][title]', 9), 'aksrt_pay[video_episode][1][title]');
assert.match(setup, /'icon' => \['type' => 'string'\]/); assert.match(setup, /'icon' => \['type' => 'string'\]/);
// The icon picker registers itself as depending on the caller's handle, so the
// pay-meta script must NOT declare the icon-picker handle back: that cycle makes
// WP_Dependencies recurse until memory is exhausted on every post editor load.
const picker = read('inc/helpers/aksrt-icon-picker.php');
assert.match(picker, /array_merge\(\['jquery', 'aksrt-svg-sprite'\], \$deps\)/);
assert.match(meta, /aksrt_icon_picker_assets\(\['aksrt-pay-meta-box'\]\)/);
const payScript = meta.match(/wp_enqueue_script\('aksrt-pay-meta-box',[^\n]*\)/)[0];
assert.doesNotMatch(payScript, /aksrt-icon-picker/);
}); });
test('front submit paid-content prices and switch use the reference alignment rules', () => { test('front submit paid-content prices and switch use the reference alignment rules', () => {