Search by

arraypress / wp-conditions

arraypress

A flexible conditions/rules engine for WordPress with admin UI, REST API search, and extensible condition types.

Package info

github.com/arraypress/wp-conditions

pkg:composer/arraypress/wp-conditions

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-08-25 15:44 UTC

This package is auto-updated.

Last update: 2026-09-04 18:14:50 UTC


README

Let a shop owner build a rule — "logged-in customers in the UK, on a weekend" — from an admin screen, and check it in code.

What it does

Anything with rules ends up needing this: a discount that applies to some carts, a fee that applies to some countries, a notice shown to some users. Hard-coding them means a release every time one changes; a settings field means parsing whatever the owner typed.

This gives the owner a builder — pick a condition, an operator, a value, and group them with any/all — and gives you one call that answers true or false.

Features

  • Register a set of rules with its own admin screen, from one call
  • Give owners built-in conditions — user role, country, day of week, cart total
  • Add a condition of your own, with its own operators and values
  • Group rules so any or all of them must match
  • Search for posts, terms and users inside a rule, rather than typing ids
  • Check a set from your own code, against whatever context you have
  • Ask which rules matched, when the answer needs explaining

Installation

composer require arraypress/wp-conditions

Quick start

Register the set, and the screen that edits it:

add_action( 'init', function () {
	register_conditions( 'discount_rule', [
		'labels'     => [
			'singular' => 'Discount Rule',
			'plural'   => 'Discount Rules',
		],
		'menu_icon'  => 'dashicons-tag',
		'conditions' => [ 'user_role', 'day_of_week', 'is_logged_in' ],
	] );
} );

Then, at the point the rule matters:

if ( check_conditions( 'discount_rule', [ 'user_id' => get_current_user_id() ] ) ) {
	// ...
}

check_conditions() is true when any rule set matches; check_all_conditions() requires all of them.

Behind a proxy

The IP and country conditions read the visitor's address from the request. Behind Cloudflare or a load balancer the address they see is the proxy's, and the real one arrives in a header any client could also send — so forwarded headers are believed only from proxies on a trusted list. Cloudflare's ranges are on it by default; add your own with the ARRAYPRESS_TRUSTED_PROXIES constant or the arraypress_trusted_proxies filter from wp-ip-utils.

Requirements

  • PHP 8.3 or later
  • WordPress 7.1 or later

License

GPL-2.0-or-later