zippovich2/wordpress-config

This package allows you to configure filters and actions via yaml config files.

v1.1.3 2020-02-06 13:53 UTC

This package is auto-updated.

Last update: 2024-10-29 05:41:12 UTC


README

Allows you to configure filters and actions via yaml config files.

Build Status Packagist

Installation

Requirements:

  • php ^7.2.5
$ composer require zippovich2/wordpress-config

Then load configs in your functions.php or right after the wp-settings.php file was included:

use WordpressWrapper\Config\Config;

//...

$config = new Config('path/to/config-dir');
$config->load();

Usage

Filters

# config/filters.yaml

filters:
  filter_name:
    - { callback: filter_callback_function, priority: 100, args: 1 }
  the_content:
    - { callback: Class::method }
    - { callback: Class::someFilter, priority: 1 }

Actions

# config/actions.yaml

actions:
  action_name:
    - { callback: action_callback_function, priority: 100, args: 1 }
  after_setup_theme:
    - { callback: App\Action\ThemeSettings::defaultOptions }

Callback prefix

You can set callback prefix to avoid long callbacks:

# config/actions.yaml

actions:
  action_name:
    - { callback: action_callback_function, priority: 100, args: 2 }
  after_setup_theme:
    - { callback: ThemeSettings::defaultOptions } # App\ActionPath\ThemeSettings:defaultOptions

callback_prefix: App\ActionPath\ # it's work only with classes

Default values

Actions

# config/actions.yaml

actions:
  action_name:
    - { callback: ~, priority: 10, args: 1 }

callback_prefix: App\Action\ 

Filters

# config/filters.yaml

filters:
  filter_name:
    - { callback: ~, priority: 10, args: 1 }

callback_prefix: App\Filter\