diff --git a/.github/workflows/WP_6_6.yaml b/.github/workflows/WP_6_6.yaml new file mode 100644 index 0000000..a3c67d6 --- /dev/null +++ b/.github/workflows/WP_6_6.yaml @@ -0,0 +1,63 @@ +name: WP 6.6 [PHP8.0-8.4] Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + runs-on: ${{ matrix.operating-system }} + services: + mysql-service: + image: mysql:8.4 + env: + MYSQL_ROOT_PASSWORD: 'crab' + MYSQL_DATABASE: pc_core_tests + ports: + - 3306:3306 + options: >- + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" + --health-interval=10s + --health-timeout=10s + --health-retries=10 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, pcov + ini-values: post_max_size=256M, log_errors=1 + tools: pecl + + - name: Check PHP Version + run: php -v + + - name: Clear existing composer + run: > + sudo rm -rf vendor + && rm -rf composer.lock + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: > + rm -rf composer.lock + && composer clearcache + && composer require php-stubs/wordpress-stubs:6.6.* --dev --no-update + && composer require roots/wordpress:6.6.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.6.* --dev --no-update + && composer update --no-cache + + - name: Run Tests on WP6.6 + env: + environment_github: true + run: composer all diff --git a/.github/workflows/WP_6_7.yaml b/.github/workflows/WP_6_7.yaml new file mode 100644 index 0000000..3f6e96f --- /dev/null +++ b/.github/workflows/WP_6_7.yaml @@ -0,0 +1,63 @@ +name: WP 6.7 [PHP8.0-8.4] Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + runs-on: ${{ matrix.operating-system }} + services: + mysql-service: + image: mysql:8.4 + env: + MYSQL_ROOT_PASSWORD: 'crab' + MYSQL_DATABASE: pc_core_tests + ports: + - 3306:3306 + options: >- + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" + --health-interval=10s + --health-timeout=10s + --health-retries=10 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, pcov + ini-values: post_max_size=256M, log_errors=1 + tools: pecl + + - name: Check PHP Version + run: php -v + + - name: Clear existing composer + run: > + sudo rm -rf vendor + && rm -rf composer.lock + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: > + rm -rf composer.lock + && composer clearcache + && composer require php-stubs/wordpress-stubs:6.7.* --dev --no-update + && composer require roots/wordpress:6.7.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.7.* --dev --no-update + && composer update --no-cache + + - name: Run Tests on WP6.7 + env: + environment_github: true + run: composer all diff --git a/.github/workflows/WP_6_8.yaml b/.github/workflows/WP_6_8.yaml new file mode 100644 index 0000000..b8c310a --- /dev/null +++ b/.github/workflows/WP_6_8.yaml @@ -0,0 +1,63 @@ +name: WP 6.8 [PHP8.0-8.4] Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + runs-on: ${{ matrix.operating-system }} + services: + mysql-service: + image: mysql:8.4 + env: + MYSQL_ROOT_PASSWORD: 'crab' + MYSQL_DATABASE: pc_core_tests + ports: + - 3306:3306 + options: >- + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" + --health-interval=10s + --health-timeout=10s + --health-retries=10 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, pcov + ini-values: post_max_size=256M, log_errors=1 + tools: pecl + + - name: Check PHP Version + run: php -v + + - name: Clear existing composer + run: > + sudo rm -rf vendor + && rm -rf composer.lock + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: > + rm -rf composer.lock + && composer clearcache + && composer require php-stubs/wordpress-stubs:6.8.* --dev --no-update + && composer require roots/wordpress:6.8.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.8.* --dev --no-update + && composer update --no-cache + + - name: Run Tests on WP6.8 + env: + environment_github: true + run: composer all diff --git a/.github/workflows/WP_6_9.yaml b/.github/workflows/WP_6_9.yaml new file mode 100644 index 0000000..598de07 --- /dev/null +++ b/.github/workflows/WP_6_9.yaml @@ -0,0 +1,70 @@ +name: WP 6.9 [PHP8.0-8.4] Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master, develop ] + +jobs: + build: + strategy: + matrix: + operating-system: [ubuntu-latest] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + runs-on: ${{ matrix.operating-system }} + services: + mysql-service: + image: mysql:8.4 + env: + MYSQL_ROOT_PASSWORD: 'crab' + MYSQL_DATABASE: pc_core_tests + ports: + - 3306:3306 + options: >- + --health-cmd="healthcheck.sh --connect || mysqladmin ping -uroot -pcrab" + --health-interval=10s + --health-timeout=10s + --health-retries=10 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, pcov + ini-values: post_max_size=256M, log_errors=1 + tools: pecl + + - name: Check PHP Version + run: php -v + + - name: Clear existing composer + run: > + sudo rm -rf vendor + && rm -rf composer.lock + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: > + rm -rf composer.lock + && composer clearcache + && composer require php-stubs/wordpress-stubs:6.9.* --dev --no-update + && composer require roots/wordpress:6.9.* --dev --no-update + && composer require wp-phpunit/wp-phpunit:6.9.* --dev --no-update + && composer update --no-cache + + - name: Run Tests on WP6.9 + env: + environment_github: true + run: composer all + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.MOUNT_CODECOV }} + files: ./clover.xml + fail_ci_if_error: false diff --git a/.gitignore b/.gitignore index 56340a2..e448b4c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ clover.xml workspace.code-workspace .phpunit.result.cache .vscode +tests/.env diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dda233b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 PinkCrab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Standard_Flags.php b/src/Standard_Flags.php index 35a6345..e712996 100644 --- a/src/Standard_Flags.php +++ b/src/Standard_Flags.php @@ -82,20 +82,15 @@ public function ajax_action(): string { */ protected function current_user(): ?array { $user = \wp_get_current_user(); - if ( ! $user || 0 === $user->ID ) { + if ( 0 === $user->ID ) { return null; } - $capabilities = array(); - if ( is_array( $user->allcaps ) ) { - $capabilities = array_values( array_keys( array_filter( $user->allcaps ) ) ); - } - return array( 'id' => (int) $user->ID, 'displayName' => (string) $user->display_name, 'roles' => array_values( (array) $user->roles ), - 'capabilities' => $capabilities, + 'capabilities' => array_keys( array_filter( $user->allcaps ) ), ); } } diff --git a/tests/.env_sample b/tests/.env_sample new file mode 100644 index 0000000..428feda --- /dev/null +++ b/tests/.env_sample @@ -0,0 +1,8 @@ +# WP Config Details + +# Please ensure the database exists before running the tests + +WP_DB_NAME=pc_core_tests +WP_DB_USER=root +WP_DB_PASS= +WP_DB_HOST=127.0.0.1