| @@ -79,8 +79,30 @@ | ||
| 79 | 79 | document.body.appendChild(button); |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | + // Same visibility logic as the chat widget: | |
| 84 | + // hide the floating button on the pattern selection screen (p=/pattern) | |
| 85 | + // and only show it when a specific template part is being edited. | |
| 86 | + function shouldShowPatternTranslateButton() { | |
| 87 | + const isSiteEditor = window.location.pathname.includes('site-editor.php'); | |
| 88 | + if (!isSiteEditor) { | |
| 89 | + return true; // Always allow outside Site Editor (for safety/future use) | |
| 90 | + } | |
| 91 | + | |
| 92 | + const urlParams = new URLSearchParams(window.location.search); | |
| 93 | + const pParam = urlParams.get('p'); | |
| 94 | + | |
| 95 | + // Do not show on: | |
| 96 | + // 1. No "p" parameter | |
| 97 | + // 2. p === '/pattern' (pattern chooser screen) | |
| 98 | + if (!pParam || pParam === '/pattern') { | |
| 99 | + return false; | |
| 100 | + } | |
| 101 | + | |
| 102 | + return true; | |
| 103 | + } | |
| 104 | + | |
| 83 | 105 | function getEditedPostContext() { |
| 84 | 106 | const store = select('core/edit-site'); |
| 85 | 107 | if (!store || typeof store.getEditedPostId !== 'function') { |
| 86 | 108 | return {}; |
| @@ -177,10 +199,12 @@ | ||
| 177 | 199 | if (!button) return; |
| 178 | 200 | |
| 179 | 201 | const { id, type } = getEditedPostContext(); |
| 180 | 202 | const isPart = id && type === 'wp_template_part'; |
| 181 | - button.disabled = !isPart; | |
| 182 | - button.style.display = isPart ? '' : 'none'; | |
| 203 | + const shouldShow = isPart && shouldShowPatternTranslateButton(); | |
| 204 | + | |
| 205 | + button.disabled = !shouldShow; | |
| 206 | + button.style.display = shouldShow ? '' : 'none'; | |
| 183 | 207 | } |
| 184 | 208 | |
| 185 | 209 | document.addEventListener('DOMContentLoaded', () => { |
| 186 | 210 | console.log('[AI Builder] Pattern translation script loaded'); |