# easy-bootstrap-shortcodes/trunk/shortcode/dropdown/plugin_shortcode.php

Easy Bootstrap Shortcode, version trunk. 105 lines.

- Page: https://pluginprobe.com/plugins/easy-bootstrap-shortcodes/trunk/code/shortcode/dropdown/plugin_shortcode.php
- Raw: https://pluginprobe.com/plugins/easy-bootstrap-shortcodes/trunk/raw/shortcode/dropdown/plugin_shortcode.php
- Modified: 2026-08-06T19:58:08+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/easy-bootstrap-shortcodes/trunk/code/shortcode/dropdown/plugin_shortcode.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use EBS\Security\Sanitizer;

function osc_theme_dropdown( $params, $content = null ) {
	$atts = shortcode_atts(
		array(
			'dropup' => '',
			'class'  => '',
		),
		$params
	);

	$content = str_replace( ']<br />', ']', $content );
	$content = str_replace( "]<br />\n", ']', $content );
	$content = str_replace( "<br />\n[", '[', $content );

	$dropup = 'dropup' === $atts['dropup'] ? 'dropup' : '';
	$class  = Sanitizer::class_list( $atts['class'] );

	$out  = '<div class="btn-group ' . $dropup . ' ' . $class . EBS_CONTAINER_CLASS . '">' . do_shortcode( $content ) . '</div>';
	$out .= "
    <script>
       jQuery(document).ready(function(){
        jQuery('.dropdown-toggle').dropdown();
        });
    </script>
    ";

	return $out;
}

ebs_backward_compatibility_callback( 'dropdown', 'osc_theme_dropdown' );

function osc_theme_dropdown_head( $params, $content = null ) {
	$atts = shortcode_atts(
		array(
			'size'  => '',
			'style' => '',
			'split' => '',
		),
		$params
	);

	$size    = Sanitizer::class_list( $atts['size'] );
	$style   = Sanitizer::class_list( $atts['style'] );
	$content = do_shortcode( $content );
	$out     = '';

	if ( 'split' === $atts['split'] ) {
		$out  = '<button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . '">' . $content . '</button>';
		$out .= '<button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . ' dropdown-toggle" data-toggle="dropdown">';
		$out .= '<span class="caret' . EBS_CONTAINER_CLASS . '"></span></button>';
	} else {
		$out  = ' <button type="button" class="btn ' . $size . ' ' . $style . EBS_CONTAINER_CLASS . ' dropdown-toggle" data-toggle="dropdown">';
		$out .= $content . ' <span class="caret' . EBS_CONTAINER_CLASS . '"></span> </button>';
	}

	return $out;
}

ebs_backward_compatibility_callback( 'dropdownhead', 'osc_theme_dropdown_head' );

function osc_theme_dropdown_body( $params, $content = null ) {
	$content = str_replace( ']<br />', ']', $content );
	$content = str_replace( "]<br />\n", ']', $content );
	$content = str_replace( "<br />\n[", '[', $content );

	$out = '<ul class="dropdown-menu' . EBS_CONTAINER_CLASS . '" role="menu">' . do_shortcode( $content ) . '</ul>';

	return $out;
}

ebs_backward_compatibility_callback( 'dropdownbody', 'osc_theme_dropdown_body' );

function osc_theme_dropdown_items( $params, $content = null ) {
	$atts = shortcode_atts(
		array(
			'type'     => '',
			'link'     => '',
			'disabled' => '',
		),
		$params
	);

	$out  = '';
	$link = Sanitizer::url( $atts['link'] );

	if ( 'divider' === $atts['type'] ) {
		$out = '<li class="divider' . EBS_CONTAINER_CLASS . '"></li>';
	} elseif ( 'menuitem' === $atts['type'] ) {
		if ( 'disabled' === $atts['disabled'] ) {
			$out = '<li class="disabled' . EBS_CONTAINER_CLASS . '"><a class="' . EBS_CONTAINER_CLASS . '" href="' . $link . '">' . do_shortcode( $content ) . '</a></li>';
		} else {
			$out = '<li><a class="' . EBS_CONTAINER_CLASS . '" href="' . $link . '">' . do_shortcode( $content ) . '</a></li>';
		}
	}

	return $out;
}

ebs_backward_compatibility_callback( 'dropdownitem', 'osc_theme_dropdown_items' );

```
