@@ -135,11 +135,6 @@ public static function render_page() {
135135 <?php $ sql_queries = self ::recreate_indices_sql (); ?>
136136 <pre id="crp-indices-sql"><code><?php echo implode ( "\n" , array_map ( 'esc_html ' , $ sql_queries ) ); ?> </code></pre>
137137 </div>
138- <script>
139- jQuery(document).ready(function($) {
140- crpAddCopyButton('crp-indices-sql');
141- });
142- </script>
143138 <?php wp_nonce_field ( 'crp-tools-settings ' ); ?>
144139 </form>
145140 </div>
@@ -203,62 +198,6 @@ public static function render_page() {
203198 <p id="crp-migration-status"></p>
204199 </div>
205200 <?php wp_nonce_field ( 'crp_migrate_meta_nonce ' , 'crp_migrate_meta_nonce ' ); ?>
206- <script>
207- jQuery(document).ready(function($) {
208- var lastId = 0;
209- var limit = <?php echo absint ( self ::BATCH_SIZE ); ?> ;
210- var totalMigrated = 0;
211-
212- $('#crp_migrate_meta').on('click', function() {
213- $(this).prop('disabled', true);
214- $('#crp-migration-progress').show();
215- migrateBatch();
216- });
217-
218- function migrateBatch() {
219- $.ajax({
220- url: ajaxurl,
221- type: 'POST',
222- data: {
223- action: 'crp_migrate_meta',
224- security: $('#crp_migrate_meta_nonce').val(),
225- last_id: lastId,
226- limit: limit
227- },
228- success: function(response) {
229- if (response.success) {
230- totalMigrated += response.data.migrated;
231- $('#crp-migration-status').text(response.data.message);
232- if (response.data.last_id !== undefined) {
233- lastId = response.data.last_id;
234- }
235- if (response.data.last_id !== undefined) {
236- undoLastId = response.data.last_id;
237- }
238- if (response.data.complete) {
239- $('#crp-migration-bar').css('width', '100%');
240- $('#crp_migrate_meta').text('<?php esc_html_e ( 'Migration Complete ' , 'contextual-related-posts ' ); ?> ').prop('disabled', true);
241- setTimeout(function() {
242- location.reload();
243- }, 2000);
244- } else {
245- var progress = Math.min((totalMigrated / (totalMigrated + response.data.remaining)) * 100, 100);
246- $('#crp-migration-bar').css('width', progress + '%');
247- migrateBatch();
248- }
249- } else {
250- $('#crp-migration-status').text('<?php esc_html_e ( 'Migration failed. Please try again. ' , 'contextual-related-posts ' ); ?> ');
251- $('#crp_migrate_meta').prop('disabled', false);
252- }
253- },
254- error: function() {
255- $('#crp-migration-status').text('<?php esc_html_e ( 'Migration failed. Please try again. ' , 'contextual-related-posts ' ); ?> ');
256- $('#crp_migrate_meta').prop('disabled', false);
257- }
258- });
259- }
260- });
261- </script>
262201 </div>
263202 </div>
264203 <?php elseif ( get_option ( 'crp_meta_migration_done ' , false ) ) : ?>
@@ -289,59 +228,6 @@ function migrateBatch() {
289228 <p id="crp-undo-status"></p>
290229 </div>
291230 <?php wp_nonce_field ( 'crp_undo_migrate_meta_nonce ' , 'crp_undo_migrate_meta_nonce ' ); ?>
292- <script>
293- jQuery(document).ready(function($) {
294- var undoLastId = 0;
295- var undoLimit = <?php echo absint ( self ::BATCH_SIZE ); ?> ;
296- var totalUndone = 0;
297-
298- $('#crp_undo_migration').on('click', function() {
299- if (!confirm('<?php esc_html_e ( 'Are you sure you want to undo the migration? This will revert to the old array storage. ' , 'contextual-related-posts ' ); ?> ')) {
300- return;
301- }
302- $(this).prop('disabled', true);
303- $('#crp-undo-progress').show();
304- undoBatch();
305- });
306-
307- function undoBatch() {
308- $.ajax({
309- url: ajaxurl,
310- type: 'POST',
311- data: {
312- action: 'crp_undo_migrate_meta',
313- security: $('#crp_undo_migrate_meta_nonce').val(),
314- last_id: undoLastId,
315- limit: undoLimit
316- },
317- success: function(response) {
318- if (response.success) {
319- totalUndone += response.data.undone;
320- $('#crp-undo-status').text(response.data.message);
321- if (response.data.complete) {
322- $('#crp-undo-bar').css('width', '100%');
323- $('#crp_undo_migration').text('<?php esc_html_e ( 'Undo Complete ' , 'contextual-related-posts ' ); ?> ').prop('disabled', true);
324- setTimeout(function() {
325- location.reload();
326- }, 2000);
327- } else {
328- var progress = Math.min((totalUndone / (totalUndone + response.data.remaining)) * 100, 100);
329- $('#crp-undo-bar').css('width', progress + '%');
330- undoBatch();
331- }
332- } else {
333- $('#crp-undo-status').text('<?php esc_html_e ( 'Undo failed. Please try again. ' , 'contextual-related-posts ' ); ?> ');
334- $('#crp_undo_migration').prop('disabled', false);
335- }
336- },
337- error: function() {
338- $('#crp-undo-status').text('<?php esc_html_e ( 'Undo failed. Please try again. ' , 'contextual-related-posts ' ); ?> ');
339- $('#crp_undo_migration').prop('disabled', false);
340- }
341- });
342- }
343- });
344- </script>
345231 </div>
346232 </div>
347233 <?php endif ; ?>
@@ -509,6 +395,8 @@ public function admin_enqueue_scripts( $hook ) {
509395 $ screen = get_current_screen ();
510396
511397 if ( $ this ->parent_id === $ screen ->id || $ this ->parent_id === $ hook ) {
398+ $ file_prefix = ( defined ( 'SCRIPT_DEBUG ' ) && SCRIPT_DEBUG ) ? '' : '.min ' ;
399+
512400 wp_enqueue_script ( 'crp-admin-js ' );
513401 wp_enqueue_style ( 'crp-admin-ui-css ' );
514402 wp_enqueue_style ( 'wp-spinner ' );
@@ -523,6 +411,28 @@ public function admin_enqueue_scripts( $hook ) {
523411 ),
524412 )
525413 );
414+
415+ wp_enqueue_script (
416+ 'crp-tools-page ' ,
417+ WZ_CRP_PLUGIN_URL . "includes/admin/js/tools-page {$ file_prefix }.js " ,
418+ array ( 'jquery ' ),
419+ WZ_CRP_VERSION ,
420+ true
421+ );
422+ wp_localize_script (
423+ 'crp-tools-page ' ,
424+ 'crpToolsPage ' ,
425+ array (
426+ 'batchSize ' => self ::BATCH_SIZE ,
427+ 'strings ' => array (
428+ 'migrationComplete ' => __ ( 'Migration Complete ' , 'contextual-related-posts ' ),
429+ 'migrationFailed ' => __ ( 'Migration failed. Please try again. ' , 'contextual-related-posts ' ),
430+ 'undoComplete ' => __ ( 'Undo Complete ' , 'contextual-related-posts ' ),
431+ 'undoFailed ' => __ ( 'Undo failed. Please try again. ' , 'contextual-related-posts ' ),
432+ 'confirmUndo ' => __ ( 'Are you sure you want to undo the migration? This will revert to the old array storage. ' , 'contextual-related-posts ' ),
433+ ),
434+ )
435+ );
526436 }
527437 }
528438
0 commit comments