Set_Up_Automator::initialize_add_integrations()


Source Source

File: src/core/classes/class-set-up-automator.php

	public function initialize_add_integrations() {
		// Check each directory
		if ( self::$auto_loaded_directories ) {
			foreach ( self::$auto_loaded_directories as $directory ) {
				$files    = array();
				$dir_name = basename( $directory );
				if ( ! isset( self::$all_integrations[ $dir_name ] ) ) {
					continue;
				}

				$files[] = self::$all_integrations[ $dir_name ]['main'];
				if ( $files ) {
					foreach ( $files as $file ) {
						if ( file_exists( $file ) ) {
							require_once $file;

							$class = apply_filters( 'automator_integrations_class_name', $this->get_class_name( $file ), $file );
							try {
								$is_using_trait = ( new ReflectionClass( $class ) )->getTraits();
							} catch ( ReflectionException $e ) {
								throw new Automator_Exception( $e->getMessage() );
							}
							$i                = new $class();
							$integration_code = ! empty( $is_using_trait ) ? $i->get_integration() : $class::$integration;
							$active           = ! empty( $is_using_trait ) ? $i->plugin_active( null, null ) : $i->plugin_active( 0, $integration_code );
							$active           = apply_filters( 'automator_maybe_integration_active', $active, $integration_code );
							if ( true !== $active ) {
								unset( $i );
								continue;
							}
							/**
							 * Include only active integrations. Legacy method.
							 * @since 3.0, trait-integrations.php does not contains this function. Not required to define
							 * for each integration now.
							 * @see \Uncanny_Automator\Recipe\Integrations::add_integration()
							 *
							 */
							if ( method_exists( $i, 'add_integration_func' ) ) {
								$i->add_integration_func();
							}

							if ( ! in_array( $integration_code, self::$active_integrations_code, true ) ) {
								self::$active_integrations_code[] = $integration_code;
							}

							$this->active_directories[ $dir_name ] = $i;
							$this->active_directories              = apply_filters( 'automator_active_integration_directories', $this->active_directories );
							if ( method_exists( $i, 'add_integration_directory_func' ) ) {
								$directories_to_include = $i->add_integration_directory_func( array(), $file );
								if ( $directories_to_include ) {
									foreach ( $directories_to_include as $dir ) {
										$this->directories_to_include[ $dir_name ][] = basename( $dir );
									}
								}
							}

							//Now everything is checked, add integration to the system.
							if ( method_exists( $i, 'add_integration' ) ) {
								$i->add_integration( $i->get_integration(), array( $i->get_name(), $i->get_icon() ) );
							}

							Utilities::add_class_instance( $class, $i );
						}
					}
				}
			}
		}
	}