Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
d0e956f
Add Composer-installable WordPress query argument builders
ephpicman Nov 12, 2026
30fd904
Fix Composer namespace mappings and test namespaces
ephpicman Nov 12, 2026
44a251a
Fix Composer namespace mappings and test namespaces
ephpicman Nov 12, 2026
501e1d5
Fix Composer namespace mappings and test namespaces
ephpicman Nov 12, 2026
f632459
Port comprehensive query argument builder unit tests
ephpicman Nov 12, 2026
fd1a953
Add Composer validation and PHPUnit CI
ephpicman Nov 12, 2026
b4a7b87
Align PHPUnit test class with its file name
ephpicman Nov 12, 2026
681456b
Add extensible WordPress query argument support
ephpicman Nov 12, 2026
f837c20
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
bba994d
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
9f85913
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
7b2b9d2
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
cc49953
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
28223a5
Preserve and expose complete WordPress query arguments
ephpicman Nov 12, 2026
6d375a0
Fix namespace and global references in query argument trait
ephpicman Nov 12, 2026
8b5dfe1
Complete date query argument helpers
ephpicman Nov 12, 2026
4091a51
Test full WordPress argument passthrough and date helpers
ephpicman Nov 12, 2026
3be8957
Document complete query argument passthrough
ephpicman Nov 12, 2026
28b3f50
Assert supported comment author ID arguments
ephpicman Nov 12, 2026
311b34b
Apply date comparisons to actual date clauses
ephpicman Nov 12, 2026
df7cf7d
Test comparisons on valid date clauses
ephpicman Nov 12, 2026
92156b2
Preserve WordPress user meta key array values
ephpicman Nov 12, 2026
917a26b
Test WordPress user meta key array support
ephpicman Nov 12, 2026
4127d9e
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
5656fc3
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
10c57db
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
fee6c6b
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
ea7678b
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
4fc75a0
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
29c59a4
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
3e1843e
Preserve WordPress query argument types and semantics
ephpicman Nov 12, 2026
cf0edad
Defer date column defaults to WordPress query context
ephpicman Nov 12, 2026
f946504
Add regression tests for WordPress argument compatibility
ephpicman Nov 12, 2026
62d4d92
Cover scalar post types and context-aware date defaults
ephpicman Nov 12, 2026
d04f648
Parse comma-separated exclusion identifiers consistently
ephpicman Nov 12, 2026
9fdbf88
Correct regression expectations for scalar post types and comma-separ…
ephpicman Nov 12, 2026
dba97e4
Remove unsupported network ID from Network Query builder test
ephpicman Nov 12, 2026
622fe35
Use WordPress context defaults for every date query helper
ephpicman Nov 12, 2026
00e54cc
Parse comma-separated term IDs in include and exclude helpers
ephpicman Nov 12, 2026
4a5e738
Fix escaped function name in include/exclude builder
ephpicman Nov 12, 2026
10cfa04
Leave default date columns to WordPress
ephpicman Nov 12, 2026
e558975
Correct PHP namespace and function separators
ephpicman Nov 12, 2026
fa564c5
Correct PHP namespace separators
ephpicman Nov 12, 2026
bf2d1ee
Preserve scalar post status query values
ephpicman Nov 12, 2026
bf43e47
Use integer site status query flags
ephpicman Nov 12, 2026
2c4b1c7
Cover WordPress post status and site flag compatibility
ephpicman Nov 12, 2026
094a55e
Assert integer values for site query flags
ephpicman Nov 12, 2026
c3879e5
Remove unsupported term ID query argument
ephpicman Nov 12, 2026
3818d26
Remove unsupported term query arguments from core tests
ephpicman Nov 12, 2026
a6f70f9
Match WordPress post order fallback
ephpicman Nov 12, 2026
f9a38fc
Match WordPress user order fallback
ephpicman Nov 12, 2026
cae7621
Test WordPress order fallback for post and user queries
ephpicman Nov 12, 2026
53b8852
Preserve null site query flags in compatibility test
ephpicman Nov 12, 2026
d309c18
Parse WordPress comma and space separated ID lists
ephpicman Nov 12, 2026
22595f9
Reuse ID list normalisation for exclusions
ephpicman Nov 12, 2026
12bbece
Test comma and whitespace separated term ID lists
ephpicman Nov 12, 2026
ca82971
Preserve WordPress post order arrays and correct status helpers
ephpicman Nov 12, 2026
7d290b2
Normalise existing date clauses before adding fluent conditions
ephpicman Nov 12, 2026
cfe9e53
Enforce WordPress term orderby string contract
ephpicman Nov 12, 2026
6766b0d
Add regression tests for WordPress query argument contracts
ephpicman Nov 12, 2026
c4ddc40
Correct regression test expectations for nested date clauses
ephpicman Nov 12, 2026
1b8f895
Fix post order argument type
ephpicman Nov 12, 2026
c1841de
Preserve initial meta query clauses
ephpicman Nov 12, 2026
5fca4d1
Preserve initial tax query clauses
ephpicman Nov 12, 2026
9f40b68
Test query argument compatibility fixes
ephpicman Nov 12, 2026
7997e24
Match WordPress tax clause detection
ephpicman Nov 12, 2026
181041b
Cover all WordPress tax clause forms
ephpicman Nov 12, 2026
10065bb
Fix OR composition for initial meta query clauses
ephpicman Nov 12, 2026
34285d8
Fix OR composition for initial tax query clauses
ephpicman Nov 12, 2026
1d2a1d0
Correct scalar taxonomy terms expectation
ephpicman Nov 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests

on:
push:
branches:
- "**"
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2

- name: Validate Composer configuration
run: composer validate --strict

- name: Install dependencies
run: composer update --prefer-dist --no-interaction

- name: Run unit tests
run: composer test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/.phpunit.cache/
/.phpunit.result.cache
/composer.lock
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,89 @@
# wordpress-database
# Pentarix WordPress Database

Composer-installable WordPress query argument builders with a fluent API.

This package currently provides the WordPress query argument-building capabilities extracted from Vertex Framework. It builds argument arrays; it does not execute queries or provide an ORM.

## Requirements

- PHP 8.0 or later
- WordPress 6.3 or later when passing generated arguments to WordPress APIs

## Installation

```bash
composer require pentarix/wordpress-database
```

Composer maps the `Pentarix\WordPressDatabase\` namespace to `src/` using PSR-4.

## Usage

```php
use Pentarix\WordPressDatabase\WordPress\MetaQueryArg;
use Pentarix\WordPressDatabase\WordPress\PostQueryArg;

$args = PostQueryArg::make()
->postType('product')
->postStatus('publish')
->postsPerPage(12)
->metaQuery(MetaQueryArg::make()->where('featured', true))
->toArray();

$query = new \\WP_Query($args);
```

## Available builders

- `CommentQueryArg`
- `DateQueryArg`
- `MetaQueryArg`
- `NetworkQueryArg`
- `PostQueryArg`
- `SiteQueryArg`
- `TaxQueryArg`
- `TermQueryArg`
- `UserQueryArg`

Supporting builders (`IncludeQueryArg`, `IncludeExcludeQueryArg`, `IncludeExcludeIsQueryArg`, and `SearchQueryArg`) are also available under `Pentarix\WordPressDatabase\WordPress`.

## Argument coverage

The main query builders retain the arguments supplied to their constructors and expose
`set()` and `setMany()` for WordPress query variables that do not have a dedicated
convenience method yet. These methods preserve the supplied key and value without
rewriting WordPress's query contract:

```php
$args = PostQueryArg::make()
->set('author', 12)
->set('post_mime_type', ['image/jpeg', 'image/png'])
->setMany([
'search_columns' => ['post_title', 'post_excerpt'],
'update_menu_item_cache' => false,
])
->toArray();
```

The builder-specific fluent methods remain the preferred interface for commonly used
arguments and nested query clauses. The generic setters provide pass-through coverage
for additional core arguments and custom query variables supported by WordPress hooks.
Values are passed to WordPress as supplied; WordPress remains responsible for query
interpretation and execution.

## Scope

The builders return arrays compatible with WordPress query APIs, including `WP_Query`, `WP_User_Query`, `WP_Comment_Query`, `WP_Term_Query`, and multisite query APIs.

They do not execute database queries, replace WordPress query classes, or bypass WordPress's query lifecycle. Direct SQL, custom-table CRUD, repositories, models, and migrations are outside the current scope.

## Development

```bash
composer install
composer test
```

## Licence

MIT. See [LICENSE](LICENSE).
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "pentarix/wordpress-database",
"description": "WordPress query argument builders with a fluent, Composer-autoloadable API.",
"type": "library",
"license": "MIT",
"require": {
"php": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5 || ^12.0"
},
"autoload": {
"psr-4": {
"Pentarix\\WordPressDatabase\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Pentarix\\WordPressDatabase\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit --configuration phpunit.xml"
},
"minimum-stability": "stable",
"prefer-stable": true
}
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true" failOnRisky="true" failOnWarning="true">
<testsuites>
<testsuite name="WordPress Database Unit Tests">
<directory>tests/WordPress</directory>
</testsuite>
</testsuites>
</phpunit>
95 changes: 95 additions & 0 deletions src/Utils/ArrayUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* @author Sina Kuhestani <sinakuhestani@gmail.com>
* @copyright 2026 Sina Kuhestani (EphpicMan)
* @link https://github.com/ephpicman GitHub
* @link https://www.linkedin.com/in/ephpicman LinkedIn
* @license See the LICENSE file in the project root.
*/

declare(strict_types=1);

namespace Pentarix\WordPressDatabase\Utils;

final class ArrayUtil
{
public static function castValues(
int|float|string|array $value,
callable $cast
): array {
$values = \is_array($value) ? $value : [$value];

return \array_values(
\array_unique(
\array_map($cast, $values),
SORT_REGULAR
)
);
}
public static function mergeCasted(
array $current,
int|float|string|array $value,
callable $cast
): array {
return \array_values(
\array_unique(
\array_merge(
$current,
self::castValues($value, $cast)
),
SORT_REGULAR
)
);
}

public static function normalizeUniqueStrings(array $values): array
{
return \array_values(
\array_unique(
\array_filter(
$values,
static function ($value): bool {
if (!\is_string($value)) {
throw new \InvalidArgumentException(
'Every value must be a string.'
);
}

return '' !== $value;
}
),
SORT_STRING
)
);
}

public static function mergeUnique(array ...$arrays): array
{
return \array_values(
\array_unique(
\array_merge(...$arrays),
SORT_REGULAR
)
);
}

public static function removeValues(
array $current,
array $values,
bool $strict = false
): array {
if (!$strict) {
return \array_values(
\array_diff($current, $values)
);
}

return \array_values(
\array_filter(
$current,
static fn($item): bool => !\in_array($item, $values, true)
)
);
}
}
20 changes: 20 additions & 0 deletions src/Utils/NumberUtil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* @author Sina Kuhestani <sinakuhestani@gmail.com>
* @copyright 2026 Sina Kuhestani (EphpicMan)
* @link https://github.com/ephpicman GitHub
* @link https://www.linkedin.com/in/ephpicman LinkedIn
* @license See the LICENSE file in the project root.
*/

declare(strict_types=1);
namespace Pentarix\WordPressDatabase\Utils;

final class NumberUtil
{
public static function absint(int|float|string $value): int
{
return (int) abs((float) $value);
}
}
Loading
Loading