Skip to content

Commit a2fbd31

Browse files
authored
Merge pull request #48 from ProgressPlanner/develop
v1.5.0
2 parents 6a22f72 + 8e2f91b commit a2fbd31

File tree

7 files changed

+331
-323
lines changed

7 files changed

+331
-323
lines changed

aaa-option-optimizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Plugin Name: AAA Option Optimizer
88
* Plugin URI: https://joost.blog/plugins/aaa-option-optimizer/
99
* Description: Tracks autoloaded options usage and allows the user to optimize them.
10-
* Version: 1.4.0
10+
* Version: 1.5.0
1111
* License: GPL-3.0+
1212
* Author: Joost de Valk
1313
* Author URI: https://joost.blog/

js/admin-script.js

Lines changed: 73 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,13 @@ jQuery( document ).ready( function () {
7070
};
7171
options.serverSide = true;
7272
options.processing = true;
73-
( options.language = {
73+
options.language = {
7474
sZeroRecords: aaaOptionOptimizer.i18n.noAutoloadedButNotUsed,
75-
} ),
76-
( options.initComplete = function () {
77-
getBulkActionsForm( selector, [ 'autoload-off' ] ).call(
78-
this
79-
);
80-
this.api()
81-
.columns( 'source:name' )
82-
.every( setupColumnFilters );
83-
} );
75+
};
76+
options.initComplete = function () {
77+
getBulkActionsForm( selector, [ 'autoload-off' ] ).call( this );
78+
this.api().columns( 'source:name' ).every( setupColumnFilters );
79+
};
8480
options.order = [ [ 1, 'asc' ] ]; // Order by 2nd column, first column is checkbox.
8581
}
8682

@@ -107,9 +103,7 @@ jQuery( document ).ready( function () {
107103

108104
if ( selector === '#requested_do_not_exist_table' ) {
109105
options.ajax = {
110-
url:
111-
aaaOptionOptimizer.root +
112-
'aaa-option-optimizer/v1/options-that-do-not-exist',
106+
url: `${ aaaOptionOptimizer.root }aaa-option-optimizer/v1/options-that-do-not-exist`,
113107
headers: { 'X-WP-Nonce': aaaOptionOptimizer.nonce },
114108
type: 'GET',
115109
dataSrc: 'data',
@@ -120,9 +114,7 @@ jQuery( document ).ready( function () {
120114

121115
if ( selector === '#all_options_table' ) {
122116
options.ajax = {
123-
url:
124-
aaaOptionOptimizer.root +
125-
'aaa-option-optimizer/v1/all-options',
117+
url: `${ aaaOptionOptimizer.root }aaa-option-optimizer/v1/all-options`,
126118
headers: { 'X-WP-Nonce': aaaOptionOptimizer.nonce },
127119
type: 'GET',
128120
dataSrc: 'data',
@@ -237,7 +229,7 @@ jQuery( document ).ready( function () {
237229
name: 'size',
238230
data: 'size',
239231
searchable: false,
240-
render: ( data ) => '<span class="num">' + data + '</span>',
232+
render: ( data ) => `<span class="num">${ data }</span>`,
241233
},
242234
{
243235
name: 'autoload',
@@ -291,44 +283,31 @@ jQuery( document ).ready( function () {
291283
* @return {string} - The HTML for the value column.
292284
*/
293285
function renderValueColumn( row ) {
294-
const popoverContent =
295-
'<div id="popover_' +
296-
row.name +
297-
'" popover class="aaa-option-optimizer-popover">' +
298-
'<button class="aaa-option-optimizer-popover__close" popovertarget="popover_' +
299-
row.name +
300-
'" popovertargetaction="hide">X</button>' +
301-
'<p><strong>Value of <code>' +
302-
row.name +
303-
'</code></strong></p>' +
304-
'<pre>' +
305-
row.value +
306-
'</pre>' +
307-
'</div>';
286+
const popoverContent = `<div id="popover_${ row.name }" popover class="aaa-option-optimizer-popover">
287+
<button class="aaa-option-optimizer-popover__close" popovertarget="popover_${ row.name }" popovertargetaction="hide">X</button>
288+
<p><strong>Value of <code>${ row.name }</code></strong></p>
289+
<pre>${ row.value }</pre>
290+
</div>`;
308291

309292
const actions = [
310-
'<button class="button dashicon" popovertarget="popover_' +
311-
row.name +
312-
'"><span class="dashicons dashicons-search"></span>' +
313-
aaaOptionOptimizer.i18n.showValue +
314-
'</button>',
293+
`<button class="button dashicon" popovertarget="popover_${ row.name }">
294+
<span class="dashicons dashicons-search"></span>
295+
${ aaaOptionOptimizer.i18n.showValue }
296+
</button>`,
315297
popoverContent,
316298
row.autoload === 'no'
317-
? '<button class="button dashicon add-autoload" data-option="' +
318-
row.name +
319-
'"><span class="dashicons dashicons-plus"></span>' +
320-
aaaOptionOptimizer.i18n.addAutoload +
321-
'</button>'
322-
: '<button class="button dashicon remove-autoload" data-option="' +
323-
row.name +
324-
'"><span class="dashicons dashicons-minus"></span>' +
325-
aaaOptionOptimizer.i18n.removeAutoload +
326-
'</button>',
327-
'<button class="button button-delete delete-option" data-option="' +
328-
row.name +
329-
'"><span class="dashicons dashicons-trash"></span>' +
330-
aaaOptionOptimizer.i18n.deleteOption +
331-
'</button >',
299+
? `<button class="button dashicon add-autoload" data-option="${ row.name }">
300+
<span class="dashicons dashicons-plus"></span>
301+
${ aaaOptionOptimizer.i18n.addAutoload }
302+
</button>`
303+
: `<button class="button dashicon remove-autoload" data-option="${ row.name }">
304+
<span class="dashicons dashicons-minus"></span>
305+
${ aaaOptionOptimizer.i18n.removeAutoload }
306+
</button>`,
307+
`<button class="button button-delete delete-option" data-option="${ row.name }">
308+
<span class="dashicons dashicons-trash"></span>
309+
${ aaaOptionOptimizer.i18n.deleteOption }
310+
</button>`,
332311
];
333312

334313
return actions.join( '' );
@@ -342,13 +321,9 @@ jQuery( document ).ready( function () {
342321
* @return {string} - The HTML for the value column.
343322
*/
344323
function renderNonExistingOptionsColumn( row ) {
345-
return (
346-
'<button class="button button-primary create-option-false" data-option="' +
347-
row.name +
348-
'">' +
349-
aaaOptionOptimizer.i18n.createOptionFalse +
350-
'</button>'
351-
);
324+
return `<button class="button button-primary create-option-false" data-option="${ row.name }">
325+
${ aaaOptionOptimizer.i18n.createOptionFalse }
326+
</button>`;
352327
}
353328

354329
/**
@@ -359,31 +334,22 @@ jQuery( document ).ready( function () {
359334
* @return {string} - The HTML for the value column.
360335
*/
361336
function renderCheckboxColumn( row ) {
362-
return (
363-
'<label for="select-option-' +
364-
row.name +
365-
'">' +
366-
'<input type="checkbox" id="select-option-' +
367-
row.name +
368-
'" class="select-option" data-option="' +
369-
row.name +
370-
'">' +
371-
'</label>'
372-
);
337+
return `<label for="select-option-${ row.name }">
338+
<input type="checkbox" id="select-option-${ row.name }" class="select-option" data-option="${ row.name }">
339+
</label>`;
373340
}
374341

375342
jQuery( '#aaa-option-reset-data' ).on( 'click', function ( e ) {
376343
e.preventDefault();
377344
jQuery.ajax( {
378-
url: aaaOptionOptimizer.root + 'aaa-option-optimizer/v1/reset',
345+
url: `${ aaaOptionOptimizer.root }aaa-option-optimizer/v1/reset`,
379346
method: 'POST',
380347
beforeSend: ( xhr ) =>
381348
xhr.setRequestHeader( 'X-WP-Nonce', aaaOptionOptimizer.nonce ),
382349
success: (
383350
response // eslint-disable-line no-unused-vars
384351
) =>
385-
( window.location =
386-
window.location.href + '&tracking_reset=true' ),
352+
( window.location = `${ window.location.href }&tracking_reset=true` ),
387353
error: ( response ) =>
388354
console.error( 'Failed to reset tracking.', response ), // eslint-disable-line no-console
389355
} );
@@ -417,7 +383,7 @@ jQuery( document ).ready( function () {
417383
}
418384

419385
jQuery.ajax( {
420-
url: aaaOptionOptimizer.root + 'aaa-option-optimizer/v1/' + route,
386+
url: `${ aaaOptionOptimizer.root }aaa-option-optimizer/v1/${ route }`,
421387
method: 'POST',
422388
beforeSend: ( xhr ) =>
423389
xhr.setRequestHeader( 'X-WP-Nonce', aaaOptionOptimizer.nonce ),
@@ -427,7 +393,7 @@ jQuery( document ).ready( function () {
427393
error: ( response ) =>
428394
// eslint-disable-next-line no-console
429395
console.error(
430-
'Failed to ' + action + ' for ' + optionName + '.',
396+
`Failed to ${ action } for ${ optionName }.`,
431397
response
432398
),
433399
} );
@@ -456,25 +422,22 @@ jQuery( document ).ready( function () {
456422
const autoloadStatus = action === 'add-autoload' ? 'yes' : 'no';
457423
const buttonHTML =
458424
action === 'add-autoload'
459-
? '<button class="button dashicon remove-autoload" data-option="' +
460-
optionName +
461-
'"><span class="dashicons dashicons-minus"></span>' +
462-
aaaOptionOptimizer.i18n.removeAutoload +
463-
'</button>'
464-
: '<button class="button dashicon add-autoload" data-option="' +
465-
optionName +
466-
'"><span class="dashicons dashicons-plus"></span>' +
467-
aaaOptionOptimizer.i18n.addAutoload +
468-
'</button>';
469-
470-
jQuery( 'tr#' + rowId )
425+
? `<button class="button dashicon remove-autoload" data-option="${ optionName }">
426+
<span class="dashicons dashicons-minus"></span>
427+
${ aaaOptionOptimizer.i18n.removeAutoload }
428+
</button>`
429+
: `<button class="button dashicon add-autoload" data-option="${ optionName }">
430+
<span class="dashicons dashicons-plus"></span>
431+
${ aaaOptionOptimizer.i18n.addAutoload }
432+
</button>`;
433+
434+
jQuery( `tr#${ rowId }` )
471435
.find( 'td.autoload' )
472436
.text( autoloadStatus );
473-
const oldButton =
474-
'button.' +
475-
( action === 'add-autoload' ? 'add' : 'remove' ) +
476-
'-autoload';
477-
jQuery( 'tr#' + rowId + ' ' + oldButton ).replaceWith( buttonHTML );
437+
const oldButton = `button.${
438+
action === 'add-autoload' ? 'add' : 'remove'
439+
}-autoload`;
440+
jQuery( `tr#${ rowId } ${ oldButton }` ).replaceWith( buttonHTML );
478441
}
479442
}
480443

@@ -505,40 +468,31 @@ jQuery( document ).ready( function () {
505468
let selectOptions = '';
506469

507470
if ( options.includes( 'autoload-on' ) ) {
508-
selectOptions =
509-
'<option value="autoload-on">' +
510-
aaaOptionOptimizer.i18n.addAutoload +
511-
'</option>';
471+
selectOptions = `<option value="autoload-on">${ aaaOptionOptimizer.i18n.addAutoload }</option>`;
512472
}
513473

514474
if ( options.includes( 'autoload-off' ) ) {
515-
selectOptions +=
516-
'<option value="autoload-off">' +
517-
aaaOptionOptimizer.i18n.removeAutoload +
518-
'</option>';
475+
selectOptions += `<option value="autoload-off">${ aaaOptionOptimizer.i18n.removeAutoload }</option>`;
519476
}
520477

521478
const select = jQuery(
522-
'<select class="aaaoo-bulk-select"><option value="">' +
523-
aaaOptionOptimizer.i18n.bulkActions +
524-
selectOptions +
525-
'</option><option value="delete">' +
526-
aaaOptionOptimizer.i18n.delete +
527-
'</option></select>'
479+
`<select class="aaaoo-bulk-select">
480+
<option value="">${ aaaOptionOptimizer.i18n.bulkActions }</option>
481+
${ selectOptions }
482+
<option value="delete">${ aaaOptionOptimizer.i18n.delete }</option>
483+
</select>`
528484
);
529485

530486
const button = jQuery(
531-
'<button type="submit" class="button aaaoo-apply-bulk-action" data-table="' +
532-
selector +
533-
'">' +
534-
aaaOptionOptimizer.i18n.apply +
535-
'</button>'
487+
`<button type="submit" class="button aaaoo-apply-bulk-action" data-table="${ selector }">
488+
${ aaaOptionOptimizer.i18n.apply }
489+
</button>`
536490
);
537491

538492
form.append( select, button );
539493

540494
// Add the form to the .dt-start cell
541-
container.find( '.dt-layout-cell.dt-start ' ).prepend( form );
495+
container.find( '.dt-layout-cell.dt-layout-start' ).prepend( form );
542496

543497
// Move .dt-length to .dt-layout-cell.dt-end
544498
// const lengthSelector = container.find(".dt-length"); // same as div.dt-length
@@ -558,14 +512,14 @@ jQuery( document ).ready( function () {
558512
const button = jQuery( this );
559513
const select = jQuery( button ).siblings( '.aaaoo-bulk-select' );
560514
const bulkAction = select.val();
561-
const table = jQuery( button.data( 'table' ) );
562-
const selectedOptions = table.find( 'input.select-option:checked' );
563515

564516
if ( ! bulkAction ) {
565517
alert( aaaOptionOptimizer.i18n.noBulkActionSelected ); // eslint-disable-line no-alert
566518
return;
567519
}
568520

521+
const table = jQuery( button.data( 'table' ) );
522+
const selectedOptions = table.find( 'input.select-option:checked' );
569523
if ( selectedOptions.length === 0 ) {
570524
alert( aaaOptionOptimizer.i18n.noOptionsSelected ); // eslint-disable-line no-alert
571525
return;
@@ -579,10 +533,12 @@ jQuery( document ).ready( function () {
579533
),
580534
};
581535

582-
if ( bulkAction === 'delete' ) {
583-
endpoint = 'delete-options';
584-
} else {
585-
endpoint = 'set-autoload-options';
536+
const endpoint =
537+
'delete' === bulkAction
538+
? 'delete-options'
539+
: 'set-autoload-options';
540+
541+
if ( bulkAction !== 'delete' ) {
586542
requestData.autoload =
587543
bulkAction === 'autoload-on' ? 'yes' : 'no';
588544
}

js/vendor/datatables.min.css

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vendor/datatables.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

known-plugins/known-plugins.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
"name": "Loginizer",
112112
"option_prefixes": ["loginizer_"]
113113
},
114+
"mainwp": {
115+
"name": "MainWP (Child or Dashboard)",
116+
"option_prefixes": ["mainwp_"]
117+
},
114118
"multibanco-ifthen-software-gateway-for-woocommerce": {
115119
"name": "Multibanco, MB WAY, Credit card, Apple Pay, Google Pay, Payshop, Cofidis Pay, and PIX (ifthenpay) for WooCommerce",
116120
"option_prefixes": ["cofidispay_ifthen_", "creditcard_ifthen_", "gateway_ifthen_", "mbway_ifthen_", "multibanco_ifthen_", "payshop_"]
@@ -171,6 +175,10 @@
171175
"name": "Simple WooCommerce Order Approval",
172176
"option_prefixes": ["swoa_"]
173177
},
178+
"slicewp_": {
179+
"name": "SliceWP Affiliates",
180+
"option_prefixes": ["slicewp_"]
181+
},
174182
"updraft": {
175183
"name": "Updraft Plus",
176184
"option_prefixes": ["updraft_", "updraftplus_"]
@@ -193,7 +201,7 @@
193201
},
194202
"woocommerce": {
195203
"name": "WooCommerce",
196-
"option_prefixes": ["wc_", "_transient__woocommerce_", "woocommerce_"]
204+
"option_prefixes": ["wc_", "_transient__woocommerce_", "woocommerce_", "wccom-"]
197205
},
198206
"woocommerce-max-quantity": {
199207
"name": "Maximum Quantity for WooCommerce Shops",

0 commit comments

Comments
 (0)