Tribe__PUE__Notices::get_formatted_plugin_names_from_classes( array|string $plugins )
Transforms a list of plugins into human readable string.
Contents
Examples of output:
# One name
"Ticket Pro"
# Two names
"Ticket Pro and Calendar Legend"
# Three names
"Ticket Pro, Calendar Legend and Date Stars"
Parameters
- $plugins
-
(array|string) (Required) Array of plugin classes.
Return
(string|false)
Source
File: src/Tribe/PUE/Notices.php
public function get_formatted_plugin_names_from_classes( $plugins ) {
$plugin_list = [];
foreach ( (array) $plugins as $class_name ) {
$pue = tribe( Tribe__Dependency::class )->get_pue_from_class( $class_name );
if ( ! $pue ) {
continue;
}
if ( ! isset( $this->plugin_names[ $pue->pue_install_key ] ) ) {
continue;
}
$plugin_list[] = $this->plugin_names[ $pue->pue_install_key ];
}
$num_plugins = count( $plugin_list );
if ( 0 === $num_plugins ) {
return false;
}
if ( 1 === $num_plugins ) {
$html = current( $plugin_list );
} elseif ( 1 < $num_plugins ) {
$all_but_last = join( ', ', array_slice( $plugin_list, 0, count( $plugin_list ) - 1 ) );
$last = current( array_slice( $plugin_list, count( $plugin_list ) - 1, 1 ) );
$html = sprintf( _x( '%1$s and %2$s', 'formatted plugin list', 'tribe-common' ), $all_but_last, $last );
}
return '<span class="plugin-list">' . $html . '</span>';
}
Changelog
| Version | Description |
|---|---|
| 4.9.12 | Introduced. |