PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / trunk
MxChat – AI Chatbot & Content Generation for WordPress vtrunk
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | js/knowledge-processing.js +124 -1 3.2.4trunk View file →
@@ -1929,9 +1929,9 @@
1929 1929 const sourceHtml = entry.has_link
1930 1930 ? '<a href="' + entry.source_url + '" target="_blank" style="color: var(--mxch-primary); text-decoration: none;"><span class="dashicons dashicons-external" style="font-size: 14px;"></span> View</a>'
1931 1931 : '<span style="color: var(--mxch-text-muted);">Manual</span>';
1932 1932
1933 - const deleteUrl = mxchatAdmin.admin_url + 'admin-post.php?action=mxchat_delete_prompt&id=' + entry.id + '&_wpnonce=' + entry.delete_nonce;
1933 + const deleteUrl = mxchatAdmin.admin_url + 'admin-post.php?action=mxchat_delete_prompt&id=' + entry.id + '&bot_id=' + encodeURIComponent(mxchatAdmin.bot_id || 'default') + '&_wpnonce=' + entry.delete_nonce;
1934 1934
1935 1935 // Check if content needs expand button (content longer than preview)
1936 1936 const needsExpand = entry.content_length > entry.preview_length;
1937 1937
@@ -2271,6 +2271,129 @@
2271 2271 $(document).on('DOMNodeInserted', function(e) {
2272 2272 if ($(e.target).hasClass('notice') && $(e.target).hasClass('is-dismissible')) {
2273 2273 setTimeout(initDismissibleNotices, 10);
2274 2274 }
2275 + });
2276 +
2277 + // ========================================
2278 + // CUSTOM META-KEY DISCOVERY PICKER (plan-mxchat-20260709-fe8e4e)
2279 + // Mirror the ACF picker's discover-and-click UX for non-ACF post meta: scan
2280 + // published content for meta keys, render clickable chips, and append chosen
2281 + // keys into the existing whitelist textarea (its autosave then persists them).
2282 + // ========================================
2283 + (function() {
2284 + var $scanBtn = $('#mxchat-scan-meta-btn');
2285 + if (!$scanBtn.length) { return; }
2286 +
2287 + var $results = $('#mxchat-meta-scan-results');
2288 + var $textarea = $('#mxchat_custom_meta_whitelist');
2289 + var $internal = $('#mxchat-scan-internal');
2290 + var $label = $scanBtn.find('.mxchat-scan-label');
2291 + var defaultLabel = $label.text();
2292 +
2293 + function currentKeys() {
2294 + return ($textarea.val() || '')
2295 + .split('\n')
2296 + .map(function(k) { return k.trim(); })
2297 + .filter(function(k) { return k.length; });
2298 + }
2299 +
2300 + function addKey(key) {
2301 + var keys = currentKeys();
2302 + if (keys.indexOf(key) !== -1) { return false; }
2303 + keys.push(key);
2304 + $textarea.val(keys.join('\n'));
2305 + // Fire the existing autosave (bound on 'change' in mxchat-admin.js).
2306 + $textarea.trigger('change');
2307 + return true;
2308 + }
2309 +
2310 + function escapeHtml(s) {
2311 + return String(s).replace(/[&<>"']/g, function(c) {
2312 + return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
2313 + });
2314 + }
2315 +
2316 + function humanize(key) {
2317 + var h = key.replace(/^_+/, '').replace(/[_-]+/g, ' ').trim();
2318 + return h.length ? h.charAt(0).toUpperCase() + h.slice(1) : key;
2319 + }
2320 +
2321 + function renderChips(keys) {
2322 + if (!keys || !keys.length) {
2323 + $results.html('<p class="mxchat-meta-scan-empty">' +
2324 + 'No custom meta keys found on your published content. Try enabling internal keys, or add keys manually below.' +
2325 + '</p>');
2326 + return;
2327 + }
2328 + var existing = currentKeys();
2329 + var html = '<div class="mxchat-meta-chip-grid">';
2330 + keys.forEach(function(item) {
2331 + var already = existing.indexOf(item.key) !== -1;
2332 + html += '<button type="button" class="mxchat-meta-chip' + (already ? ' is-added' : '') +
2333 + '" data-key="' + escapeHtml(item.key) + '"' + (already ? ' aria-pressed="true"' : '') + '>' +
2334 + '<span class="mxchat-meta-chip-main">' +
2335 + '<span class="mxchat-meta-chip-name">' + escapeHtml(humanize(item.key)) + '</span>' +
2336 + '<span class="mxchat-meta-chip-key">' + escapeHtml(item.key) + '</span>' +
2337 + '</span>' +
2338 + '<span class="mxchat-meta-chip-meta">on ' + item.count + ' post' + (item.count === 1 ? '' : 's') +
2339 + (item.sample ? ' · e.g. ' + escapeHtml(item.sample) : '') + '</span>' +
2340 + '<span class="mxchat-meta-chip-tick">' + (already ? '✓ Added' : '+ Add') + '</span>' +
2341 + '</button>';
2342 + });
2343 + html += '</div>';
2344 + $results.html(html);
2345 + }
2346 +
2347 + $scanBtn.on('click', function() {
2348 + var nonce = $scanBtn.data('nonce') ||
2349 + (window.mxchatAdmin && mxchatAdmin.settings_nonce) || '';
2350 + var ajaxUrl = (window.mxchatAdmin && (mxchatAdmin.ajax_url || mxchatAdmin.ajaxurl)) ||
2351 + window.ajaxurl || '/wp-admin/admin-ajax.php';
2352 +
2353 + $scanBtn.prop('disabled', true);
2354 + $label.text('Scanning…');
2355 + $results.html('<p class="mxchat-meta-scan-loading">Scanning your content for meta keys…</p>');
2356 +
2357 + $.post(ajaxUrl, {
2358 + action: 'mxchat_scan_custom_meta_keys',
2359 + _ajax_nonce: nonce,
2360 + include_internal: $internal.is(':checked') ? '1' : '0'
2361 + }).done(function(resp) {
2362 + if (resp && resp.success && resp.data && resp.data.keys) {
2363 + renderChips(resp.data.keys);
2364 + } else {
2365 + var msg = (resp && resp.data && resp.data.message) ? resp.data.message : 'Scan failed. Please try again.';
2366 + $results.html('<p class="mxchat-meta-scan-empty">' + escapeHtml(msg) + '</p>');
2367 + }
2368 + }).fail(function() {
2369 + $results.html('<p class="mxchat-meta-scan-empty">Scan request failed. Please try again.</p>');
2370 + }).always(function() {
2371 + $scanBtn.prop('disabled', false);
2372 + $label.text(defaultLabel);
2373 + });
2374 + });
2375 +
2376 + // Chip click -> add the raw key to the whitelist textarea (dedup) + autosave.
2377 + $results.on('click', '.mxchat-meta-chip', function() {
2378 + var $chip = $(this);
2379 + if ($chip.hasClass('is-added')) { return; }
2380 + var key = String($chip.data('key'));
2381 + if (addKey(key)) {
2382 + $chip.addClass('is-added').attr('aria-pressed', 'true');
2383 + $chip.find('.mxchat-meta-chip-tick').text('✓ Added');
2384 + }
2385 + });
2386 + })();
2387 +
2388 + // ========================================
2389 + // VIDEO CARDS — threshold follows the master switch (plan f52492)
2390 + // ========================================
2391 + // Presentation only. The server gate does NOT consult the threshold when
2392 + // the switch is off, so hiding the field never changes behavior — it just
2393 + // stops the page offering a number that is currently inert. Mirrors the
2394 + // YouTube import form's own show/hide idiom on this same page. Autosave is
2395 + // untouched: both fields keep their own change handler in mxchat-admin.js.
2396 + $('#mxchat_video_embed_enabled').on('change', function() {
2397 + $('#mxchat-video-embed-threshold-field').toggle($(this).is(':checked'));
2275 2398 });
2276 2399 });