public static function assets( $hook ) { if ( ! in_array( $hook, [ 'post.php', 'post-new.php' ], true ) ) { return; } $screen = get_current_screen(); if ( ! $screen || 'branch' !== $screen->post_type ) { return; } wp_enqueue_script( 'jquery' ); $js = <<<'JS' jQuery(function($) { var $app = $('#bmm-app'); if (!$app.length) { return; } var branchId = $app.data('branch'); var nonce = $('#bmm_nonce').val() || ''; var $rows = $('#bmm-rows'); function request(action, data) { data = data || {}; data.action = action; data.nonce = nonce; data.branch_id = branchId; return $.ajax({ url: window.ajaxurl, type: 'POST', dataType: 'json', data: data }); } function showError(xhr, status, error) { var message = 'خطا در ارتباط با سرور.'; if (xhr && xhr.responseText) { message += '
' + $('
').text(xhr.responseText).html() + ''; } else if (error) { message += '
' + $('
').text(error).html() + ''; } $rows.html(message); } function loadRows() { $rows.text('در حال بارگذاری...'); request('bmm_branch_rows', {}) .done(function(res) { if (res && res.success && res.data && typeof res.data.html !== 'undefined') { $rows.html(res.data.html); } else { $rows.text('پاسخ سرور نامعتبر است: ' + JSON.stringify(res)); } }) .fail(showError); } $('#bmm-search-btn').on('click', function() { var term = $('#bmm-search').val().trim(); if (term.length < 2) { $('#bmm-search-results').text('حداقل دو حرف وارد کنید.'); return; } $('#bmm-search-results').text('در حال جستجو...'); request('bmm_search_products', { term: term }) .done(function(res) { if (!res || !res.success || !res.data || !res.data.items) { $('#bmm-search-results').text('خطا در جستجوی محصولات.'); return; } var $list = $('
'); res.data.items.forEach(function(item) { var $line = $('
').css('padding', '6px 0'); $('').text(item.title + ' (#' + item.id + ') ').appendTo($line); $('