Git Product home page Git Product logo

better-wordpress-hooks's People

Contributors

calvinalkan avatar gridpane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

better-wordpress-hooks's Issues

InvalidListenerException when creating multiple Events without method definition.

Assuming the following 2 Listener.

NewAppointment::class => [
			SendStaffBookingConfirmationEmail::class,
			StaffBookingCustomerSync::class,
		],

do not implement __invoke but use the default handleEvent method the ListenerFactory will throw an exception. This happens because for the second listener the "alias" is an integer with value 1. This value needs to be normalized before creating the listener.

Allow EventObjects to customize their payload

Sometimes EventObjects are pure data classes for one variable and the listener is not interested in the event object but only the variable. It would be good to have some sort of payload method on event objects which allows dictating the payload passed to the listeners when the event gets dispatched.

Allow mapped events to be resolved from the service container.

Currently mapped events are not loaded from the service container. In fact, they don't even go through the dispatcher flow at all. Instead, they are directly going through the WP hook API.

Create an option to pass an optional argument to mapped events to also resolve them from the service container

Implement a default() method for FilterableEvent

Allow Filterable events to define a default message that can optionally adjust the returned payload if the filtered value is either the same as the payload or if the filtered value is null or did not respect the API and return value of a filter.

Replace the ReflectsCallable trait with a more powerful class from another project

Replace the reflects callable trait with the ReflectionPayload class from another project of mine. This would allow to handle certain edge cases better and build the hook payload using the container by combining type-checks and parameter names. Right now the payload is passed by order into the listener which may cause a problem with certain edge cases with for example the init hook where WP-passes an empty string as the first argument.

https://github.com/calvinalkan/wp-mvc/blob/master/src/Support/ReflectionPayload.php

Allow binding events to interfaces

Right now it's not possible to create an event listener and bind it to an interface.
The dispatcher will flag it as an invalid listener since it's neither a closure nor an instance nor a callable.

[BUG] - Events are always WP Filters which is weird for some use cases

Using the following configuration:

$listeners => [

BookingCreated::class => [
        NotifyOwner::class, 
        NotifyAttendee::class
   ]
].

Both Listeners rely on the event object. This setup requires set NotifyOwner::class MUST return the received event which is weird. If the first listener does not return the event php NotifyAttendee::class will receive null due to WordPress resetting the value here.

The fix is easy. In the WordpressApi class that is the bridge to WP we just need a conditional check and use do_actioninstead of apply_filters respectively.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.