Skip to content
Snippets Groups Projects
Select Git revision
  • 6c970f957af11e6ba0a45833d2c0a3dd21eead19
  • master default protected
  • fix/deprecated_functions
  • devel
  • feat/translations
  • feat/upgrade_to_pro_url
  • feat/lang
  • bugfix/require-interface
  • bugfix/require-once-error
  • feature/activation-hooks
  • feature/template-loader
  • feature/template-renderer
  • feature/plugin-activation
  • feature/hookable-object
  • feature/builder-pattern
  • 2.1.2
  • 2.1.1
  • 2.1.0
  • 2.0.0
  • 2.0.0-beta1
  • 1.4.4
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4
  • 1.3.3
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.2.0
  • 1.1
  • 1.0
32 results

HookableParent.php

Blame
  • HookableParent.php 1.10 KiB
    <?php
    
    namespace WPDesk\PluginBuilder\Plugin;
    
    trait HookableParent {
    
    	/**
    	 * Hookable objects.
    	 *
    	 * @var array[Hookable]
    	 */
    	private $hookable_objects = array();
    
    	/**
    	 * Add hookable object.
    	 *
    	 * @param Hookable|HookablePluginDependant $hookable_object Hookable object.
    	 */
    	public function add_hookable( Hookable $hookable_object ) {
    		if ( $hookable_object instanceof HookablePluginDependant ) {
    			$hookable_object->set_plugin( $this );
    		}
    		$this->hookable_objects[] = $hookable_object;
    	}
    
    	/**
    	 * Get hookable instance.
    	 *
    	 * @param string $class_name Class name.
    	 *
    	 * @return false|Hookable
    	 */
    	public function get_hookable_instance_by_class_name( $class_name ) {
    		foreach ( $this->hookable_objects as $hookable_object ) {
    			if ( $hookable_object instanceof $class_name ) {
    				return $hookable_object;
    			}
    		}
    		return false;
    	}
    
    	/**
    	 * Run hooks method on all hookable objects.
    	 */
    	protected function hooks_on_hookable_objects() {
    		/** @var Hookable $hookable_object $hookable_object */
    		foreach ( $this->hookable_objects as $hookable_object ) {
    			$hookable_object->hooks();
    		}
    	}
    
    
    }