示例#1
0
    /**
     * Returns  one or more HTML <li> elements
     *
     * @param string $element_text
     * @param array $args {
     *
     *      @type string $before
     *      @type string $before_text
     *      @type string[]|string $attributes
     *      @type string $class
     *      @type string $after_text
     *      @type string $after
     *      @type callable $filter
     *      @type mixed $index
     * }
     * @return string
     */
    static function get_html_li_element_html($element_text, $args = array())
    {
        $args = wp_parse_args($args, array('before' => '', 'class' => '', 'attributes' => array(), 'before_text' => '', 'after_text' => '', 'after' => '', 'filter' => null, 'elements' => array(), 'index' => null));
        $before_text = $args['before_text'] ? esc_html($args['before_text']) : '';
        $element_text = $element_text ? esc_html($element_text) : '';
        $after_text = $args['after_text'] ? esc_html($args['after_text']) : '';
        if (!empty($args['attributes']['class'])) {
            $args['class'] = esc_attr("{$args['attributes']['class']} {$args['class']}");
            unset($args['attributes']['class']);
        }
        if ($args['filter']) {
            $args = call_user_func($args['filter'], $args, $element_text, $args['elements']);
        }
        $attributes = count($args['attributes']) ? $args['attributes'] : '';
        if ($attributes) {
            $attributes = ' ' . WPLib::get_html_attributes_html($attributes);
        }
        $elements_html .= <<<HTML
{$args['before']}<li{$attributes} class="{$args['class']}">{$before_text}{$element_text}{$after_text}</li>{$args['after']}
HTML;
        return $elements_html;
    }