ulgm_group_mangement_group_dropdown_padding
Filters the padding applied to the group management group dropdown for finer control over its visual spacing.
add_filter( 'ulgm_group_mangement_group_dropdown_padding', $callback, 10, 2 );
Description
Filters the padding applied to group items in the dropdown. Developers can modify the input string and multiplier to customize the visual indentation for nested groups, aiding in hierarchical representation.
Usage
add_filter( 'ulgm_group_mangement_group_dropdown_padding', 'your_function_name', 10, 2 );
Parameters
-
$depth(mixed) - This parameter is an array containing default padding characters and a multiplier based on the current depth within the group hierarchy.
-
$depth(mixed) - This parameter holds an array containing the padding character and a multiplier based on the depth of the group in the dropdown hierarchy.
Return Value
The filtered value.
Examples
/**
* Modify the padding for group dropdown items to add more indentation for deeper levels.
*
* The default padding uses '— ' repeated by the depth. This filter allows
* customization of the input character and multiplier.
*
* @param array $padding An array containing 'input' (the character to repeat) and 'multiplier' (how many times to repeat it).
* @param int $depth The current depth of the item in the hierarchy.
* @return array The modified padding array.
*/
add_filter( 'ulgm_group_mangement_group_dropdown_padding', 'my_custom_group_dropdown_padding', 10, 2 );
function my_custom_group_dropdown_padding( $padding, $depth ) {
// Ensure we have a valid depth to avoid unexpected behavior.
if ( ! is_numeric( $depth ) || $depth < 0 ) {
$depth = 0;
}
// Add an extra indentation character for every two levels deeper.
$additional_indentation = floor( $depth / 2 );
// Combine the default input character with an extra character for the additional indentation.
$padding['input'] = '- ' . $padding['input']; // Prepend default dash with another dash.
$padding['multiplier'] = $depth + $additional_indentation; // Increase multiplier based on depth and extra indentation.
return $padding;
}
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/includes/class-walker-group-dropdown.php:60
src/includes/class-walker-group-dropdown.php:385
public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
$padding = apply_filters(
'ulgm_group_mangement_group_dropdown_padding',
[
'input' => '— ',
'multiplier' => $depth * 1
],
$depth
);
$pad = str_repeat( $padding['input'], $padding['multiplier'] );
if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
$args['value_field'] = 'ID';
}
$output .= "t<option class="level-$depth" value="" . esc_attr( $page->{$args['value_field']} ) . '"';
if ( $page->ID == $args['selected'] ) {
$output .= ' selected="selected"';
}
$output .= '>';
$title = $page->post_title;
if ( '' === $title ) {
/* translators: %d: ID of a post. */
$title = sprintf( __( '#%d (no title)' ), $page->ID );
}
/**
* Filters the page title when creating an HTML drop-down list of pages.
*
* @param string $title Page title.
* @param WP_Post $page Page data object.
*
* @since 3.1.0
*
*/
$title = apply_filters( 'list_pages', $title, $page );
$output .= $pad . esc_html( $title );
$output .= "</option>n";
}