commit
d1cb997034
1 changed files with 48 additions and 0 deletions
@ -0,0 +1,48 @@
|
||||
<?php |
||||
/** |
||||
* Plugin Name: Aldine catalog toggle fix |
||||
* Description: Adds the missing book_id to Aldine's "In Catalog" AJAX request on Network Admin > Sites. |
||||
*/ |
||||
|
||||
add_action( 'admin_print_footer_scripts', function () { |
||||
if ( ! is_network_admin() || ( $GLOBALS['pagenow'] ?? '' ) !== 'sites.php' ) { |
||||
return; |
||||
} |
||||
?> |
||||
<script id="aldine-catalog-fix"> |
||||
(function () { |
||||
var lastBookId = null; |
||||
console.debug('[aldine-fix] loaded'); |
||||
|
||||
function remember(ev) { |
||||
var el = ev.target; |
||||
if (!el || !el.classList || !el.classList.contains('in-catalog')) { return; } |
||||
var row = el.closest('tr'); |
||||
var cb = row ? row.querySelector('input[name="allblogs[]"], th.check-column input[type="checkbox"]') : null; |
||||
lastBookId = cb ? cb.value : null; |
||||
console.debug('[aldine-fix] ' + ev.type + ' on in-catalog, book_id =', lastBookId); |
||||
} |
||||
// Capture phase, several events, so we run before Aldine's handler whatever it listens to. |
||||
['mousedown', 'keydown', 'click', 'change'].forEach(function (t) { |
||||
document.addEventListener(t, remember, true); |
||||
}); |
||||
|
||||
// Patch at the XHR level so it works whichever copy of jQuery Aldine uses. |
||||
var origSend = XMLHttpRequest.prototype.send; |
||||
XMLHttpRequest.prototype.send = function (body) { |
||||
if (typeof body === 'string' |
||||
&& body.indexOf('action=pressbooks_aldine_update_catalog') !== -1 |
||||
&& !/(^|&)book_id=\d+/.test(body)) { |
||||
if (lastBookId) { |
||||
body += '&book_id=' + encodeURIComponent(lastBookId); |
||||
console.debug('[aldine-fix] added book_id', lastBookId); |
||||
} else { |
||||
console.warn('[aldine-fix] catalog request seen but no book_id captured'); |
||||
} |
||||
} |
||||
return origSend.call(this, body); |
||||
}; |
||||
})(); |
||||
</script> |
||||
<?php |
||||
}, 99 ); |
||||
Loading…
Reference in new issue