Skip to content

Commit 0f5747f

Browse files
Tsvetan StoychevTsvetan Stoychev
authored andcommitted
Refactored the plugin file structure. Added consent loader. Added page type detection.
1 parent f237fe5 commit 0f5747f

68 files changed

Lines changed: 7520 additions & 1186 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.editorconfig‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# EditorConfig helps maintain consistent coding styles
2+
# https://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[*.php]
13+
indent_style = tab
14+
indent_size = 4
15+
16+
[*.{js,json,yml,yaml,css}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
trim_trailing_whitespace = false
22+
23+
[Makefile]
24+
indent_style = tab

‎.github/workflows/ci.yml‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
workflow_dispatch:
10+
11+
jobs:
12+
unit:
13+
name: Unit (PHP ${{ matrix.php }})
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: ['7.4', '8.1', '8.2', '8.3']
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
tools: composer:v2
29+
coverage: none
30+
31+
- name: Install dependencies
32+
working-directory: plugins/basicrum
33+
run: composer install --no-interaction --prefer-dist
34+
35+
- name: PHP syntax lint
36+
working-directory: plugins/basicrum
37+
run: composer lint:php
38+
39+
- name: Coding standards
40+
working-directory: plugins/basicrum
41+
run: composer lint
42+
43+
- name: Unit tests
44+
working-directory: plugins/basicrum
45+
run: ./vendor/bin/phpunit --configuration phpunit.xml
46+
47+
integration:
48+
name: Integration (PHP ${{ matrix.php }}, WP ${{ matrix.wp }})
49+
runs-on: ubuntu-latest
50+
needs: unit
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
include:
55+
- php: '7.4'
56+
wp: '6.0'
57+
- php: '8.2'
58+
wp: 'trunk'
59+
60+
steps:
61+
- name: Checkout
62+
uses: actions/checkout@v4
63+
64+
- name: Setup PHP
65+
uses: shivammathur/setup-php@v2
66+
with:
67+
php-version: ${{ matrix.php }}
68+
tools: composer:v2
69+
coverage: none
70+
71+
- name: Install dependencies
72+
working-directory: plugins/basicrum
73+
run: composer install --no-interaction --prefer-dist
74+
75+
- name: Install WP test library (best effort)
76+
continue-on-error: true
77+
run: |
78+
set -e
79+
sudo apt-get update
80+
sudo apt-get install -y subversion
81+
82+
WP_TESTS_DIR=/tmp/wordpress-tests-lib
83+
WP_CORE_DIR=/tmp/wordpress
84+
TESTS_SVN_BASE="https://develop.svn.wordpress.org/${{ matrix.wp }}/tests/phpunit"
85+
CORE_SVN_BASE="https://develop.svn.wordpress.org/${{ matrix.wp }}/src"
86+
87+
mkdir -p "$WP_TESTS_DIR" "$WP_CORE_DIR"
88+
89+
svn export --force --quiet "$TESTS_SVN_BASE/includes" "$WP_TESTS_DIR/includes" || true
90+
svn export --force --quiet "$TESTS_SVN_BASE/data" "$WP_TESTS_DIR/data" || true
91+
svn export --force --quiet "$CORE_SVN_BASE/wp-includes" "$WP_CORE_DIR/wp-includes" || true
92+
svn export --force --quiet "$CORE_SVN_BASE/wp-admin" "$WP_CORE_DIR/wp-admin" || true
93+
94+
- name: Integration tests
95+
working-directory: plugins/basicrum
96+
env:
97+
WP_TESTS_DIR: /tmp/wordpress-tests-lib
98+
run: ./vendor/bin/phpunit --configuration phpunit-with-integration.xml

‎.github/workflows/prerelease.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build Plugin Pre-Release
2+
3+
on:
4+
release:
5+
types: [prereleased]
6+
7+
jobs:
8+
build:
9+
name: Build Plugin Artifact
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '7.4'
20+
tools: composer:v2
21+
coverage: none
22+
23+
- name: Install runtime dependencies
24+
working-directory: plugins/basicrum
25+
run: composer install --no-dev --no-interaction --prefer-dist
26+
27+
- name: Generate plugin artifact
28+
run: |
29+
set -e
30+
sudo apt-get update
31+
sudo apt-get install -y rsync zip
32+
33+
mkdir -p release/basicrum
34+
rsync -rc --exclude-from="$GITHUB_WORKSPACE/plugins/basicrum/.distignore" "$GITHUB_WORKSPACE/plugins/basicrum/" release/basicrum/ --delete --delete-excluded
35+
36+
cd "$GITHUB_WORKSPACE/release"
37+
zip -r "$GITHUB_WORKSPACE/basicrum.zip" basicrum
38+
39+
- name: Upload release asset
40+
uses: softprops/action-gh-release@v2
41+
with:
42+
files: basicrum.zip

‎.github/workflows/release.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release Plugin
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
build:
9+
name: Build Release Artifact
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '7.4'
20+
tools: composer:v2
21+
coverage: none
22+
23+
- name: Install runtime dependencies
24+
working-directory: plugins/basicrum
25+
run: composer install --no-dev --no-interaction --prefer-dist
26+
27+
- name: Generate plugin artifact
28+
run: |
29+
set -e
30+
sudo apt-get update
31+
sudo apt-get install -y rsync zip
32+
33+
mkdir -p release/basicrum
34+
rsync -rc --exclude-from="$GITHUB_WORKSPACE/plugins/basicrum/.distignore" "$GITHUB_WORKSPACE/plugins/basicrum/" release/basicrum/ --delete --delete-excluded
35+
36+
cd "$GITHUB_WORKSPACE/release"
37+
zip -r "$GITHUB_WORKSPACE/basicrum.zip" basicrum
38+
39+
- name: Upload release asset
40+
uses: softprops/action-gh-release@v2
41+
with:
42+
files: basicrum.zip

‎.gitignore‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# IDE
2+
.idea/
3+
.vscode/
4+
*.swp
5+
*.swo
6+
7+
# Composer
8+
/plugins/basicrum/vendor/
9+
10+
# Node
11+
/node_modules/
12+
13+
# PHPUnit
14+
.phpunit.result.cache
15+
coverage.xml
16+
/plugins/basicrum/.phpunit.result.cache
17+
/plugins/basicrum/coverage.xml
18+
19+
# Release artifacts
20+
/release/
21+
/basicrum.zip
22+
23+
# Local research and planning notes
24+
/plan-refs/
25+
/plugin-references/
26+
27+
# Translation backups
28+
*.pot~
29+
*.po~
30+
31+
# OS files
32+
.DS_Store
33+
Thumbs.db

‎.idea/workspace.xml‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Basicrum WordPress Plugin
2+
3+
`plugins/basicrum/` is the installable plugin. It uses the `Basicrum\WP`
4+
namespace, PSR-4 Composer autoloading, PHP 7.4+, and WordPress 6.0+.
5+
6+
## Structure
7+
8+
- `basicrum.php` is the bootstrap; `src/Plugin.php` registers services.
9+
- `src/Assets.php` injects Boomerang and config; `PageTypeDetector.php` sets
10+
`p_type`; `Compatibility.php` handles cache-plugin exclusions.
11+
- The standard loader is used without consent mode; consent mode uses the
12+
consent loader and exposes `OPT_IN_BASIC_RUM()` / `OPT_OUT_BASIC_RUM()` for
13+
integration with a site's consent banner.
14+
- Settings use the `basicrum_settings` option. Keep defaults, UI, and
15+
sanitization in sync in `Helpers`, `Admin\Settings\Page`, and
16+
`Admin\Settings\Validate`.
17+
- Add version-gated migrations to `Admin\Upgrades`; use the option/version
18+
constants from `Helpers`.
19+
20+
## Conventions
21+
22+
- Follow WordPress-Core/WPCS. The text domain is `basicrum`.
23+
- Guard PHP files with `ABSPATH`; escape output and sanitize all input.
24+
- Prefix hooks with `basicrum_`; use `Assets` handle constants rather than
25+
hard-coded script handles.
26+
- Boomerang lives in `assets/js/boomr/`; standard and consent loaders live in
27+
`assets/js/loaders/`.
28+
29+
## Checks
30+
31+
Run from the repository root:
32+
33+
```bash
34+
make composer-install
35+
make lint-php
36+
make unit
37+
make integration-setup
38+
make integration
39+
```
40+
41+
Unit tests use Brain\Monkey; integration tests use the WordPress test suite.

0 commit comments

Comments
 (0)