$provider_label ) { if ( ! is_string( $file ) || ! preg_match( '#^[A-Za-z0-9][A-Za-z0-9._-]*(?:/[A-Za-z0-9][A-Za-z0-9._-]*)*\.php$#D', $file ) || ! is_string( $provider_label ) || trim( $provider_label ) === '' ) { throw new \InvalidArgumentException( 'Integration provider is invalid.' ); } } $this->id = $id; $this->label = $label; $this->category = $category; $this->providers = $providers; } public function detect(): array { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $installed = get_plugins(); $found = array(); $edges = array(); foreach ( $this->providers as $file => $label ) { if ( ! is_string( $file ) || ! isset( $installed[ $file ] ) ) { continue; } $active = is_plugin_active( $file ); $found[] = array( 'file' => $file, 'label' => sanitize_text_field( $label ), 'active' => $active ); $edges[] = new Edge( 'edge:integration:' . $this->id . ':' . hash( 'sha256', $file ), 'plugin:' . $file, 'integration:' . $this->id, 'provides', 'high', array( 'evidence' => 'integration_detector' ) ); } if ( $found === array() ) { return array( 'nodes' => array(), 'edges' => array() ); } return array( 'nodes' => array( new Node( 'integration:' . $this->id, 'integration', $this->category, sanitize_text_field( $this->label ), 'unknown', 0, array( 'providers' => $found, 'active' => count( array_filter( $found, static function ( array $provider ): bool { return $provider['active']; } ) ) > 0 ) ) ), 'edges' => $edges, ); } }