| @@ -14,8 +14,23 @@ | ||
| 14 | 14 | if (!defined('ABSPATH')) { |
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | +/** | |
| 19 | + * Whether this section is rendered outside any settings form. | |
| 20 | + * | |
| 21 | + * On General Settings and Indexation Control the section sits inside | |
| 22 | + * #metaSyncGeneralSetting / #metaSyncSeoControlsForm, whose own save button | |
| 23 | + * posts these fields along with everything else. The standalone Instant | |
| 24 | + * Indexing page has no such form — its only button ("Save Post Types") posts | |
| 25 | + * metasync_post_types and ignores the credentials entirely — so a service | |
| 26 | + * account pasted or uploaded there could never be saved. In that context we | |
| 27 | + * render a dedicated Save button wired to its own AJAX endpoint. | |
| 28 | + * | |
| 29 | + * Callers opt in by setting $google_index_standalone before the include. | |
| 30 | + */ | |
| 31 | +$google_index_standalone = !empty($google_index_standalone); | |
| 32 | + | |
| 18 | 33 | ?> |
| 19 | 34 | |
| 20 | 35 | <div style="padding: 20px;"> |
| 21 | 36 | <!-- Requirements (Collapsible) --> |
| @@ -55,9 +70,9 @@ | ||
| 55 | 70 | <table class="form-table" style="margin-top: 0;"> |
| 56 | 71 | <tr> |
| 57 | 72 | <th scope="row" style="width: 200px;"> |
| 58 | 73 | <label for="google_index_service_account_json">Service Account JSON</label> |
| 59 | - <?php Metasync::render_tooltip_icon('google_index_service_account_json', 'Paste the private key file from a Google Cloud service account added to your Search Console property. This lets the plugin ask Google to crawl your pages. Treat it like a password — it\'s stored on your server and never shared.'); ?> | |
| 74 | + <?php Metasync::render_tooltip_icon('google_index_service_account_json', 'Paste the private key file from a Google Cloud service account added to your Search Console property. This lets the plugin ask Google to crawl your pages. Treat it like a password. It is stored on your server and never shared.'); ?> | |
| 60 | 75 | </th> |
| 61 | 76 | <td> |
| 62 | 77 | <textarea name="google_index_service_account_json" |
| 63 | 78 | id="google_index_service_account_json" |
| @@ -79,15 +94,37 @@ | ||
| 79 | 94 | |
| 80 | 95 | <tr> |
| 81 | 96 | <th scope="row"> |
| 82 | 97 | <label for="google_index_service_account_file">Upload JSON File</label> |
| 98 | + <?php Metasync::render_tooltip_icon('google_index_service_account_file', 'Upload the service account JSON key file you downloaded from Google Cloud instead of pasting it. The file fills in the Service Account JSON box above. It is only stored once you save.'); ?> | |
| 83 | 99 | </th> |
| 84 | 100 | <td> |
| 85 | - <input type="file" | |
| 86 | - name="google_index_service_account_file" | |
| 101 | + <input type="file" | |
| 102 | + name="google_index_service_account_file" | |
| 87 | 103 | id="google_index_service_account_file" |
| 88 | - accept=".json" | |
| 104 | + accept=".json,application/json" | |
| 89 | 105 | class="regular-text" /> |
| 106 | + | |
| 107 | + <!-- | |
| 108 | + Selected-file row. Hidden until a file is chosen; the admin | |
| 109 | + JS fills in the name and reveals it. "Remove" clears the | |
| 110 | + input and restores the textarea to whatever it held before | |
| 111 | + the file was read, so a mis-click does not destroy a saved | |
| 112 | + (redacted) configuration the user never meant to replace. | |
| 113 | + --> | |
| 114 | + <p id="google-index-selected-file" style="display:none;margin:8px 0 0;"> | |
| 115 | + <span class="dashicons dashicons-media-code" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> | |
| 116 | + <strong id="google-index-selected-file-name"></strong> | |
| 117 | + <button type="button" | |
| 118 | + id="google-index-remove-file" | |
| 119 | + class="button-link" | |
| 120 | + style="margin-left:8px;color:var(--dashboard-error, #b32d2e);text-decoration:none;" | |
| 121 | + aria-label="Remove the selected JSON file">× Remove</button> | |
| 122 | + </p> | |
| 123 | + | |
| 124 | + <!-- Inline validation feedback; replaces the old alert(). --> | |
| 125 | + <div id="google-index-file-messages" style="margin-top:8px;"></div> | |
| 126 | + | |
| 90 | 127 | <p class="description"> |
| 91 | 128 | Upload your service account JSON file. This will auto-populate the textarea above. |
| 92 | 129 | </p> |
| 93 | 130 | </td> |
| @@ -92,21 +129,54 @@ | ||
| 92 | 129 | </p> |
| 93 | 130 | </td> |
| 94 | 131 | </tr> |
| 95 | 132 | </table> |
| 96 | - | |
| 133 | + | |
| 97 | 134 | <!-- Action Buttons and Test Results --> |
| 98 | - <?php if ($is_configured): ?> | |
| 135 | + <?php if ($google_index_standalone): ?> | |
| 136 | + <!-- | |
| 137 | + Standalone Instant Indexing page only. The embedded contexts are | |
| 138 | + saved by their own form's save button, so adding a second one there | |
| 139 | + would give the page two competing save paths. | |
| 140 | + --> | |
| 99 | 141 | <div style="margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;"> |
| 100 | - <button type="button" | |
| 101 | - id="google-index-test-connection" | |
| 142 | + <?php wp_nonce_field('metasync_google_index_account', 'metasync_google_index_account_nonce'); ?> | |
| 143 | + <button type="button" | |
| 144 | + id="google-index-save-config" | |
| 145 | + class="button button-primary"> | |
| 146 | + <span class="dashicons dashicons-yes" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Save Configuration | |
| 147 | + </button> | |
| 148 | + | |
| 149 | + <?php if ($is_configured): ?> | |
| 150 | + <button type="button" | |
| 151 | + id="google-index-test-connection" | |
| 152 | + class="button button-secondary" | |
| 153 | + style="margin-left: 10px;"> | |
| 154 | + <span class="dashicons dashicons-yes" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Test Connection | |
| 155 | + </button> | |
| 156 | + | |
| 157 | + <button type="button" | |
| 158 | + id="google-index-clear-config" | |
| 159 | + class="button button-link-delete" | |
| 160 | + style="margin-left: 10px;"> | |
| 161 | + <span class="dashicons dashicons-trash" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Clear Configuration | |
| 162 | + </button> | |
| 163 | + <?php endif; ?> | |
| 164 | + | |
| 165 | + <div id="google-index-save-messages" style="margin-top: 15px;"></div> | |
| 166 | + <div id="google-index-test-results" style="margin-top: 15px;"></div> | |
| 167 | + </div> | |
| 168 | + <?php elseif ($is_configured): ?> | |
| 169 | + <div style="margin-top: 20px; padding-top: 15px; border-top: 1px solid #ddd;"> | |
| 170 | + <button type="button" | |
| 171 | + id="google-index-test-connection" | |
| 102 | 172 | class="button button-secondary"> |
| 103 | 173 | <span class="dashicons dashicons-yes" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Test Connection |
| 104 | 174 | </button> |
| 105 | - | |
| 106 | - <button type="button" | |
| 175 | + | |
| 176 | + <button type="button" | |
| 107 | 177 | id="google-index-clear-config" |
| 108 | - class="button button-link-delete" | |
| 178 | + class="button button-link-delete" | |
| 109 | 179 | style="margin-left: 10px;"> |
| 110 | 180 | <span class="dashicons dashicons-trash" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Clear Configuration |
| 111 | 181 | </button> |
| 112 | 182 | |