ulgm_management_shortcode
Filters the output of the ULGM management shortcode before it is displayed on the frontend.
add_filter( 'ulgm_management_shortcode', $callback, 10, 1 );
Description
Fires after the group management shortcode data is prepared, including messages from redirects. Developers can filter this array to modify or add custom data to the group management shortcode's output. The `$ulgm_management_shortcode` parameter is an array containing shortcode data.
Usage
add_filter( 'ulgm_management_shortcode', 'your_function_name', 10, 1 );
Parameters
-
$ulgm_management_shortcode(mixed) - This parameter, `$ulgm_management_shortcode`, is an array that holds data related to the group management shortcode, including any messages to be displayed.
Return Value
The filtered value.
Examples
<?php
/**
* Example function to modify the data passed to the 'ulgm_management_shortcode' filter.
* This example adds a custom 'user_role' key to the array if the current user has a specific role.
*
* @param array $shortcode_data The original array of data for the shortcode.
* @return array The modified array of data.
*/
function my_custom_ulgm_management_shortcode_data( $shortcode_data ) {
// Check if the current user is logged in.
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
// Check if the current user has the 'administrator' role.
if ( in_array( 'administrator', (array) $current_user->roles ) ) {
$shortcode_data['user_role'] = 'administrator';
} elseif ( in_array( 'editor', (array) $current_user->roles ) ) {
$shortcode_data['user_role'] = 'editor';
} else {
$shortcode_data['user_role'] = 'other';
}
} else {
$shortcode_data['user_role'] = 'guest';
}
// You could also modify existing keys, for example, by changing the message format.
if ( isset( $shortcode_data['message'] ) && ! empty( $shortcode_data['message'] ) ) {
$shortcode_data['message'] = 'Custom Prefix: ' . $shortcode_data['message'];
}
return $shortcode_data;
}
add_filter( 'ulgm_management_shortcode', 'my_custom_ulgm_management_shortcode_data', 10, 1 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/group-management/group-management-interface.php:1383
// Message is set by a redirect in the JS file
if ( ulgm_filter_has_var( 'message' ) ) {
self::$ulgm_management_shortcode['message'] = esc_html( wp_kses( ulgm_filter_input( 'message' ), array() ) );
} else {
self::$ulgm_management_shortcode['message'] = '';
}
self::$ulgm_management_shortcode = apply_filters( 'ulgm_management_shortcode', self::$ulgm_management_shortcode );
}
/**
* @return array
*/
private static function get_frontend_localized_strings() {