transliterate($str); // trim white spaces at beginning and end of alias and make lowercase $str = trim(mb_strtolower($str)); // remove any duplicate whitespace, and ensure all characters are alphanumeric $str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str); // trim dashes at beginning and end of alias $str = trim($str, '-'); return $str; } /** * Helper method to generate a WP shortcode. * * @param string $component The shortcode name (component). * @param array $attrs The shortcode args. * @param string $content The shortcode contents. */ public static function shortcode($component, $attrs = array(), $content = null) { $shortcode = ''; foreach ($attrs as $k => $v) { if (is_array($v)) { $v = implode(',', $v); } if (is_scalar($v)) { // encode single and double quotes $v = htmlentities($v, ENT_QUOTES); // encode left brackets $v = str_replace('[', '[', $v); // encode right brackets $v = str_replace(']', ']', $v); $shortcode .= " $k=\"$v\""; } } if ($content && is_string($content)) { $v = $content; // encode single and double quotes $v = htmlentities($v, ENT_QUOTES); // encode left brackets $v = str_replace('[', '[', $v); // encode right brackets $v = str_replace(']', ']', $v); $shortcode = " \"$v\""; } return "[{$component}$shortcode]"; } }