From 6845ffaa75b87390fe5b516c5200735ba2856e5d Mon Sep 17 00:00:00 2001 From: Alex Sirota Date: Tue, 5 Nov 2024 04:57:50 -0500 Subject: [PATCH] Continue to sync playground-ready with newest PRs on main (#129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Prevent Recursion on certain Host name patterns (#69) --------- Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> * Playground ready updating into main (#71) * Update blueprint.json Switching to default theme of 2022 to support minimum WP Playground support for WordPress version as 5.9.9 Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> * Switching blueprint.json to 2022 theme Signed-off-by: Alex Sirota --------- Signed-off-by: Alex Sirota Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> * `Add New Plugin`: Remove 'Featured' and 'Favorites' tabs when API rewrite is enabled. (#80) * Add class for overriding plugins screens. * Remove unused tabs when API rewrite is enabled. * `Add New Theme`: Remove 'Favorites' filter tab when API rewrite is enabled. (#82) * Add class for overriding themes screens. * Hide unsupported filters. * Redirect unsupported filters to `theme-install.php`. --------- Signed-off-by: Alex Sirota Co-authored-by: Alex Sirota * Add PHPUnit. (#87) * Add PHPUnit scaffolding. * Add Composer files for dependencies and test script. * Add `.gitignore`. * Add sample test for `Admin_Settings::get_setting()`. * Add PHP 8.3 to the test matrix. * Add `.cache/*` to `.gitignore`. * Limit testing to PHP 7.4 (minimum) and 8.3 (latest). * `Plugins Screens`: Initialize in `Controller::__construct()`. (#89) * `Workflows`: Fix PHP version and add more workflow triggers. (#92) * Fix PHP version. * Add `push` and `workflow_dispatch` workflow triggers. * `Tests`: Ensure options are not set when tests run. (#95) * Introduce a test constant. * Don't initialize when the tests are running. * Use a new object for testing `Admin_Settings::get_setting()`. * Warning when debug-aspire-update.log doesnt exist (#109) * `Tests`: Add default coverage settings. (#97) * Improve I18N Issues Based on version 0.5 (#104) * Fixes Settings not getting saved when rewrites were turned off (#108) * Add French Translation (#105) * I18n fr fr (#113) * Translations loading fix112 (#114) * Add French translations. * load any available translations with code in the plugin * #110 (#116) Fixes #110 * Add nonce verification and sanitize `$_REQUEST/$_GET` values. (#115) Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com> * Added German Translation (#111) * added German translation * added gitignore for .DS_Store Signed-off-by: Harikrishnan R * Voltron has landed. (#117) The Voltron has landed. See if you can find where. * `Admin Settings`: Delete all settings when the plugin is uninstalled. (#118) * `Admin Settings`: Add multisite-safe deletion of all settings. * Delete all settings when the plugin is uninstalled. * add multisite support (#102) * accidentally deleted (#124) Fixed typo in code deleted when addressing #102 * Add `.editorconfig`. (#123) * create zip with each new tagged release (#121) * create zip with each new tagged release * update .gitattributes * Cleanup after `.editorconfig` was added to the repository. (#126) * Add coding standard. (#127) * Add Coding Standard. * Add PHPCS cache directory. * Coding Standards: Apply PHPCBF to codebase. * Coding Standards: Add GitHub workflow. --------- Signed-off-by: Alex Sirota Co-authored-by: Alex Sirota --------- Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> Signed-off-by: Alex Sirota Signed-off-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Signed-off-by: Harikrishnan R Co-authored-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> Co-authored-by: Alex Lion Co-authored-by: Sébastien SERRE Co-authored-by: Harikrishnan R Co-authored-by: Andy Fragen --- .cache/.gitkeep | 0 .github/workflows/coding-standards.yml | 85 ++++ .gitignore | 3 + assets/css/aspire-update.css | 127 ++--- assets/js/aspire-update.js | 480 +++++++++--------- assets/playground/blueprint.json | 110 ++-- composer.json | 13 + composer.lock | 400 ++++++++++++++- includes/autoload.php | 2 +- includes/class-admin-settings.php | 138 ++--- includes/class-api-rewrite.php | 6 +- includes/class-controller.php | 4 +- includes/class-debug.php | 6 +- includes/class-plugins-screens.php | 6 +- includes/class-themes-screens.php | 14 +- languages/AspireUpdate-de_DE.I10n.php | 46 +- languages/AspireUpdate-zh_TW.l10n.php | 4 +- phpcs.xml.dist | 61 +++ readme.txt | 2 +- .../AdminSettings_GetSettingTest.php | 4 +- tests/bootstrap.php | 4 +- 21 files changed, 1049 insertions(+), 466 deletions(-) create mode 100644 .cache/.gitkeep create mode 100644 .github/workflows/coding-standards.yml create mode 100644 phpcs.xml.dist diff --git a/.cache/.gitkeep b/.cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..26873f8 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,85 @@ +name: PHP coding standards + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + # Runs the PHP coding standards checks. + # + # Violations are reported inline with annotations. + # + # Performs the following steps: + # - Checks out the repository. + # - Sets up PHP. + # - Configures caching for PHPCS scans. + # - Installs Composer dependencies. + # - Make Composer packages available globally. + # - Runs PHPCS on the full codebase (warnings excluded). + # - Generate a report for displaying issues as pull request annotations. + # - Runs PHPCS on the `tests` directory without (warnings included). + # - Generate a report for displaying `test` directory issues as pull request annotations. + # - Ensures version-controlled files are not modified or deleted. + phpcs: + name: Run coding standards checks + runs-on: ubuntu-latest + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Set up PHP + uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1 + with: + coverage: none + tools: cs2pr + + # This date is used to ensure that the PHPCS cache is cleared at least once every week. + # http://man7.org/linux/man-pages/man1/date.1.html + - name: "Get last Monday's date" + id: get-date + run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT + + - name: Cache PHPCS scan cache + uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1 + with: + path: | + .cache/phpcs-src.json + .cache/phpcs-tests.json + key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }} + + - name: Install Composer dependencies + uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0 + + - name: Make Composer packages available globally + run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH + + - name: Run PHPCS on all files + id: phpcs-files + if: ${{ ! inputs.old-branch }} + run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml + + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs-files.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-report.xml + + - name: Check test suite files for warnings + id: phpcs-tests + run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml + + - name: Show test suite scan results in PR + if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }} + run: cs2pr ./.cache/phpcs-tests-report.xml + + - name: Ensure version-controlled files are not modified during the tests + run: git diff --exit-code diff --git a/.gitignore b/.gitignore index 88586c1..beb2775 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ /tests/cache /tests/coverage .DS_Store + +# Track placeholders so that empty directories stay in the repo. +!.gitkeep diff --git a/assets/css/aspire-update.css b/assets/css/aspire-update.css index 89be84f..c8d1825 100644 --- a/assets/css/aspire-update.css +++ b/assets/css/aspire-update.css @@ -1,63 +1,64 @@ -@keyframes glow { - 0% { - background-color: rgba(255, 223, 0, 0.1); - } - - 100% { - background-color: none; - } -} - -.glow-reveal { - animation: glow 0.5s ease-in-out; -} - -.aspireupdate-settings-field-hosts-wrapper .aspireupdate-settings-field-hosts-row { - margin: 0 0 10px; -} - -#aspireupdate-generate-api-key { - display: inline-block; - width: 30px; - height: 30px; - background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; - background-color: #cbcbcb; - border: 1px solid #8c8f94; - border-radius: 3px; - clip-path: inset(0 0 0 0); - color: transparent; - cursor: pointer; - transition: background-color 0.3s ease; -} - -#aspireupdate-generate-api-key:hover { - background-color: #e3e3e3; -} - -.aspireupdate-settings-field-wrapper p.error { - color: #bc3b3b; - display: none; -} - -#voltron { - color: transparent; - font-size: 8px; - line-height: 6px; - display: inline-block; - cursor: default; -} - -#voltron:hover { - animation: blink 1.8s ease-in-out infinite; - animation-delay: 5s; -} - -@keyframes blink { - 0%, - 100% { - color: inherit; - } - 50% { - color: transparent; - } -} + +@keyframes glow { + 0% { + background-color: rgba(255, 223, 0, 0.1); + } + + 100% { + background-color: none; + } +} + +.glow-reveal { + animation: glow 0.5s ease-in-out; +} + +.aspireupdate-settings-field-hosts-wrapper .aspireupdate-settings-field-hosts-row { + margin: 0 0 10px; +} + +#aspireupdate-generate-api-key { + display: inline-block; + width: 30px; + height: 30px; + background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; + background-color: #cbcbcb; + border: 1px solid #8c8f94; + border-radius: 3px; + clip-path: inset(0 0 0 0); + color: transparent; + cursor: pointer; + transition: background-color 0.3s ease; +} + +#aspireupdate-generate-api-key:hover { + background-color: #e3e3e3; +} + +.aspireupdate-settings-field-wrapper p.error { + color: #bc3b3b; + display: none; +} + +#voltron { + color: transparent; + font-size: 8px; + line-height: 6px; + display: inline-block; + cursor: default; +} + +#voltron:hover { + animation: blink 1.8s ease-in-out infinite; + animation-delay: 5s; +} + +@keyframes blink { + 0%, + 100% { + color: inherit; + } + 50% { + color: transparent; + } +} diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index fa9b96f..e9f9f42 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -1,239 +1,241 @@ -jQuery(document).ready(function () { - new ApiRewrites(); - new ApiDebug(); -}); - -class ApiRewrites { - constructor() { - ApiRewrites.host_selector.init(); - ApiRewrites.other_hosts.init(); - ApiRewrites.api_key.init(); - ApiRewrites.enabled_rewrites.init(); - } - - static enabled_rewrites = { - field: jQuery('#aspireupdate-settings-field-enable'), - sub_fields: [], - init() { - ApiRewrites.enabled_rewrites.sub_fields = [ - ApiRewrites.host_selector, - ApiRewrites.api_key - ]; - - ApiRewrites.enabled_rewrites.field.change(function () { - if (jQuery(this).is(':checked')) { - ApiRewrites.enabled_rewrites.show_options(); - } else { - ApiRewrites.enabled_rewrites.hide_options(); - } - }).change(); - }, - show_options() { - Fields.show(ApiRewrites.enabled_rewrites.sub_fields); - }, - hide_options() { - Fields.hide(ApiRewrites.enabled_rewrites.sub_fields); - } - } - - static host_selector = { - field: jQuery('#aspireupdate-settings-field-api_host'), - init() { - ApiRewrites.host_selector.field.change(function () { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - if ('other' === selected_option.val()) { - ApiRewrites.other_hosts.show(); - } else { - ApiRewrites.other_hosts.hide(); - } - - if (ApiRewrites.host_selector.is_api_key_required()) { - ApiRewrites.api_key.make_required(); - } else { - ApiRewrites.api_key.remove_required(); - } - - if (ApiRewrites.host_selector.has_api_key_url()) { - ApiRewrites.api_key.show_action_button(); - } else { - ApiRewrites.api_key.hide_action_button(); - } - }).change(); - }, - is_api_key_required() { - let is_api_rewrites_enabled = jQuery('#aspireupdate-settings-field-enable').is(':checked'); - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let require_api_key = selected_option.attr('data-require-api-key'); - if (is_api_rewrites_enabled && 'true' === require_api_key) { - return true; - } - return false; - }, - has_api_key_url() { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let api_url = selected_option.attr('data-api-key-url'); - if ('' !== api_url) { - return true; - } - return false; - }, - get_api_key_url() { - let selected_option = ApiRewrites.host_selector.field.find(":selected"); - let api_url = selected_option.attr('data-api-key-url'); - if ('' !== api_url) { - return api_url; - } - return ''; - }, - } - - static other_hosts = { - field: jQuery('#aspireupdate-settings-field-api_host_other'), - init() { - ApiRewrites.other_hosts.field.on("blur", function () { - let value = ApiRewrites.other_hosts.field.val(); - value = ApiRewrites.other_hosts.strip_protocol(value); - value = ApiRewrites.other_hosts.strip_dangerous_characters(value); - ApiRewrites.other_hosts.field.val(value); - }); - }, - show() { - ApiRewrites.other_hosts.field.parent().show(); - ApiRewrites.other_hosts.field.focus(); - ApiRewrites.other_hosts.make_required(); - }, - hide() { - ApiRewrites.other_hosts.field.parent().hide(); - ApiRewrites.other_hosts.remove_required(); - }, - make_required() { - ApiRewrites.other_hosts.field.prop('required', true); - }, - remove_required() { - ApiRewrites.other_hosts.field.prop('required', false); - }, - strip_protocol(value) { - const protocol_regex = /^(https?|ftp|sftp|smtp|ftps|file):\/\/|^www\./i; - return value.replace(protocol_regex, ''); - }, - strip_dangerous_characters(value) { - const dangerous_characters_regex = /[<>/"'&;]/g; - return value.replace(dangerous_characters_regex, ''); - } - } - - static api_key = { - field: jQuery('#aspireupdate-settings-field-api_key'), - action_button: jQuery('#aspireupdate-generate-api-key'), - init() { - ApiRewrites.api_key.action_button.click(function () { - ApiRewrites.api_key.hide_error(); - ApiRewrites.api_key.get_api_key(); - }); - ApiRewrites.api_key.hide_error(); - }, - get_api_key() { - let parameters = { - "url": ApiRewrites.host_selector.get_api_key_url(), - "type": "POST", - "contentType": 'application/json', - "data": JSON.stringify({ - "domain": aspireupdate.domain - }) - }; - jQuery.ajax(parameters) - .done(function (response) { - ApiRewrites.api_key.field.val(response.apikey); - }) - .fail(function (response) { - if ((response.status === 400) || (response.status === 401)) { - ApiRewrites.api_key.show_error(response.responseJSON?.error); - } else { - ApiRewrites.api_key.show_error('Unexpected Error: ' + response.status); - } - }); - }, - show() { - ApiRewrites.api_key.field.parent().parent().parent().show(); - }, - hide() { - ApiRewrites.api_key.field.parent().parent().parent().hide(); - }, - show_action_button() { - ApiRewrites.api_key.action_button.show(); - }, - hide_action_button() { - ApiRewrites.api_key.action_button.hide(); - }, - make_required() { - ApiRewrites.api_key.field.prop('required', true); - }, - remove_required() { - ApiRewrites.api_key.field.prop('required', false); - }, - show_error(message) { - ApiRewrites.api_key.field.parent().find('.error').html(message).show(); - }, - hide_error() { - ApiRewrites.api_key.field.parent().find('.error').html('').hide(); - } - } -} - -class ApiDebug { - constructor() { - ApiDebug.enabled_debug.init(); - } - - static enabled_debug = { - field: jQuery('#aspireupdate-settings-field-enable_debug'), - sub_fields: [], - init() { - ApiDebug.enabled_debug.sub_fields = [ - ApiDebug.debug_type, - ApiDebug.disable_ssl_verification - ]; - - ApiDebug.enabled_debug.field.change(function () { - if (jQuery(this).is(':checked')) { - ApiDebug.enabled_debug.show_options(); - } else { - ApiDebug.enabled_debug.hide_options(); - } - }).change(); - }, - show_options() { - Fields.show(ApiDebug.enabled_debug.sub_fields); - }, - hide_options() { - Fields.hide(ApiDebug.enabled_debug.sub_fields); - } - } - - static debug_type = { - field: jQuery('.aspireupdate-settings-field-wrapper-enable_debug_type'), - } - - static disable_ssl_verification = { - field: jQuery('#aspireupdate-settings-field-disable_ssl_verification'), - } -} - -class Fields { - static show(sub_fields) { - jQuery.each(sub_fields, function (index, sub_field) { - sub_field.field.closest('tr').show().addClass('glow-reveal'); - sub_field.field.change(); - setTimeout(function () { - sub_field.field.closest('tr').removeClass('glow-reveal'); - }, 500); - }); - } - - static hide(sub_fields) { - jQuery.each(sub_fields, function (index, sub_field) { - sub_field.field.closest('tr').hide(); - sub_field.field.change(); - }); - } -} \ No newline at end of file + +jQuery(document).ready(function () { + new ApiRewrites(); + new ApiDebug(); +}); + +class ApiRewrites { + constructor() { + ApiRewrites.host_selector.init(); + ApiRewrites.other_hosts.init(); + ApiRewrites.api_key.init(); + ApiRewrites.enabled_rewrites.init(); + } + + static enabled_rewrites = { + field: jQuery('#aspireupdate-settings-field-enable'), + sub_fields: [], + init() { + ApiRewrites.enabled_rewrites.sub_fields = [ + ApiRewrites.host_selector, + ApiRewrites.api_key + ]; + + ApiRewrites.enabled_rewrites.field.change(function () { + if (jQuery(this).is(':checked')) { + ApiRewrites.enabled_rewrites.show_options(); + } else { + ApiRewrites.enabled_rewrites.hide_options(); + } + }).change(); + }, + show_options() { + Fields.show(ApiRewrites.enabled_rewrites.sub_fields); + }, + hide_options() { + Fields.hide(ApiRewrites.enabled_rewrites.sub_fields); + } + } + + static host_selector = { + field: jQuery('#aspireupdate-settings-field-api_host'), + init() { + ApiRewrites.host_selector.field.change(function () { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + if ('other' === selected_option.val()) { + ApiRewrites.other_hosts.show(); + } else { + ApiRewrites.other_hosts.hide(); + } + + if (ApiRewrites.host_selector.is_api_key_required()) { + ApiRewrites.api_key.make_required(); + } else { + ApiRewrites.api_key.remove_required(); + } + + if (ApiRewrites.host_selector.has_api_key_url()) { + ApiRewrites.api_key.show_action_button(); + } else { + ApiRewrites.api_key.hide_action_button(); + } + }).change(); + }, + is_api_key_required() { + let is_api_rewrites_enabled = jQuery('#aspireupdate-settings-field-enable').is(':checked'); + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let require_api_key = selected_option.attr('data-require-api-key'); + if (is_api_rewrites_enabled && 'true' === require_api_key) { + return true; + } + return false; + }, + has_api_key_url() { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let api_url = selected_option.attr('data-api-key-url'); + if ('' !== api_url) { + return true; + } + return false; + }, + get_api_key_url() { + let selected_option = ApiRewrites.host_selector.field.find(":selected"); + let api_url = selected_option.attr('data-api-key-url'); + if ('' !== api_url) { + return api_url; + } + return ''; + }, + } + + static other_hosts = { + field: jQuery('#aspireupdate-settings-field-api_host_other'), + init() { + ApiRewrites.other_hosts.field.on("blur", function () { + let value = ApiRewrites.other_hosts.field.val(); + value = ApiRewrites.other_hosts.strip_protocol(value); + value = ApiRewrites.other_hosts.strip_dangerous_characters(value); + ApiRewrites.other_hosts.field.val(value); + }); + }, + show() { + ApiRewrites.other_hosts.field.parent().show(); + ApiRewrites.other_hosts.field.focus(); + ApiRewrites.other_hosts.make_required(); + }, + hide() { + ApiRewrites.other_hosts.field.parent().hide(); + ApiRewrites.other_hosts.remove_required(); + }, + make_required() { + ApiRewrites.other_hosts.field.prop('required', true); + }, + remove_required() { + ApiRewrites.other_hosts.field.prop('required', false); + }, + strip_protocol(value) { + const protocol_regex = /^(https?|ftp|sftp|smtp|ftps|file):\/\/|^www\./i; + return value.replace(protocol_regex, ''); + }, + strip_dangerous_characters(value) { + const dangerous_characters_regex = /[<>/"'&;]/g; + return value.replace(dangerous_characters_regex, ''); + } + } + + static api_key = { + field: jQuery('#aspireupdate-settings-field-api_key'), + action_button: jQuery('#aspireupdate-generate-api-key'), + init() { + ApiRewrites.api_key.action_button.click(function () { + ApiRewrites.api_key.hide_error(); + ApiRewrites.api_key.get_api_key(); + }); + ApiRewrites.api_key.hide_error(); + }, + get_api_key() { + let parameters = { + "url": ApiRewrites.host_selector.get_api_key_url(), + "type": "POST", + "contentType": 'application/json', + "data": JSON.stringify({ + "domain": aspireupdate.domain + }) + }; + jQuery.ajax(parameters) + .done(function (response) { + ApiRewrites.api_key.field.val(response.apikey); + }) + .fail(function (response) { + if ((response.status === 400) || (response.status === 401)) { + ApiRewrites.api_key.show_error(response.responseJSON?.error); + } else { + ApiRewrites.api_key.show_error('Unexpected Error: ' + response.status); + } + }); + }, + show() { + ApiRewrites.api_key.field.parent().parent().parent().show(); + }, + hide() { + ApiRewrites.api_key.field.parent().parent().parent().hide(); + }, + show_action_button() { + ApiRewrites.api_key.action_button.show(); + }, + hide_action_button() { + ApiRewrites.api_key.action_button.hide(); + }, + make_required() { + ApiRewrites.api_key.field.prop('required', true); + }, + remove_required() { + ApiRewrites.api_key.field.prop('required', false); + }, + show_error(message) { + ApiRewrites.api_key.field.parent().find('.error').html(message).show(); + }, + hide_error() { + ApiRewrites.api_key.field.parent().find('.error').html('').hide(); + } + } +} + +class ApiDebug { + constructor() { + ApiDebug.enabled_debug.init(); + } + + static enabled_debug = { + field: jQuery('#aspireupdate-settings-field-enable_debug'), + sub_fields: [], + init() { + ApiDebug.enabled_debug.sub_fields = [ + ApiDebug.debug_type, + ApiDebug.disable_ssl_verification + ]; + + ApiDebug.enabled_debug.field.change(function () { + if (jQuery(this).is(':checked')) { + ApiDebug.enabled_debug.show_options(); + } else { + ApiDebug.enabled_debug.hide_options(); + } + }).change(); + }, + show_options() { + Fields.show(ApiDebug.enabled_debug.sub_fields); + }, + hide_options() { + Fields.hide(ApiDebug.enabled_debug.sub_fields); + } + } + + static debug_type = { + field: jQuery('.aspireupdate-settings-field-wrapper-enable_debug_type'), + } + + static disable_ssl_verification = { + field: jQuery('#aspireupdate-settings-field-disable_ssl_verification'), + } +} + +class Fields { + static show(sub_fields) { + jQuery.each(sub_fields, function (index, sub_field) { + sub_field.field.closest('tr').show().addClass('glow-reveal'); + sub_field.field.change(); + setTimeout(function () { + sub_field.field.closest('tr').removeClass('glow-reveal'); + }, 500); + }); + } + + static hide(sub_fields) { + jQuery.each(sub_fields, function (index, sub_field) { + sub_field.field.closest('tr').hide(); + sub_field.field.change(); + }); + } +} + diff --git a/assets/playground/blueprint.json b/assets/playground/blueprint.json index 3b89a47..d9e8453 100644 --- a/assets/playground/blueprint.json +++ b/assets/playground/blueprint.json @@ -1,57 +1,57 @@ { - "$schema": "https://playground.wordpress.net/blueprint-schema.json", - "preferredVersions": { - "php": "latest", - "wp": "latest" - }, - "meta": { - "title": "AspirePress AspireUpdate Plugin Demo", - "description": "Load table AspireUpdate plugin into a WordPress Playground site", - "author": "asirota", - "categories": [ - "demo", - "plugin" - ] - }, - "siteOptions": { - "blogname": "AspireUpdate Demo Site" - }, - "plugins": [ - "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=playground-ready", - "error-log-viewer", - "plugin-check" - ], - "features": { - "networking": true - }, - "login": true, - "landingPage": "/wp-admin/admin.php?page=aspireupdate-settings", - "steps": [ - { - "step": "defineWpConfigConsts", - "consts": { - "WP_DISABLE_FATAL_ERROR_HANDLER": false, - "WP_DEBUG": false, - "WP_DEBUG_LOG": false, - "WP_DEBUG_DISPLAY": true - } - }, - { - "step": "writeFile", - "path": "/wordpress/wp-content/mu-plugins/rewrite.php", - "data": "set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );" - }, - { - "step": "installTheme", - "themeData": { - "resource": "wordpress.org/themes", - "slug": "twentytwentytwo" - } - }, - { - "step": "writeFile", - "path": "/wordpress/wp-content/mu-plugins/bgnightly-notice.php", - "data": "

Welcome to AspireUpdate Demo. Visit AspirePress documentation for more details.

'; });" - } - ] + "$schema": "https://playground.wordpress.net/blueprint-schema.json", + "preferredVersions": { + "php": "latest", + "wp": "latest" + }, + "meta": { + "title": "AspirePress AspireUpdate Plugin Demo", + "description": "Load table AspireUpdate plugin into a WordPress Playground site", + "author": "asirota", + "categories": [ + "demo", + "plugin" + ] + }, + "siteOptions": { + "blogname": "AspireUpdate Demo Site" + }, + "plugins": [ + "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=playground-ready", + "error-log-viewer", + "plugin-check" + ], + "features": { + "networking": true + }, + "login": true, + "landingPage": "/wp-admin/admin.php?page=aspireupdate-settings", + "steps": [ + { + "step": "defineWpConfigConsts", + "consts": { + "WP_DISABLE_FATAL_ERROR_HANDLER": false, + "WP_DEBUG": false, + "WP_DEBUG_LOG": false, + "WP_DEBUG_DISPLAY": true + } + }, + { + "step": "writeFile", + "path": "/wordpress/wp-content/mu-plugins/rewrite.php", + "data": "set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );" + }, + { + "step": "installTheme", + "themeData": { + "resource": "wordpress.org/themes", + "slug": "twentytwentytwo" + } + }, + { + "step": "writeFile", + "path": "/wordpress/wp-content/mu-plugins/bgnightly-notice.php", + "data": "

Welcome to AspireUpdate Demo. Visit AspirePress documentation for more details.

'; });" + } + ] } diff --git a/composer.json b/composer.json index c5a7ae5..d2a49e5 100644 --- a/composer.json +++ b/composer.json @@ -1,4 +1,5 @@ { + "name": "aspirepress/aspire-update", "description": "Update plugins and themes for WordPress.", "type": "wordpress-plugin", @@ -12,9 +13,21 @@ "php": ">=7.4.0" }, "require-dev": { + + "squizlabs/php_codesniffer": "3.10.3", + "wp-coding-standards/wpcs": "~3.1.0", "yoast/phpunit-polyfills": "^1.1.0" }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "scripts": { + "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", + "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary, source", "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit" ] } + + } diff --git a/composer.lock b/composer.lock index e7dcd4e..0af7c9c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,10 +4,90 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0916844f3ac21ff922fe9b414c14d840", + + "content-hash": "ee8f3669b94f591108fa37dfcf3db475", "packages": [], "packages-dev": [ { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "doctrine/instantiator", "version": "1.5.0", "source": { @@ -314,6 +394,174 @@ "time": "2022-02-21T01:04:05+00:00" }, { + + "name": "phpcsstandards/phpcsextra", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.9", + "squizlabs/php_codesniffer": "^3.8.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "security": "https://github.com/PHPCSStandards/PHPCSExtra/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2023-12-08T16:49:07+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.12", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/87b233b00daf83fb70f40c9a28692be017ea7c6c", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.10.0 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.1.0 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "security": "https://github.com/PHPCSStandards/PHPCSUtils/security/policy", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-05-20T13:34:27+00:00" + }, + { + "name": "phpunit/php-code-coverage", "version": "9.2.32", "source": { @@ -1699,6 +1947,88 @@ "time": "2020-09-28T06:39:44+00:00" }, { + + "name": "squizlabs/php_codesniffer", + "version": "3.10.3", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/62d32998e820bddc40f99f8251958aed187a5c9c", + "reference": "62d32998e820bddc40f99f8251958aed187a5c9c", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-09-18T10:38:58+00:00" + }, + { + "name": "theseer/tokenizer", "version": "1.2.3", "source": { @@ -1749,6 +2079,74 @@ "time": "2024-03-03T12:36:25+00:00" }, { + + "name": "wp-coding-standards/wpcs", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.2.1", + "phpcsstandards/phpcsutils": "^1.0.10", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/php_codesniffer", + "type": "custom" + } + ], + "time": "2024-03-25T16:39:00+00:00" + }, + { + "name": "yoast/phpunit-polyfills", "version": "1.1.2", "source": { diff --git a/includes/autoload.php b/includes/autoload.php index ffbf35e..8cc0a3b 100644 --- a/includes/autoload.php +++ b/includes/autoload.php @@ -15,7 +15,7 @@ */ function aspire_update_autoloader( $class_name ) { if ( false !== strpos( $class_name, 'AspireUpdate\\' ) ) { - $class_name = strtolower( str_replace( array( 'AspireUpdate\\', '_' ), array( '', '-' ), $class_name ) ); + $class_name = strtolower( str_replace( [ 'AspireUpdate\\', '_' ], [ '', '-' ], $class_name ) ); $file = __DIR__ . DIRECTORY_SEPARATOR . 'class-' . $class_name . '.php'; if ( file_exists( $file ) ) { diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index 86c0a95..1105ad9 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -44,14 +44,16 @@ class Admin_Settings { * The Constructor. */ public function __construct() { - add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'register_admin_menu' ) ); - add_action( 'admin_init', array( $this, 'reset_settings' ) ); - add_action( 'admin_init', array( $this, 'register_settings' ) ); - add_action( 'admin_notices', array( $this, 'reset_admin_notice' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - - add_action( 'admin_init', array( $this, 'update_settings' ) ); - add_action( 'network_admin_edit_aspireupdate-settings', array( $this, 'update_settings' ) ); + + add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'register_admin_menu' ] ); + add_action( 'admin_init', [ $this, 'reset_settings' ] ); + add_action( 'admin_init', [ $this, 'register_settings' ] ); + add_action( 'admin_notices', [ $this, 'reset_admin_notice' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); + + add_action( 'admin_init', [ $this, 'update_settings' ] ); + add_action( 'network_admin_edit_aspireupdate-settings', [ $this, 'update_settings' ] ); + } /** @@ -72,7 +74,7 @@ public static function get_instance() { * @return array The default values. */ private function get_default_settings() { - $options = array(); + $options = []; $options['api_host'] = 'api.aspirecloud.org'; return $options; } @@ -95,10 +97,12 @@ public function reset_settings() { wp_safe_redirect( add_query_arg( - array( + [ 'reset-success' => 'success', 'reset-success-nonce' => wp_create_nonce( 'aspireupdate-reset-success-nonce' ), - ), + + ], + network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ); @@ -161,7 +165,7 @@ public function get_setting( $setting_name, $default_value = false ) { } if ( isset( $options['enable_debug_type'] ) && is_array( $options['enable_debug_type'] ) ) { - $debug_types = array(); + $debug_types = []; foreach ( $options['enable_debug_type'] as $debug_type_name => $debug_type_enabled ) { if ( $debug_type_enabled ) { $debug_types[] = $debug_type_name; @@ -181,7 +185,7 @@ public function get_setting( $setting_name, $default_value = false ) { * @return array An array of values as defined in the Config File. */ private function get_settings_from_config_file() { - $options = array(); + $options = []; if ( ! defined( 'AP_ENABLE' ) ) { define( 'AP_ENABLE', false ); @@ -208,7 +212,7 @@ private function get_settings_from_config_file() { } if ( ! defined( 'AP_DEBUG_TYPES' ) ) { - define( 'AP_DEBUG_TYPES', array() ); + define( 'AP_DEBUG_TYPES', [] ); } elseif ( is_array( AP_DEBUG_TYPES ) ) { $options['enable_debug_type'] = AP_DEBUG_TYPES; } @@ -241,7 +245,9 @@ public function update_settings() { update_site_option( $this->option_name, $this->sanitize_settings( wp_unslash( $_POST['aspireupdate_settings'] ) ) ); wp_safe_redirect( - add_query_arg( array( network_admin_url( 'index.php?page=aspireupdate-settings' ) ) ) + + add_query_arg( [ network_admin_url( 'index.php?page=aspireupdate-settings' ) ] ) + ); exit; } @@ -263,7 +269,7 @@ public function register_admin_menu() { 'AspireUpdate', is_multisite() ? 'manage_network_options' : 'manage_options', 'aspireupdate-settings', - array( $this, 'the_settings_page' ) + [ $this, 'the_settings_page' ] ); } } @@ -275,19 +281,23 @@ public function register_admin_menu() { * @return void */ public function admin_enqueue_scripts( $hook ) { - if ( ! in_array( $hook, array( 'dashboard_page_aspireupdate-settings','index_page_aspireupdate-settings' ) ) ) { + + if ( ! in_array( $hook, [ 'dashboard_page_aspireupdate-settings', 'index_page_aspireupdate-settings' ], true ) ) { + return; } - wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', array(), AP_VERSION ); - wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', array( 'jquery' ), AP_VERSION, true ); + wp_enqueue_style( 'aspire_update_settings_css', plugin_dir_url( __DIR__ ) . 'assets/css/aspire-update.css', [], AP_VERSION ); + wp_enqueue_script( 'aspire_update_settings_js', plugin_dir_url( __DIR__ ) . 'assets/js/aspire-update.js', [ 'jquery' ], AP_VERSION, true ); wp_localize_script( 'aspire_update_settings_js', 'aspireupdate', - array( + + [ + 'ajax_url' => network_admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), 'domain' => Utilities::get_top_level_domain(), - ) + ] ); } @@ -298,10 +308,12 @@ public function admin_enqueue_scripts( $hook ) { */ public function the_settings_page() { $reset_url = add_query_arg( - array( + [ 'reset' => 'reset', 'reset-nonce' => wp_create_nonce( 'aspireupdate-reset-nonce' ), - ), + + ], + network_admin_url( 'index.php?page=aspireupdate-settings' ) ); ?> @@ -408,9 +420,9 @@ public function register_settings() { register_setting( $this->option_group, $this->option_name, - array( - 'sanitize_callback' => array( $this, 'sanitize_settings' ), - ) + [ + 'sanitize_callback' => [ $this, 'sanitize_settings' ], + ] ); add_settings_section( @@ -418,64 +430,64 @@ public function register_settings() { esc_html__( 'API Configuration', 'AspireUpdate' ), null, 'aspireupdate-settings', - array( + [ 'before_section' => '
', 'after_section' => '
', - ) + ] ); add_settings_field( 'enable', esc_html__( 'Enable AspireUpdate API Rewrites', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'enable', 'type' => 'checkbox', 'data' => $options, - ) + ] ); add_settings_field( 'api_host', esc_html__( 'API Host', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'api_host', 'type' => 'hosts', 'data' => $options, 'description' => esc_html__( 'Your new API Host.', 'AspireUpdate' ), - 'options' => array( - array( + 'options' => [ + [ 'value' => 'api.aspirecloud.org', 'label' => 'AspireCloud (api.aspirecloud.org)', 'require-api-key' => 'false', 'api-key-url' => 'api.aspirecloud.org/v1/apitoken', - ), - array( + ], + [ 'value' => 'other', 'label' => esc_html__( 'Other', 'AspireUpdate' ), 'require-api-key' => 'false', - ), - ), - ) + ], + ], + ] ); add_settings_field( 'api_key', esc_html__( 'API Key', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_settings_section', - array( + [ 'id' => 'api_key', 'type' => 'api-key', 'data' => $options, 'description' => esc_html__( 'Provides an API key for repositories that may require authentication.', 'AspireUpdate' ), - ) + ] ); add_settings_section( @@ -483,58 +495,58 @@ public function register_settings() { esc_html__( 'API Debug Configuration', 'AspireUpdate' ), null, 'aspireupdate-settings', - array( + [ 'before_section' => '
', 'after_section' => '
', - ) + ] ); add_settings_field( 'enable_debug', esc_html__( 'Enable Debug Mode', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'enable_debug', 'type' => 'checkbox', 'data' => $options, 'description' => esc_html__( 'Enables debug mode for the plugin.', 'AspireUpdate' ), - ) + ] ); add_settings_field( 'enable_debug_type', esc_html__( 'Enable Debug Type', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'enable_debug_type', 'type' => 'checkbox-group', 'data' => $options, - 'options' => array( + 'options' => [ 'request' => esc_html__( 'Request', 'AspireUpdate' ), 'response' => esc_html__( 'Response', 'AspireUpdate' ), 'string' => esc_html__( 'String', 'AspireUpdate' ), - ), + ], 'description' => esc_html__( 'Outputs the request URL and headers / response headers and body / string that is being rewritten.', 'AspireUpdate' ), - ) + ] ); add_settings_field( 'disable_ssl_verification', esc_html__( 'Disable SSL Verification', 'AspireUpdate' ), - array( $this, 'add_settings_field_callback' ), + [ $this, 'add_settings_field_callback' ], 'aspireupdate-settings', 'aspireupdate_debug_settings_section', - array( + [ 'id' => 'disable_ssl_verification', 'type' => 'checkbox', 'data' => $options, 'class' => 'advanced-setting', 'description' => esc_html__( 'Disables the verification of SSL to allow local testing.', 'AspireUpdate' ), - ) + ] ); } @@ -545,15 +557,15 @@ public function register_settings() { * * @return void Echos the Field HTML. */ - public function add_settings_field_callback( $args = array() ) { + public function add_settings_field_callback( $args = [] ) { - $defaults = array( + $defaults = [ 'id' => '', 'type' => 'text', 'description' => '', - 'data' => array(), - 'options' => array(), - ); + 'data' => [], + 'options' => [], + ]; $args = wp_parse_args( $args, $defaults ); $id = $args['id']; $type = $args['type']; @@ -642,7 +654,7 @@ class="regular-text" * @return array The processed Input. */ public function sanitize_settings( $input ) { - $sanitized_input = array(); + $sanitized_input = []; $sanitized_input['enable'] = (int) ! empty( $input['enable'] ); $sanitized_input['api_key'] = sanitize_text_field( $input['api_key'] ?? '' ); @@ -653,7 +665,7 @@ public function sanitize_settings( $input ) { if ( isset( $input['enable_debug_type'] ) && is_array( $input['enable_debug_type'] ) ) { $sanitized_input['enable_debug_type'] = array_map( 'sanitize_text_field', $input['enable_debug_type'] ); } else { - $sanitized_input['enable_debug_type'] = array(); + $sanitized_input['enable_debug_type'] = []; } $sanitized_input['disable_ssl_verification'] = (int) ! empty( $input['disable_ssl_verification'] ); diff --git a/includes/class-api-rewrite.php b/includes/class-api-rewrite.php index 86836f5..9002907 100644 --- a/includes/class-api-rewrite.php +++ b/includes/class-api-rewrite.php @@ -45,7 +45,7 @@ public function __construct( $redirected_host, $disable_ssl ) { $this->redirected_host = strtolower( $redirected_host ); } $this->disable_ssl = $disable_ssl; - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); } /** @@ -80,9 +80,9 @@ public function pre_http_request( $response, $parsed_args, $url ) { /** * Temporarily Unhook Filter to prevent recursion. */ - remove_filter( 'pre_http_request', array( $this, 'pre_http_request' ) ); + remove_filter( 'pre_http_request', [ $this, 'pre_http_request' ] ); $response = wp_remote_request( $updated_url, $parsed_args ); - add_filter( 'pre_http_request', array( $this, 'pre_http_request' ), 10, 3 ); + add_filter( 'pre_http_request', [ $this, 'pre_http_request' ], 10, 3 ); Debug::log_response( $response ); diff --git a/includes/class-controller.php b/includes/class-controller.php index b595424..6099736 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -20,7 +20,9 @@ public function __construct() { Themes_Screens::get_instance(); $this->api_rewrite(); - add_action( 'init', array( $this, 'load_textdomain' ) ); + + add_action( 'init', [ $this, 'load_textdomain' ] ); + } /** diff --git a/includes/class-debug.php b/includes/class-debug.php index 21e07f5..5a64b24 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -109,7 +109,7 @@ private static function format_message( $message ) { public static function log_string( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'string', $debug_types, true ) ) { self::log( $message, 'string' ); } @@ -123,7 +123,7 @@ public static function log_string( $message ) { public static function log_request( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'request', $debug_types, true ) ) { self::log( $message, 'request' ); } @@ -137,7 +137,7 @@ public static function log_request( $message ) { public static function log_response( $message ) { $admin_settings = Admin_Settings::get_instance(); $debug_mode = $admin_settings->get_setting( 'enable_debug', false ); - $debug_types = $admin_settings->get_setting( 'enable_debug_type', array() ); + $debug_types = $admin_settings->get_setting( 'enable_debug_type', [] ); if ( $debug_mode && is_array( $debug_types ) && in_array( 'response', $debug_types, true ) ) { self::log( $message, 'response' ); } diff --git a/includes/class-plugins-screens.php b/includes/class-plugins-screens.php index b69e40e..732c6eb 100644 --- a/includes/class-plugins-screens.php +++ b/includes/class-plugins-screens.php @@ -23,10 +23,10 @@ class Plugins_Screens { * * @var array */ - protected $unsupported_filters = array( + protected $unsupported_filters = [ 'featured', 'favorites', - ); + ]; /** * The Constructor. @@ -34,7 +34,7 @@ class Plugins_Screens { public function __construct() { $admin_settings = Admin_Settings::get_instance(); if ( $admin_settings->get_setting( 'enable', false ) ) { - add_filter( 'install_plugins_tabs', array( $this, 'remove_unused_filter_tabs' ) ); + add_filter( 'install_plugins_tabs', [ $this, 'remove_unused_filter_tabs' ] ); } } diff --git a/includes/class-themes-screens.php b/includes/class-themes-screens.php index ad77d15..a993daf 100644 --- a/includes/class-themes-screens.php +++ b/includes/class-themes-screens.php @@ -23,9 +23,9 @@ class Themes_Screens { * * @var array */ - protected $unsupported_filters = array( + protected $unsupported_filters = [ 'favorites', - ); + ]; /** * The Constructor. @@ -33,8 +33,8 @@ class Themes_Screens { public function __construct() { $admin_settings = Admin_Settings::get_instance(); if ( $admin_settings->get_setting( 'enable', false ) ) { - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); - add_action( 'load-theme-install.php', array( $this, 'redirect_to_theme_install' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] ); + add_action( 'load-theme-install.php', [ $this, 'redirect_to_theme_install' ] ); } } @@ -65,13 +65,13 @@ public function admin_enqueue_scripts( $hook ) { wp_register_style( 'aspire_update_themes_screens_css', false, - array(), + [], AP_VERSION ); wp_enqueue_style( 'aspire_update_themes_screens_css' ); - $css_selectors = array(); + $css_selectors = []; foreach ( $this->unsupported_filters as $filter ) { $css_selectors[] = '.wp-filter .filter-links a[data-sort="' . $filter . '"]'; } @@ -95,7 +95,7 @@ public function redirect_to_theme_install() { if ( $nonce && ! wp_verify_nonce( $nonce, 'query-themes' ) ) { return; } - + $browse = isset( $_GET['browse'] ) ? sanitize_text_field( wp_unslash( $_GET['browse'] ) ) : ''; if ( ! in_array( $browse, $this->unsupported_filters, true ) ) { diff --git a/languages/AspireUpdate-de_DE.I10n.php b/languages/AspireUpdate-de_DE.I10n.php index 4297531..900ff0a 100644 --- a/languages/AspireUpdate-de_DE.I10n.php +++ b/languages/AspireUpdate-de_DE.I10n.php @@ -1,25 +1,27 @@ 'AspireUpdate','report-msgid-bugs-to'=>'','pot-creation-date'=>'2024-11-04 00:29+0000','po-revision-date'=>'2024-11-04 00:29+0000','last-translator'=>'','language-team'=>'German (Germany)','language'=>'de_DE','plural-forms'=>'nplurals=2; plural=n != 1;','mime-version'=>'1.0','content-type'=>'text/plain; charset=UTF-8','content-transfer-encoding'=>'8bit','x-generator'=>'Loco https://localise.biz/','x-loco-version'=>'2.6.11; wp-6.6.2','x-domain'=>'AspireUpdate','messages'=>[ - 'API Configuration'=>'API-Konfiguration', - 'API Debug Configuration'=>'API-Debug-Konfiguration', - 'API Host'=>'API-Host', - 'API Key'=>'API-Schlüssel', - 'AspirePress'=>'AspirePress', - 'AspireUpdate'=>'AspireUpdate', - 'AspireUpdate Settings'=>'AspireUpdate-Einstellungen', - 'Disable SSL Verification'=>'SSL-Überprüfung deaktivieren', - 'Disables the verification of SSL to allow local testing.'=>'Deaktiviert die SSL-Überprüfung, um lokale Tests zu ermöglichen.', - 'Enable AspireUpdate API Rewrites'=>'Aktivieren der AspireUpdate API-Umschreibungen', - 'Enable Debug Mode'=>'Debug-Modus aktivieren', - 'Enable Debug Type'=>'Debug-Typ aktivieren', - 'Enables debug mode for the plugin.'=>'Aktiviert den Debug-Modus für das Plugin.', - 'https://aspirepress.org/'=>'AspireUpdate', - 'https://docs.aspirepress.org/aspireupdate/'=>'https://docs.aspirepress.org/aspireupdate/', - 'Outputs the request URL and headers / response headers and body / string that is being rewritten.'=>'Gibt die Anfrage-URL und Header / Antwort-Header und -Body / Zeichenfolge aus, die umgeschrieben wird.', - 'Provides an API key for repositories that may require authentication.'=>'Stellt einen API-Schlüssel für Repositories bereit, die möglicherweise eine Authentifizierung erfordern.', - 'Request'=>'Anfrage', - 'Response'=>'Antwort', - 'String'=>'Zeichenkette', - 'Update plugins and themes for WordPress.'=>'Aktualisiert Plugins und Themes für WordPress.', - 'Your new API Host.'=>'Ihr neuer API-Host' + + 'API Configuration'=>'API-Konfiguration', + 'API Debug Configuration'=>'API-Debug-Konfiguration', + 'API Host'=>'API-Host', + 'API Key'=>'API-Schlüssel', + 'AspirePress'=>'AspirePress', + 'AspireUpdate'=>'AspireUpdate', + 'AspireUpdate Settings'=>'AspireUpdate-Einstellungen', + 'Disable SSL Verification'=>'SSL-Überprüfung deaktivieren', + 'Disables the verification of SSL to allow local testing.'=>'Deaktiviert die SSL-Überprüfung, um lokale Tests zu ermöglichen.', + 'Enable AspireUpdate API Rewrites'=>'Aktivieren der AspireUpdate API-Umschreibungen', + 'Enable Debug Mode'=>'Debug-Modus aktivieren', + 'Enable Debug Type'=>'Debug-Typ aktivieren', + 'Enables debug mode for the plugin.'=>'Aktiviert den Debug-Modus für das Plugin.', + 'https://aspirepress.org/'=>'AspireUpdate', + 'https://docs.aspirepress.org/aspireupdate/'=>'https://docs.aspirepress.org/aspireupdate/', + 'Outputs the request URL and headers / response headers and body / string that is being rewritten.'=>'Gibt die Anfrage-URL und Header / Antwort-Header und -Body / Zeichenfolge aus, die umgeschrieben wird.', + 'Provides an API key for repositories that may require authentication.'=>'Stellt einen API-Schlüssel für Repositories bereit, die möglicherweise eine Authentifizierung erfordern.', + 'Request'=>'Anfrage', + 'Response'=>'Antwort', + 'String'=>'Zeichenkette', + 'Update plugins and themes for WordPress.'=>'Aktualisiert Plugins und Themes für WordPress.', + 'Your new API Host.'=>'Ihr neuer API-Host' + ]]; diff --git a/languages/AspireUpdate-zh_TW.l10n.php b/languages/AspireUpdate-zh_TW.l10n.php index 530790f..609d2ec 100644 --- a/languages/AspireUpdate-zh_TW.l10n.php +++ b/languages/AspireUpdate-zh_TW.l10n.php @@ -1,2 +1,4 @@ NULL,'plural-forms'=>NULL,'language'=>'zh_TW','project-id-version'=>'AspireUpdate','pot-creation-date'=>'2024-11-02 12:34-0700','po-revision-date'=>'2024-11-02 12:40-0700','x-generator'=>'Poedit 3.5','messages'=>['Settings have been reset to default.'=>'設定已重設為預設值。','AspireUpdate Settings'=>'AspireUpdate 設定','Save Changes'=>'儲存設定','Reset'=>'重設','API Configuration'=>'API 組態','Enable AspireUpdate API Rewrites'=>'啟用 AspireUpdate API 重寫','API Host'=>'API 主機','Your new API Host.'=>'設定新的 API 主機。','Other'=>'其他主機','API Key'=>'API 金鑰','Provides an API key for repositories that may require authentication.'=>'為需要驗證的存放庫提供 API 金鑰。','API Debug Configuration'=>'API 偵錯組態','Enable Debug Mode'=>'啟用偵錯模式','Enables debug mode for the plugin.'=>'為外掛啟用偵錯模式。','Enable Debug Type'=>'啟用偵錯類型','Request'=>'要求','Response'=>'回應','String'=>'字串','Outputs the request URL and headers / response headers and body / string that is being rewritten.'=>'輸出經過重寫的要求網址、標頭、回應標頭、內容及字串。','Disable SSL Verification'=>'停用 SSL 驗證','Disables the verification of SSL to allow local testing.'=>'停用 SSL 驗證,便能在本機環境進行測試。','Generate API Key'=>'產生 API 金鑰','AspireUpdate'=>'AspireUpdate','https://aspirepress.org/'=>'https://aspirepress.org/','Update plugins and themes for WordPress.'=>'更新 WordPress 的外掛及佈景主題。','AspirePress'=>'AspirePress','https://docs.aspirepress.org/aspireupdate/'=>'https://docs.aspirepress.org/aspireupdate/']]; \ No newline at end of file + +return ['domain'=>NULL,'plural-forms'=>NULL,'language'=>'zh_TW','project-id-version'=>'AspireUpdate','pot-creation-date'=>'2024-11-02 12:34-0700','po-revision-date'=>'2024-11-02 12:40-0700','x-generator'=>'Poedit 3.5','messages'=>['Settings have been reset to default.'=>'設定已重設為預設值。','AspireUpdate Settings'=>'AspireUpdate 設定','Save Changes'=>'儲存設定','Reset'=>'重設','API Configuration'=>'API 組態','Enable AspireUpdate API Rewrites'=>'啟用 AspireUpdate API 重寫','API Host'=>'API 主機','Your new API Host.'=>'設定新的 API 主機。','Other'=>'其他主機','API Key'=>'API 金鑰','Provides an API key for repositories that may require authentication.'=>'為需要驗證的存放庫提供 API 金鑰。','API Debug Configuration'=>'API 偵錯組態','Enable Debug Mode'=>'啟用偵錯模式','Enables debug mode for the plugin.'=>'為外掛啟用偵錯模式。','Enable Debug Type'=>'啟用偵錯類型','Request'=>'要求','Response'=>'回應','String'=>'字串','Outputs the request URL and headers / response headers and body / string that is being rewritten.'=>'輸出經過重寫的要求網址、標頭、回應標頭、內容及字串。','Disable SSL Verification'=>'停用 SSL 驗證','Disables the verification of SSL to allow local testing.'=>'停用 SSL 驗證,便能在本機環境進行測試。','Generate API Key'=>'產生 API 金鑰','AspireUpdate'=>'AspireUpdate','https://aspirepress.org/'=>'https://aspirepress.org/','Update plugins and themes for WordPress.'=>'更新 WordPress 的外掛及佈景主題。','AspirePress'=>'AspirePress','https://docs.aspirepress.org/aspireupdate/'=>'https://docs.aspirepress.org/aspireupdate/']]; + diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..af33bc2 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,61 @@ + + + Apply WordPress Coding Standards to all AspireUpdate files + + + + + + + + + + + + + + + + + + + + + + + + . + + + /vendor/* + + + /languages/* + + + + + + + + + + + diff --git a/readme.txt b/readme.txt index c20faae..6844d4b 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === AspireUpdate === Contributors: sarah-savage, namithj, asirota Donate link: https://github.com/sponsors/aspirepress -Tags: +Tags: Requires at least: 5.3 Tested up to: 6.7 Stable tag: 0.5 diff --git a/tests/AdminSettings/AdminSettings_GetSettingTest.php b/tests/AdminSettings/AdminSettings_GetSettingTest.php index d54aed0..9516f90 100644 --- a/tests/AdminSettings/AdminSettings_GetSettingTest.php +++ b/tests/AdminSettings/AdminSettings_GetSettingTest.php @@ -7,13 +7,13 @@ /** * Tests for Admin_Settings::get_setting() - * + * * @covers \AspireUpdate\Admin_Settings::get_setting */ class AdminSettings_GetSettingTest extends WP_UnitTestCase { /** * Test that the default 'api_host' value is retrieved. - * + * * @covers \AspireUpdate\Admin_Settings::get_default_settings */ public function test_should_get_default_api_host() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 6daa840..b851569 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -31,7 +31,9 @@ * Manually load the plugin being tested. */ function _manually_load_plugin() { - require dirname( dirname( __FILE__ ) ) . '/aspire-update.php'; + + require dirname( __DIR__ ) . '/aspire-update.php'; + } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );