Last active
February 21, 2017 11:40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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