immediate/im-fabric-wordpress

This package is abandoned and no longer maintained. No replacement package was suggested.

The Immediate Fabric WordPress support package

1.3.0 2018-08-07 16:16 UTC

This package is not auto-updated.

Last update: 2019-01-29 14:51:30 UTC


README

The Immediate Fabric WordPress support package.

Introduction

This package is intended to solve two main issues when developing in WordPress:

  • Testability;
  • Loose typing.

It solves the first by wrapping certain calls to WordPress in an abstracted layer, allowing unit tests to reliably mock those calls to WordPress.

Loose typing is solved by converting loosely typed arguments into more predictable and testable Entities.

Installation

This package is intended as a support package, and is typically installed automatically when using the Fabric Plugin Skeleton. For the moment, it's necessary to include the repository reference in your plugin's composer.json.

"repositories": [
    {
        "type": "vcs",
        "url": "git@github.immediate.co.uk:WCP-Packages/im-fabric-wordpress.git"
    }
],

Requirements

  • PHP >=7.1
  • WordPress

Usage

This package tries to match the original WordPress function names where possible to lessen the learning curve and possible confusion when trying to use WordPress functionality. For the most part, WordPress snake_case functions are simply replaced by camelCase methods.

Actions

addAction(string $hook, Action $action)

Wrapper for the WordPress add_action function for hooks.

Usage

Instead of a standard callable as a second argument, addAction() expects a strictly typed Action object.

doAction(string $hook[, mixed $arg])

Wrapper for the WordPress do_action function for hooks.

Usage

This method matches the original functionality.

removeAction(string $hook, Action $action)

Wrapper for the WordPress remove_action function for hooks.

Usage

Instead of a standard callable as a second argument, removeAction() expects the exact same instance of the original Action that was added. If calling removeAction() from within the Action itself, you can pass in $this as the Action argument.

Filters

addFilter(string $hook, Filter $filter)

Wrapper for the WordPress add_filter function for hooks.

Usage

Instead of a standard callable as a second argument, addFilter() expects a strictly typed Filter object.

applyFilters(string $hook, mixed $value)

Wrapper for the WordPress apply_filters function for hooks.

Usage

This method matches the original functionality.

removeFiler(string $hook, Filter $filter)

Wrapper for the WordPress remove_filter function for hooks.

Usage

Instead of a standard callable as a second argument, removeFilter() expects the exact same instance of the original Filter that was added. If calling removeFilter() from within the Filter itself, you can pass in $this as the Filter argument.

Menus

registerMenuLocation(MenuLocation $menuLocation)

Wrapper for the WordPress register_nav_menu function for menu locations.

Usage

Instead of passing in string arguments for the location and description respectively, registerMenuLocation() expects a strictly typed MenuLocation object.

Widgets

registerWidgetArea(WidgetArea $widgetArea)

Wrapper for the WordPress register_sidebar function for widget areas.

Usage

Instead of passing in an array containing the widget area details, registerWidgetArea() expects a strictly typed WidgetArea object.

registerWidget(Widget $widget)

Wrapper for the WordPress register_widget function for widgets.

Usage

This method works in a similar way to the original functionality, but only accepts a strictly typed Widget object.