*/ public function integrations(): array { /** * Filter the integrations shown on the Integrations screen. * * @param array $integrations */ $integrations = (array) apply_filters( 'submex_admin_integrations', array() ); usort( $integrations, static fn( array $a, array $b ): int => strcasecmp( (string) ( $a['title'] ?? '' ), (string) ( $b['title'] ?? '' ) ) ); return $integrations; } public function render(): void { if ( ! current_user_can( Menu::CAPABILITY ) ) { wp_die( esc_html__( 'You do not have permission to manage subscriptions.', 'submex' ) ); } App_Host::start( self::SLUG ); $this->render_screen(); App_Host::end(); } private function render_screen(): void { $integrations = $this->integrations(); Page_Shell::open( __( 'Integrations', 'submex' ), __( 'Hand a subscription to the plugin that delivers what it pays for, and take it back when it ends.', 'submex' ) ); if ( ! $integrations ) { printf( '

%s

%s

', esc_html__( 'Nothing to connect yet', 'submex' ), esc_html__( 'Integrations hand a subscription to the plugin that grants what it pays for — a course, a mailing list, a licence key. Submex Pro adds them.', 'submex' ) ); Page_Shell::close(); return; } $groups = array(); foreach ( $integrations as $integration ) { $category = (string) ( $integration['category'] ?? '' ); $category = '' !== $category ? $category : __( 'Other', 'submex' ); $groups[ $category ][] = $integration; } foreach ( $groups as $category => $items ) { echo '

' . esc_html( $category ) . '

'; foreach ( $items as $integration ) { $this->render_tile( $integration ); } echo '
'; } echo '

' . esc_html__( 'An integration only does anything while the plugin it connects to is active, and only for products you have configured it on.', 'submex' ) . '

'; Page_Shell::close(); } /** * @param array $integration */ private function render_tile( array $integration ): void { $active = ! empty( $integration['active'] ); $title = (string) ( $integration['title'] ?? '' ); $description = (string) ( $integration['description'] ?? '' ); echo '
'; $this->render_icon( $integration ); printf( '

%s

%s

', esc_html( $title ), esc_html( sprintf( /* translators: %s: the plugin an integration needs */ __( 'Needs %s', 'submex' ), (string) ( $integration['requires'] ?? $title ) ) ) ); if ( '' !== $description ) { echo '

' . esc_html( $description ) . '

'; } $hint = (string) ( $integration['hint'] ?? '' ); if ( '' !== $hint ) { echo '

' . esc_html( $hint ) . '

'; } printf( '
%s', $active ? 'submex-badge--good' : '', esc_html( $active ? __( 'Connected', 'submex' ) : __( 'Not active', 'submex' ) ) ); $this->render_configure( $integration ); $this->render_action( $integration, $active ); echo '
'; } /** * The plugin's WordPress.org icon when it has one, otherwise its initial: a broken * image in a grid of logos looks like the integration itself is broken. * * @param array $integration */ private function render_icon( array $integration ): void { $title = (string) ( $integration['title'] ?? '?' ); $icon = (string) ( $integration['icon'] ?? '' ); $first = strtoupper( function_exists( 'mb_substr' ) ? mb_substr( $title, 0, 1 ) : substr( $title, 0, 1 ) ); if ( '' === $icon ) { printf( '', esc_html( $first ) ); return; } printf( '', esc_attr( $first ), esc_url( $icon ) ); } /** * Install where we can, link out where the plugin is sold rather than hosted. */ private function render_action( array $integration, bool $active ): void { if ( $active ) { return; } $slug = (string) ( $integration['slug'] ?? '' ); if ( '' !== $slug && current_user_can( 'install_plugins' ) && current_user_can( 'activate_plugins' ) ) { printf( '', esc_attr( $slug ), esc_html__( 'Install', 'submex' ) ); return; } $url = (string) ( $integration['url'] ?? '' ); if ( '' === $url ) { return; } printf( '%s ', esc_url( $url ), esc_html__( 'Get it', 'submex' ) ); } /** * @param array $integration */ private function render_configure( array $integration ): void { $url = (string) ( $integration['configure_url'] ?? '' ); if ( '' === $url ) { return; } $label = (string) ( $integration['configure_label'] ?? '' ); printf( '%s', esc_url( $url ), esc_html( '' !== $label ? $label : __( 'Settings', 'submex' ) ) ); } }