| @@ -2272,116 +2272,5 @@ | ||
| 2272 | 2272 | if ($(e.target).hasClass('notice') && $(e.target).hasClass('is-dismissible')) { |
| 2273 | 2273 | setTimeout(initDismissibleNotices, 10); |
| 2274 | 2274 | } |
| 2275 | 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 { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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 | 2276 | }); |