pollora/wordpress-args

Manipulate WordPress arguments as an object.
11,366 2
Install
composer require pollora/wordpress-args
Latest Version:1.1.1
PHP:^8.2
Laravel:12 · 13
Older releases:11
License:MIT
Last Updated:Oct 7, 2026
Links: GitHub  ·  Packagist
Maintainer: pollora

WordPress Arguments turns an object into the arguments array that WordPress functions expect (register_post_type(), register_taxonomy(), WP_Query…). Add the ArgumentHelper trait to a class, give it one property per argument, and it builds the array for you: property names become snake_case keys, unset properties are left out, and raw arguments can be merged on top. It is for package authors who want a fluent, typed API over WordPress arguments instead of hand-written arrays.

Part of Pollora, the Laravel framework for WordPress. In a Pollora project it is already installed, as the base of pollora/query and pollora/entity.

Installation

composer require pollora/wordpress-args

Requires PHP 8.2+ and illuminate/support 12 or 13. Building the arguments calls WordPress's wp_parse_args(), so it runs inside WordPress.

Quick start

use Pollora\WordPressArgs\ArgumentHelper;

class BookPostType
{
    use ArgumentHelper;

    private ?bool $public = null;

    private ?bool $showInRest = null;

    private ?string $menuIcon = null;

    public function public(): self
    {
        $this->public = true;

        return $this;
    }

    public function showInRest(): self
    {
        $this->showInRest = true;

        return $this;
    }

    public function menuIcon(string $icon): self
    {
        $this->menuIcon = $icon;

        return $this;
    }

    public function getArgs(): array
    {
        return $this->buildArguments();
    }
}

$args = (new BookPostType)
    ->public()
    ->showInRest()
    ->setRawArgs(['has_archive' => 'books'])
    ->getArgs();

// [
//     'public' => true,
//     'show_in_rest' => true,
//     'has_archive' => 'books',
// ]

register_post_type('book', $args);

How it works

ArgumentHelper reads the properties declared on the class (all visibilities):

  • each property name is converted to snake_case with Laravel's Str::snake(): showInRest becomes show_in_rest;
  • properties whose value is null are skipped, so WordPress keeps its own defaults for them;
  • raw arguments set with setRawArgs() are merged last, with wp_parse_args(), and win over the properties of the same name.

Methods

Method Visibility Returns
extractArgumentFromProperties() public The arguments built from the properties only.
setRawArgs(array $rawArgs) public $this. Stores arguments to merge on top.
getRawArgs() public The raw arguments, or null.
buildArguments() protected The properties' arguments merged with the raw ones. Expose it from your class (for example as getArgs()).

rawArgs is the trait's own property and is never turned into an argument.

In the wild

  • pollora/entity: its Entity base class uses the trait, and getArgs() builds the arguments passed to post type and taxonomy registration.
  • pollora/query: PostQuery uses it to build the WP_Query arguments returned by getArguments().

Testing

vendor/bin/pest

Contributing

Contributions are welcome: see the contributing guide. Report security issues privately, as described in the security policy.

License

WordPress Arguments is open-source software licensed under the MIT license. © RuBee group

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

593,882,149 34,959
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

399,241,428 4,660

Version History

Version Released PHP Laravel License
1.1.1 ^8.2 ^12.0 || ^13.0 MIT
1.1.0 ^8.2 ^12.0 || ^13.0 GPL-2.0-or-later
1.0 ^11.0 GPL-2.0-or-later