Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How do I avoid getting “Restricted area” errors?
I’m almost there with a new plugin, all_pic, but am stumped.
How can I safely run an admin-side Ajax request in Textpattern 4.9+ from a plugin (Type 4), triggered by a blur() or change() event, to fetch dynamic field data — and avoid getting“Restricted area” errors?
// php
if(@txpinterface == 'admin') {
register_callback('all_pic','article');
register_callback('all_pic_css','admin_side','head_end');
register_callback('all_pic_js_config', 'admin_side', 'head_end');
register_callback('all_pic_js', 'admin_side', 'head_end');
register_callback('all_pic_ajax_get_thumbs', 'all_pic', 'get_thumbs');
//register_callback('all_pic_ajax_get_thumbs', 'admin-ajax', 'all_pic_get_thumbs');
}
function all_pic_ajax_get_thumbs() {
if (!is_logged_in()) {
exit('Not authorized');
}
$ids = gps('ids');
if (!$ids) {
exit('No IDs provided');
}
$idArray = explode(',', $ids);
echo all_pic_render_thumbs($idArray);
exit;
}
// js line 62 https://github.com/gizulor/all_pic/blob/main/all_pic.js
$thumbInputs.on('input', debounce(function() {
const $input = $(this);
const container = $input.next().find('.all_pics');
const value = $input.val().split(/[ ,]+/).map(s => s.trim()).filter(Boolean);
const currentIds = container.find('.all_pics__item').map(function() {
return this.className.replace(/.*id(\d+).*/, '$1');
}).get();
// Remove missing thumbs
currentIds.forEach(id => {
if (!value.includes(id)) {
container.find(`.id${id}`).remove();
}
});
const newIds = value.filter(id => !currentIds.includes(id));
if (!newIds.length) return;
// Fetch thumbs
$.ajax({
url: '/textpattern/index.php',
method: 'POST',
data: {
event: 'all_pic',
step: 'get_thumbs',
ids: newIds.join(',')
},
success: function(html) {
const $temp = $('<div>').html(html);
newIds.forEach(function(id) {
const $thumb = $temp.find(`.id${id}`);
if ($thumb.length) {
container.append($thumb);
} else {
console.warn(`No thumb found in Ajax for id ${id}`);
}
});
},
error: function(xhr) {
console.error('Ajax thumb fetch failed:', xhr.responseText);
}
});
}, 400));
all_pic
- In the Write panel, find and add images to the Article Image field or any specified custom field
- The default Images panel opens in a SideView, providing full search and edit capabilities
- Build gallery
shortcode
s for insertion into any textarea - Thumbnail previews, reordered via dragging
What started as an attempt to get bot_image_upload to work properly with multiple fields, branched off into a hacked-together but largely functional variant.
Since then I’ve had help from a friendly LLM (ChatGTP). I’m interested in everyones’ opinion on the code.
Offline
Re: How do I avoid getting “Restricted area” errors?
I think you should (at least) add _txp_token
to your data
, see e.g. l.598 of textpattern.js
.
Offline
Re: How do I avoid getting “Restricted area” errors?
etc wrote #340055:
I think you should (at least) add
_txp_token
to yourdata
, see e.g. l.598 oftextpattern.js
.
Thanks; on-it!
Offline
Re: How do I avoid getting “Restricted area” errors?
Can I be added to the Plugin Authors group?
Thanks!
Offline
Re: How do I avoid getting “Restricted area” errors?
giz wrote #340199:
Can I be added to the Plugin Authors group?
Please proceed to github.com/textpattern/textpattern.github.io/issues and fill out the paperwork (choose: ‘Register author prefix’ issue type), operators are standing by.
(Plus it lets me check the docs site updates are working as expected.)
Offline
Re: How do I avoid getting “Restricted area” errors?
giz wrote #340199:
Can I be added to the Plugin Authors group?
I presume you mean on the forum, as your ‘all’ prefix is already registered.
Edit: Done.
Last edited by Bloke (2025-08-15 20:58:12)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: How do I avoid getting “Restricted area” errors?
Thanks!
Offline