[ 'label' => __( 'LMS', 'subscription' ), 'section' => __( 'Learning Management System', 'subscription' ), 'bg' => '#ede9fe', 'color' => '#6d28d9', ], 'crm' => [ 'label' => __( 'CRM', 'subscription' ), 'section' => __( 'Customer Relationship Management', 'subscription' ), 'bg' => '#fce7f3', 'color' => '#9d174d', ], 'automation' => [ 'label' => __( 'Automation', 'subscription' ), 'section' => __( 'Automation', 'subscription' ), 'bg' => '#e0f2fe', 'color' => '#0369a1', ], 'email' => [ 'label' => __( 'Email', 'subscription' ), 'section' => __( 'Email Marketing', 'subscription' ), 'bg' => '#dcfce7', 'color' => '#166534', ], 'license' => [ 'label' => __( 'License', 'subscription' ), 'section' => __( 'License Management', 'subscription' ), 'bg' => '#fef3c7', 'color' => '#92400e', ], ]; // Group third-party integrations by category, preserving the config order above // and appending any uncategorised ones under "Other". $third_party_grouped = []; foreach ( array_keys( $category_config ) as $cat_key ) { $third_party_grouped[ $cat_key ] = []; } foreach ( $third_party as $integration ) { $cat_key = $integration['category'] ?? ''; $cat_key = isset( $category_config[ $cat_key ] ) ? $cat_key : 'other'; $third_party_grouped[ $cat_key ][] = $integration; } $third_party_grouped = array_filter( $third_party_grouped ); /** * Facet counts for the filter bar. * * Derived from the same array the cards render from, so a count can never * disagree with what is on screen — including when filter_integration_actions() * has removed something, or when a future integration is added and nobody * remembers to update a hardcoded number. */ $subscrpt_status_of = static function ( array $integration ): string { if ( ! empty( $integration['is_active'] ) ) { return 'active'; } return ! empty( $integration['is_installed'] ) ? 'inactive' : 'not-installed'; }; $subscrpt_facets = [ 'category' => [], 'status' => [ 'active' => 0, 'inactive' => 0, 'not-installed' => 0, ], // No `recurring` facet: every integration that supports automatic // recurring is a payment gateway, so the chip selected exactly the same // six cards as the Payment Gateways category. The card badge still shows // it, where it says something about that one integration. 'tag' => [ 'free' => 0, 'pro' => 0, 'beta' => 0, ], ]; foreach ( $integrations as $integration ) { $cat_key = ( ( $integration['type'] ?? '' ) === 'payment_gateway' ) ? 'payment_gateway' : ( isset( $category_config[ $integration['category'] ?? '' ] ) ? $integration['category'] : 'other' ); $subscrpt_facets['category'][ $cat_key ] = ( $subscrpt_facets['category'][ $cat_key ] ?? 0 ) + 1; ++$subscrpt_facets['status'][ $subscrpt_status_of( $integration ) ]; if ( ! empty( $integration['is_pro'] ) ) { ++$subscrpt_facets['tag']['pro']; } else { ++$subscrpt_facets['tag']['free']; } if ( ! empty( $integration['is_beta'] ) ) { ++$subscrpt_facets['tag']['beta']; } } $subscrpt_total = count( $integrations ); // Labels for the category chips. Payment gateways are a `type`, not a // `category`, but on this page they read as one more group. // // The short `label` rather than the full `section`: in a 232px rail // "Customer Relationship Management" wraps to two lines and the group of // chips ends up taller than the viewport. The section headings above the // cards still spell it out in full. $subscrpt_category_labels = [ 'payment_gateway' => __( 'Payment Gateways', 'subscription' ) ]; foreach ( $category_config as $key => $cfg ) { $subscrpt_category_labels[ $key ] = $cfg['label'] ?? $cfg['section']; } $subscrpt_category_labels['other'] = __( 'Other', 'subscription' ); $subscrpt_status_labels = [ 'active' => __( 'Active', 'subscription' ), 'inactive' => __( 'Inactive', 'subscription' ), 'not-installed' => __( 'Not installed', 'subscription' ), ]; $subscrpt_tag_labels = [ 'free' => __( 'Free', 'subscription' ), 'pro' => __( 'Pro', 'subscription' ), 'beta' => __( 'Beta', 'subscription' ), ]; ?>