WPGraphQL
3 years ago
Enfold.php
4 years ago
Genesis.php
4 years ago
Jetpack.php
4 years ago
Polylang.php
2 years ago
Service_Provider.php
3 years ago
WPML.php
4 years ago
YARPP.php
4 years ago
Service_Provider.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods\Integrations; |
| 4 | |
| 5 | use Pods\Integration; |
| 6 | |
| 7 | /** |
| 8 | * Class Service_Provider |
| 9 | * |
| 10 | * Add third party integrations where needed. |
| 11 | * @todo Make all integrations inherit the Integration abstract class and use loops. |
| 12 | * |
| 13 | * @since 2.8.0 |
| 14 | */ |
| 15 | class Service_Provider extends \Pods\Service_Provider_Base { |
| 16 | |
| 17 | protected $integrations = []; |
| 18 | |
| 19 | /** |
| 20 | * Registers the classes and functionality needed for third party integrations. |
| 21 | * |
| 22 | * @since 2.8.0 |
| 23 | */ |
| 24 | public function register() { |
| 25 | |
| 26 | $this->integrations = [ |
| 27 | 'polylang' => Polylang::class, |
| 28 | 'wpml' => WPML::class, |
| 29 | 'enfold' => Enfold::class, |
| 30 | ]; |
| 31 | |
| 32 | foreach ( $this->integrations as $integration ) { |
| 33 | $this->container->singleton( $integration, $integration ); |
| 34 | } |
| 35 | |
| 36 | $this->container->singleton( 'pods.integration.genesis', Genesis::class ); |
| 37 | $this->container->singleton( 'pods.integration.yarpp', YARPP::class ); |
| 38 | $this->container->singleton( 'pods.integration.jetpack', Jetpack::class ); |
| 39 | |
| 40 | $this->hooks(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Hooks all the methods and actions the class needs. |
| 45 | * |
| 46 | * @since 2.8.0 |
| 47 | */ |
| 48 | protected function hooks() { |
| 49 | |
| 50 | add_filter( 'pods_admin_config_pod_fields_post_type_supported_features', $this->container->callback( 'pods.integration.genesis', 'add_post_type_supports' ) ); |
| 51 | add_filter( 'pods_admin_config_pod_fields_post_type_supported_features', $this->container->callback( 'pods.integration.yarpp', 'add_post_type_supports' ) ); |
| 52 | add_filter( 'pods_admin_config_pod_fields_post_type_supported_features', $this->container->callback( 'pods.integration.jetpack', 'add_post_type_supports' ) ); |
| 53 | |
| 54 | if ( ! did_action( 'plugins_loaded' ) ) { |
| 55 | add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 56 | } else { |
| 57 | $this->plugins_loaded(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * All plugins are loaded. |
| 63 | * |
| 64 | * @since 2.8.0 |
| 65 | */ |
| 66 | public function plugins_loaded() { |
| 67 | |
| 68 | /** |
| 69 | * Filter what integration classes should run on the plugins_loaded hook. |
| 70 | * |
| 71 | * @since 2.8.0 |
| 72 | * |
| 73 | * @param \Pods\Integration[] $integrations The list of integrations to run on plugins_loaded hook. |
| 74 | */ |
| 75 | $integrations = apply_filters( 'pods_integrations_on_plugins_loaded', $this->integrations ); |
| 76 | foreach ( $integrations as $class ) { |
| 77 | if ( is_string( $class ) ) { |
| 78 | $class = $this->container->make( $class ); |
| 79 | } |
| 80 | if ( $class instanceof Integration ) { |
| 81 | if ( $class->is_active() ) { |
| 82 | $class->hook(); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 |