API
1 day ago
Admin
1 day ago
Blocks
1 day ago
CLI
1 day ago
Container
1 day ago
Data
1 day ago
Integrations
1 day ago
REST
1 day ago
Theme
1 day ago
Tools
1 day ago
Whatsit
1 day ago
Config_Handler.php
1 day ago
Integration.php
1 day ago
Permissions.php
1 day ago
Pod_Manager.php
1 day ago
Service_Provider.php
1 day ago
Service_Provider_Base.php
1 day ago
Service_Provider_Fallback.php
1 day ago
Static_Cache.php
1 day ago
Whatsit.php
1 day ago
Wisdom_Tracker.php
1 day ago
Integration.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods; |
| 4 | |
| 5 | /** |
| 6 | * Integration abstract class. |
| 7 | * |
| 8 | * @since 2.8.0 |
| 9 | */ |
| 10 | abstract class Integration { |
| 11 | |
| 12 | /** |
| 13 | * Integration hooks. |
| 14 | * |
| 15 | * @var array[] { |
| 16 | * @type array $action { |
| 17 | * @type callable $callback The callback. |
| 18 | * @type int $priority Priority. |
| 19 | * @type int $arguments Number of arguments. |
| 20 | * } |
| 21 | * @type array $filter { |
| 22 | * @type callable $callback The callback. |
| 23 | * @type int $priority Priority. |
| 24 | * @type int $arguments Number of arguments. |
| 25 | * } |
| 26 | * } |
| 27 | */ |
| 28 | protected $hooks = [ |
| 29 | 'action' => [ |
| 30 | // 'name' => [ 'callback', 10, 2 ], |
| 31 | ], |
| 32 | 'filter' => [ |
| 33 | // 'name' => [ 'callback', 10, 2 ], |
| 34 | ], |
| 35 | ]; |
| 36 | |
| 37 | /** |
| 38 | * Whether the integration is active. |
| 39 | * |
| 40 | * @since 2.8.0 |
| 41 | * |
| 42 | * @return bool |
| 43 | */ |
| 44 | public static function is_active() { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Add the class hooks. |
| 50 | * |
| 51 | * @since 2.8.0 |
| 52 | */ |
| 53 | public function hook() { |
| 54 | foreach ( $this->hooks as $type => $hooks ) { |
| 55 | foreach ( $hooks as $hook => $params ) { |
| 56 | if ( is_string( $params[0] ) && is_callable( [ $this, $params[0] ] ) ) { |
| 57 | $params[0] = [ $this, $params[0] ]; |
| 58 | } |
| 59 | array_unshift( $params, $hook ); |
| 60 | call_user_func_array( 'add_' . $type, $params ); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Remove the class hooks. |
| 67 | * |
| 68 | * @since 2.8.0 |
| 69 | */ |
| 70 | public function unhook() { |
| 71 | foreach ( $this->hooks as $type => $hooks ) { |
| 72 | foreach ( $hooks as $hook => $params ) { |
| 73 | if ( is_string( $params[0] ) && is_callable( $this, $params[0] ) ) { |
| 74 | $params[0] = [ $this, $params[0] ]; |
| 75 | } |
| 76 | array_unshift( $params, $hook ); |
| 77 | call_user_func_array( 'remove_' . $type, $params ); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | } |
| 83 |