API
4 months ago
Admin
4 months ago
Blocks
4 months ago
CLI
4 months ago
Container
4 months ago
Data
4 months ago
Integrations
4 months ago
REST
4 months ago
Theme
4 months ago
Tools
4 months ago
WP
4 months ago
Whatsit
4 months ago
Config_Handler.php
4 months ago
Integration.php
4 months ago
Permissions.php
4 months ago
Pod_Manager.php
4 months ago
Service_Provider.php
4 months ago
Service_Provider_Base.php
4 months ago
Static_Cache.php
4 months ago
Whatsit.php
4 months ago
Wisdom_Tracker.php
4 months ago
Integration.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods; |
| 4 | |
| 5 | // Don't load directly. |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | die( '-1' ); |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Integration abstract class. |
| 12 | * |
| 13 | * @since 2.8.0 |
| 14 | */ |
| 15 | abstract class Integration { |
| 16 | |
| 17 | /** |
| 18 | * Integration hooks. |
| 19 | * |
| 20 | * @var array[] { |
| 21 | * @type array $action { |
| 22 | * @type callable $callback The callback or name of the method on current object. |
| 23 | * @type int $priority Priority. |
| 24 | * @type int $arguments Number of arguments. |
| 25 | * } |
| 26 | * @type array $filter { |
| 27 | * @type callable $callback The callbackor name of the method on current object. |
| 28 | * @type int $priority Priority. |
| 29 | * @type int $arguments Number of arguments. |
| 30 | * } |
| 31 | * } |
| 32 | */ |
| 33 | protected $hooks = [ |
| 34 | 'action' => [ |
| 35 | // 'name' => [ 'callback', 10, 2 ], |
| 36 | ], |
| 37 | 'filter' => [ |
| 38 | // 'name' => [ 'callback', 10, 2 ], |
| 39 | ], |
| 40 | ]; |
| 41 | |
| 42 | /** |
| 43 | * Whether the integration is active. |
| 44 | * |
| 45 | * @since 2.8.0 |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | public static function is_active() { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Add the class hooks. |
| 55 | * |
| 56 | * @since 2.8.0 |
| 57 | */ |
| 58 | public function hook() { |
| 59 | foreach ( $this->hooks as $type => $hooks ) { |
| 60 | foreach ( $hooks as $hook => $params ) { |
| 61 | if ( is_string( $params[0] ) && method_exists( $this, $params[0] ) ) { |
| 62 | $params[0] = [ $this, $params[0] ]; |
| 63 | } |
| 64 | |
| 65 | if ( ! is_callable( $params[0]) ) { |
| 66 | _doing_it_wrong( 'hook', 'Pods Integration should have a callable for the first hook parameter', '2.8.0' ); |
| 67 | } |
| 68 | |
| 69 | array_unshift( $params, $hook ); |
| 70 | call_user_func_array( 'add_' . $type, $params ); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | $this->post_hook(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Do any post-hook related functionality. |
| 79 | * |
| 80 | * @since 3.2.7 |
| 81 | */ |
| 82 | public function post_hook() {} |
| 83 | |
| 84 | /** |
| 85 | * Remove the class hooks. |
| 86 | * |
| 87 | * @since 2.8.0 |
| 88 | */ |
| 89 | public function unhook() { |
| 90 | foreach ( $this->hooks as $type => $hooks ) { |
| 91 | foreach ( $hooks as $hook => $params ) { |
| 92 | if ( is_string( $params[0] ) && is_callable( $this, $params[0] ) ) { |
| 93 | $params[0] = [ $this, $params[0] ]; |
| 94 | } |
| 95 | array_unshift( $params, $hook ); |
| 96 | call_user_func_array( 'remove_' . $type, $params ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | $this->post_unhook(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Do any post-unhook related functionality. |
| 105 | * |
| 106 | * @since 3.2.7 |
| 107 | */ |
| 108 | public function post_unhook() {} |
| 109 | |
| 110 | } |
| 111 |