Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save overclokk/b413975015612ef56c02b829a02c3fcc to your computer and use it in GitHub Desktop.
Save overclokk/b413975015612ef56c02b829a02c3fcc to your computer and use it in GitHub Desktop.
<php
/**
* Class description
*/
class My_Class implements Subscriber_Interface {
/**
* Returns an array of hooks that this subscriber wants to register with
* the WordPress plugin API.
*
* @hooked italystrap_entry_content - 10
*
* @return array
*/
public static function get_subscribed_events() {
return array(
'italystrap_entry_content' => array(
'function_to_add' => 'render',
'priority' => apply_filters( 'italystrap_my_class_priority', 10 ),
),
);
}
/**
* Render the output of the controller.
*/
public function render() {
// Do somethings
}
}
/**
* The implementation
*/
$registered_classes = array(
'Another_Class' => '\ItalyStrap\Another_Class',
'My_Class' => array(
'\ItalyStrap\My_CLass',
40, // This is the new priority
),
);
foreach ( $registered_classes as $class_name => $value ) {
$class_name = strtolower( $class_name );
$prefixed_classname = "italystrap_{$class_name}";
if ( is_array( $value ) ) {
add_filter( "italystrap_{$class_name}_priority", function ( $priority ) use ( $value ) {
if ( ! isset( $value[1] ) ) {
return $priority;
}
return $value[1];
});
$value = $value[0];
}
$$prefixed_classname = $injector->make( $value ); // Auryn PHP DIC
$event_manager->add_subscriber( $$prefixed_classname );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment