handleShortcodeAsaCollection($options, $label); } } if (!function_exists('asa_item')) { /** * displays one item, can be used everywhere in php code, eg sidebar * * @param string $asin * @param null|string $tpl * @param array $options */ function asa_item($asin, $tpl = null, $options = array()) { echo wp_kses_asa(asa_get_item($asin, $tpl, $options)); } } if (!function_exists('asa_get_item')) { /** * return the rendered product template * * @param string $asin * @param null|string $tpl * @param array $options * @return string */ function asa_get_item($asin, $tpl = null, $options = array()) { global $asa; return $asa->getItem($asin, $tpl, $options); } } if (!function_exists('asa_get_tpl_name_from_options')) { /** * @param $options * @return null|string */ function asa_get_tpl_name_from_options($options) { $tplName = null; if (!is_array($options)) { $options = array($options); } foreach ($options as $k => $v) { if (empty($k) && is_string($v) && !empty($v)) { $tplName = $v; } } if (!isset($tplName) && isset($options['tpl'])) { $tplName = trim($options['tpl']); } return $tplName; } } if (!function_exists('asa_var_to_array')) { /** * @param $var * @return array */ function asa_var_to_array($var) { if (!is_array($var)) { if (empty($var)) { $var = array(); } else { $var = array($var); } } return $var; } } if (!function_exists('esc_html_asa')) { /** * Shortcut to prevent code duplication * * @param $text * @return string */ function esc_html_asa($text) { $safe_text = wp_check_invalid_utf8( $text ); // _wp_specialchars will break the output of HTML tags and makes the esc_html function useless for escaping vars containing HTML code // see: https://developer.wordpress.org/reference/functions/esc_html/#div-comment-595 //$safe_text = _wp_specialchars( $text ); // instead the contents between the HTML tags has to be escaped, so just don't check for "echo $somevar" but what is inside $somevar return $safe_text; } } if (!function_exists('wp_kses_asa')) { /** * Shortcut to prevent code duplication * * @param $string * @param array $allowed_html * @param array $allowed_protocols * @return string */ function wp_kses_asa($string, $allowed_html = [], $allowed_protocols = []) { // $allowed_html = array_merge([ // '