Skip to content

Commit c739d28

Browse files
authored
Merge pull request #69 from WebberZone/develop
Develop
2 parents 5082c80 + 3c05b1b commit c739d28

438 files changed

Lines changed: 94799 additions & 6809 deletions

File tree

Some content is hidden

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

.github/workflows/cs.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,15 @@ jobs:
3030
tools: cs2pr
3131
coverage: none
3232

33-
- name: 'Composer: set up PHPCS dependencies'
34-
run: |
35-
composer require --no-update squizlabs/php_codesniffer wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp dealerdirect/phpcodesniffer-composer-installer
36-
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
37-
3833
# Install dependencies and handle caching in one go.
3934
# @link https://github.com/marketplace/actions/install-composer-dependencies
4035
- name: Install Composer dependencies
4136
uses: "ramsey/composer-install@v3"
4237

43-
- name: 'Run Composer Update'
44-
run: |
45-
composer update
46-
4738
# Check the code-style consistency of the PHP files.
4839
- name: Check PHP code style
4940
continue-on-error: true
5041
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml
5142

5243
- name: Show PHPCS results in PR
53-
run: cs2pr --graceful-warnings ./phpcs-report.xml
44+
run: cs2pr --graceful-warnings ./phpcs-report.xml

.github/workflows/phpcompat.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: PHP Compatibility
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**.md'
7+
- '**.txt'
8+
pull_request:
9+
paths-ignore:
10+
- '**.md'
11+
- '**.txt'
12+
workflow_dispatch: {}
13+
14+
jobs:
15+
phpcompat:
16+
name: 'PHP Compatibility Check'
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: '8.0'
27+
coverage: none
28+
29+
# Create isolated environment for PHPCompatibility with PHPCS 4.x
30+
- name: Setup PHPCompatibility
31+
run: |
32+
mkdir phpcompat-tools
33+
cd phpcompat-tools
34+
composer init --name="temp/phpcompat" --type=project --no-interaction
35+
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
36+
composer require --dev \
37+
squizlabs/php_codesniffer:"^4.0" \
38+
phpcompatibility/php-compatibility:"dev-develop" \
39+
dealerdirect/phpcodesniffer-composer-installer:"^1.0" \
40+
--no-interaction
41+
42+
# Check PHP 7.4 through 8.5 compatibility
43+
- name: Check PHP Compatibility (7.4-8.5)
44+
run: |
45+
cd phpcompat-tools
46+
./vendor/bin/phpcs -p \
47+
--standard=PHPCompatibility \
48+
--runtime-set testVersion 7.4-8.5 \
49+
--extensions=php \
50+
--ignore=*/vendor/*,*/node_modules/*,*/tests/*,*/phpunit/*,*/freemius/* \
51+
../ || exit_code=$?
52+
53+
# Exit with the phpcs exit code (if set)
54+
exit ${exit_code:-0}

.github/workflows/unit-tests.yml

Lines changed: 30 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Unit Tests
22

33
on:
4-
# Run on all pushes and on all pull requests.
5-
# Prevent the build from running when there are only irrelevant changes.
64
push:
75
paths-ignore:
86
- '**.md'
@@ -11,7 +9,6 @@ on:
119
paths-ignore:
1210
- '**.md'
1311
- '**.txt'
14-
# Allow manually triggering the workflow.
1512
workflow_dispatch:
1613

1714
jobs:
@@ -21,105 +18,72 @@ jobs:
2118
strategy:
2219
fail-fast: false
2320
matrix:
24-
# Notes regarding supported versions in WP:
25-
# The base matrix only contains the PHP versions which are supported on all supported WP versions.
26-
php: ['8.0', '8.1', '7.4']
21+
php: ['7.4', '8.1', '8.2', '8.3']
2722
wp: ['latest']
28-
experimental: [false]
23+
mysql: ['8.0']
2924

3025
include:
31-
# Complement the builds run via the matrix with high/low WP builds for PHP 7.4 and 8.0.
32-
# PHP 8.0 is sort of supported since WP 5.6.
33-
# PHP 7.4 is supported since WP 5.3.
3426
- php: '8.3'
27+
wp: '6.6'
28+
mysql: '8.0'
29+
- php: '8.4'
3530
wp: 'latest'
31+
mysql: '8.0'
3632
experimental: true
37-
- php: '8.2'
33+
- php: '8.5'
3834
wp: 'latest'
35+
mysql: '8.0'
3936
experimental: true
40-
- php: '8.2'
41-
wp: '6.3'
42-
experimental: true
43-
- php: '8.0'
44-
wp: '5.9'
45-
experimental: true
46-
47-
name: "PHP ${{ matrix.php }} - WP ${{ matrix.wp }}"
4837

49-
continue-on-error: ${{ matrix.experimental }}
50-
51-
services:
52-
mysql:
53-
# WP 5.4 is the first WP version which largely supports MySQL 8.0.
54-
# See: https://core.trac.wordpress.org/ticket/49344
55-
# During the setting up of these tests, it became clear that MySQL 8.0
56-
# in combination with PHP < 7.4 is not properly/sufficiently supported
57-
# within WP Core.
58-
# See: https://core.trac.wordpress.org/ticket/52496
59-
image: mysql:${{ ( matrix.wp == 5.3 && '5.6' ) || ( (matrix.wp < 5.4 || matrix.php < 7.4) && '5.7' ) || '8.0' }}
60-
env:
61-
MYSQL_ALLOW_EMPTY_PASSWORD: false
62-
ports:
63-
- 3306:3306
64-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
38+
name: "PHP ${{ matrix.php }} - WP ${{ matrix.wp }} - MySQL ${{ matrix.mysql }}"
39+
continue-on-error: ${{ matrix.experimental == true }}
6540

6641
steps:
6742
- name: Checkout code
6843
uses: actions/checkout@v4
6944

45+
- name: Setup MySQL
46+
uses: ankane/setup-mysql@v1
47+
with:
48+
mysql-version: ${{ matrix.mysql }}
49+
7050
- name: Install PHP
7151
uses: shivammathur/setup-php@v2
7252
with:
7353
php-version: ${{ matrix.php }}
74-
extensions: mysqli, mysql
54+
extensions: mysqli
7555
coverage: none
7656

77-
# On WP 5.2, PHPUnit 5.x, 6.x and 7.x are supported.
78-
# On PHP >= 8.0, PHPUnit 7.5+ is needed, no matter what.
79-
- name: Determine supported PHPUnit version
80-
id: set_phpunit
57+
- name: Set PHPUnit version
8158
run: |
8259
if [[ "${{ matrix.php }}" > "8.0" ]]; then
8360
echo "PHPUNIT=9.*" >> $GITHUB_ENV
8461
else
8562
echo "PHPUNIT=5.7.*||6.*||7.5.*||8.5.*" >> $GITHUB_ENV
8663
fi
8764
88-
- name: 'Composer: set up PHPUnit'
89-
env:
90-
PHPUNIT: ${{ env.PHPUNIT }}
91-
run: composer require --no-update phpunit/phpunit:"${{ env.PHPUNIT }}"
65+
- name: Set up PHPUnit
66+
run: composer require --no-update phpunit/phpunit:"$PHPUNIT"
9267

93-
# Install dependencies and handle caching in one go.
94-
# @link https://github.com/marketplace/actions/install-composer-dependencies
95-
- name: Install Composer dependencies for PHP < 8.0
68+
- name: Install dependencies for PHP < 8.0
9669
if: ${{ matrix.php < 8.0 }}
97-
uses: "ramsey/composer-install@v2"
70+
uses: ramsey/composer-install@v3
9871

99-
# For the PHP 8.0 and above, we need to install with ignore platform reqs as not all dependencies allow it yet.
100-
- name: Install Composer dependencies for PHP >= 8.0
72+
- name: Install dependencies for PHP >= 8.0
10173
if: ${{ matrix.php >= 8.0 }}
102-
uses: "ramsey/composer-install@v2"
74+
uses: ramsey/composer-install@v3
10375
with:
10476
composer-options: --ignore-platform-reqs
10577

106-
- name: Install Subversion
107-
run: sudo apt-get install subversion
108-
109-
- name: Set up WordPress
110-
run: phpunit/install.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp }}
111-
112-
- name: Tool versions
78+
- name: Set up WordPress test environment
11379
run: |
114-
php --version
115-
composer --version
116-
./vendor/bin/phpunit --version
117-
which ./vendor/bin/phpunit
80+
sudo apt-get install -y subversion
81+
bash phpunit/install.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp }}
11882
119-
- name: Run the unit tests - single site
120-
run: ./vendor/bin/phpunit
83+
- name: Run tests (single site)
84+
run: vendor/bin/phpunit
12185

122-
- name: Run the unit tests - multisite
86+
- name: Run tests (multisite)
12387
env:
12488
WP_MULTISITE: 1
125-
run: ./vendor/bin/phpunit
89+
run: vendor/bin/phpunit

.github/workflows/zipitup.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ jobs:
2323
steps:
2424
- name: Checkout code
2525
uses: actions/checkout@v4
26+
2627
- name: Build project
2728
run: |
2829
mkdir build
30+
2931
- name: Create artifact
3032
uses: montudor/action-zip@v1
3133
with:
32-
args: zip -X -r build/${{ github.event.repository.name }}.zip . -x *.git* node_modules/\* .* "*/\.*" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md *.dist *.yml *.neon composer.* package.json dev-helpers** build** wporg-assets** phpunit**
34+
args: zip -X -r build/${{ github.event.repository.name }}.zip . -x *.git* node_modules/\* .* "*/\.*" "*/.git*" "*/.DS_Store" CODE_OF_CONDUCT.md CONTRIBUTING.md ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md CLAUDE.md *.dist *.yml *.neon composer.* package.json package-lock.json "dev-helpers/*" "build/*" "wporg-assets/*" "docs/*" "phpunit/*" phpstan-bootstrap.php build-assets.js
35+
3336
- name: Upload artifact
3437
uses: actions/upload-artifact@v4
3538
with:
@@ -40,4 +43,4 @@ jobs:
4043
with:
4144
args: build/${{ github.event.repository.name }}.zip application/zip
4245
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Ignore entire vendor except Freemius
2+
/vendor/*
3+
!/vendor/freemius/
4+
5+
# Tooling
6+
/phpcompat-tools/
7+
/node_modules/
8+
9+
# Lock files
10+
package-lock.json
11+
composer.lock
12+
13+
# Claude AI
14+
.claude/

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Plugin Overview
6+
7+
WebberZone Knowledge Base is a free WordPress plugin (namespace `WebberZone\Knowledge_Base`) that creates a multi-product knowledge base system. This is the standalone free version — there is no `includes/pro/` directory here. The companion premium plugin (knowledgebase-pro) is a separate repository that extends this codebase with pro features.
8+
9+
- **Plugin entry**: `knowledgebase.php` (defines constants, loads Freemius, triggers autoloader)
10+
- **PHP**: 7.4+ | **WordPress**: 6.7+
11+
- **Custom post type**: `wz_knowledgebase` | **Taxonomies**: `wzkb_category`, `wzkb_product`, `wzkb_tag`
12+
- **Constants**: `WZKB_VERSION`, `WZKB_PLUGIN_DIR`, `WZKB_PLUGIN_URL`, `WZKB_PLUGIN_FILE`, `WZKB_DEFAULT_THUMBNAIL_URL`
13+
14+
## Build & Development Commands
15+
16+
### PHP
17+
18+
```bash
19+
composer install # Install dependencies
20+
composer test # Run phpcs + phpcompat + phpstan
21+
composer phpcs # WordPress coding standards check
22+
composer phpcbf # Auto-fix coding standards
23+
composer phpstan # Static analysis (Level 5)
24+
composer phpcompat # PHP 7.4–8.5 compatibility check
25+
vendor/bin/phpunit # Run unit tests
26+
vendor/bin/phpunit --filter TestName # Run a single test by name
27+
WP_MULTISITE=1 vendor/bin/phpunit # Run multisite unit tests
28+
```
29+
30+
### JavaScript / Blocks
31+
32+
```bash
33+
npm run build # Build all blocks (runs build:free + build:pro)
34+
npm run build:free # Build all free blocks
35+
npm run build:assets # Minify CSS/JS and generate RTL
36+
npm run start # Watch mode for free blocks
37+
npm run lint:js # Lint JavaScript
38+
npm run lint:css # Lint CSS
39+
npm run format # Auto-format JS and CSS
40+
```
41+
42+
Individual block builds: `npm run build:[kb|articles|sections|products|search|breadcrumb|related|alerts]`
43+
44+
Note: `package.json` also contains `build:pro` and `build:rating` scripts that reference `includes/pro/` — these are irrelevant in this repository and will fail if run here.
45+
46+
### Distribution
47+
48+
```bash
49+
composer zip # Create PHP distribution zip
50+
npm run zip # Create full plugin zip (wp-scripts plugin-zip)
51+
```
52+
53+
## Architecture
54+
55+
### Main Bootstrap Flow
56+
57+
1. `plugins_loaded` hook → `Main::get_instance()` (singleton)
58+
2. `Main::init()` instantiates all component handlers and registers their hooks
59+
3. Admin components only load on `is_admin()` (deferred to `init` action for translation readiness)
60+
4. `Main` has `$pro` and `$is_pro_enabled` properties defined but they are never set in this repository — those are only used by the pro plugin
61+
62+
### Key Patterns
63+
64+
**Autoloader** (`includes/autoloader.php`): PSR-4 style. Converts `WebberZone\Knowledge_Base\Admin\Settings``includes/admin/class-settings.php`.
65+
66+
**Hook Registry** (`includes/util/class-hook-registry.php`): Custom wrapper around WordPress actions/filters with duplicate prevention and closure support. All components register hooks through this instead of calling `add_action()`/`add_filter()` directly.
67+
68+
**Settings**: Global `$wzkb_settings` populated at plugin load. Read via `wzkb_get_option( $key )` or `wzkb_get_settings()`. Settings page in `includes/admin/class-settings.php`. Stored as a single serialized array under option key `wzkb_settings`. All settings filters use the prefix `wzkb_` (e.g. `wzkb_get_option_{$key}`).
69+
70+
**Caching** (`includes/util/class-cache.php`): Term meta-based caching (not transients) with expiry timestamps. AJAX endpoint for admin cache clearing.
71+
72+
**Free/Pro coexistence**: The plugin includes deactivation logic in `knowledgebase.php` — activating either the free or pro plugin automatically deactivates the other and shows an admin notice.
73+
74+
### Component Map
75+
76+
| Directory | Responsibility |
77+
|---|---|
78+
| `includes/admin/` | Settings UI, columns, wizard, notices, activation |
79+
| `includes/frontend/` | Templates, display, shortcodes, styles, search, breadcrumbs, related articles, feeds, patterns |
80+
| `includes/blocks/` | 8 free Gutenberg blocks (React in `src/`, compiled to `build/`) |
81+
| `includes/rest/` | REST API under `/wzkb/v1/` namespace |
82+
| `includes/widgets/` | 4 classic WordPress widgets (Articles, Sections, Breadcrumb, Products) |
83+
| `includes/util/` | Hook registry, caching utilities, helpers |
84+
85+
### Block Development
86+
87+
Blocks are in `includes/blocks/src/[block-name]/`. Each block has its own `block.json`, React `edit.js`, and server-side render via PHP. After editing block source, run `npm run build:[block-name]` — never edit files in `build/` directly.
88+
89+
### Public Helper Functions
90+
91+
`includes/functions.php` exposes the plugin's public API. Key functions:
92+
- `wzkb_knowledge()` — render the full KB output
93+
- `wzkb_get_option( $key )` / `wzkb_get_settings()` — read settings (prefer over `get_option()` directly)
94+
- `wzkb_get_breadcrumb()`, `wzkb_get_search_form()`, `wzkb_get_alert()`, `wzkb_related_articles()` — frontend rendering helpers
95+
- `wzkb_get_the_post_thumbnail()` — thumbnail retrieval (supports ACF image fields)
96+
- `wzkb_get_kb_url()`, `wzkb_get_product_sections_list()`, `wzkb_get_term_hierarchy_path()` — URL and taxonomy helpers
97+
98+
### REST API
99+
100+
Endpoints under `/wzkb/v1/`: `/sections` (product sections), `/knowledgebase` (list), `/knowledgebase/{id}` (single). Responses are object-cached under group `wzkb_rest` (300 s TTL); cache is invalidated on post save/delete and term changes.
101+
102+
## Code Quality Configuration
103+
104+
- **PHPCS**: `phpcs.xml.dist` — WordPress coding standards
105+
- **PHPStan**: `phpstan.neon.dist` — Level 5 strict analysis; baseline in `phpstan-baseline.neon`
106+
- **PHPUnit**: `phpunit.xml.dist` — test configuration, tests in `phpunit/tests/`

LICENSE.txt

100755100644
File mode changed.

0 commit comments

Comments
 (0)