Ejemplo n.º 1
0
/**
 * List all available addons. If an employee ID is provided, list what that 
 * employee can provide only.
 *
 * @since	1.4
 * @param	int		$employee_id	An employee user ID, otherwise query current user.
 * @param	bool	$price			True to display the formatted package price
 * @return	str		HTML formatted string listing package information
 */
function mdjm_list_available_addons($employee_id = 0, $price = false)
{
    if (!mdjm_packages_enabled()) {
        return __('No addons available', 'mobile-dj-manager');
    }
    if (!empty($employee_id)) {
        $addons = mdjm_get_addons_by_employee($employee_id, false);
    } else {
        $addons = mdjm_get_addons();
    }
    if (!$addons) {
        return __('No addons available', 'mobile-dj-manager');
    }
    $return = array();
    foreach ($addons as $addon) {
        $addon_price = '';
        if ($price) {
            $addon_price = ' ' . mdjm_currency_filter(mdjm_format_amount(mdjm_get_package_price($addon->ID)));
        }
        $return[] = get_the_title($addon->ID) . '' . $addon_price;
    }
    $return = apply_filters('mdjm_list_available_addons', $return, $price);
    return implode('<br />', $return);
}
Ejemplo n.º 2
0
/**
 * Addons List Shortcode.
 * 
 * @param	arr		$atts		Shortcode attributes. See $atts.
 * @param	str|int	$filter_value	The value to which to filter $filter_by. Default false (all).
 * @param	str		$list			List type to display. li for bulleted. Default p.
 * @param	bool	$cost			Whether or not display the price. Default false.
 *
 *
 */
function mdjm_shortcode_addons_list($atts)
{
    global $post;
    $atts = shortcode_atts(array('filter_by' => false, 'filter_value' => false, 'list' => 'p', 'desc' => false, 'desc_length' => mdjm_get_option('package_excerpt_length', 55), 'cost' => false, 'addon_class' => false, 'cost_class' => false, 'desc_class' => false), $atts, 'mdjm-addons');
    ob_start();
    $output = '';
    if (!empty($post) && 'mdjm-package' == get_post_type($post->ID)) {
        $package_addons = mdjm_get_package_addons($post->ID);
        $addons = array();
        foreach ($package_addons as $package) {
            $addons[] = mdjm_get_addon($package);
        }
    } elseif (!empty($atts['filter_by']) && !empty($atts['filter_value']) && $atts['filter_by'] != 'false' && $atts['filter_value'] != 'false') {
        // Filter addons by user
        if ($atts['filter_by'] == 'category') {
            $addons = mdjm_get_addons_in_category($atts['filter_value']);
        } elseif ($atts['filter_by'] == 'package') {
            if (!is_numeric($atts['filter_value'])) {
                // For backwards compatibility
                $package = mdjm_get_package_by('slug', $atts['filter_value']);
                if ($package) {
                    $atts['filter_value'] = $package->ID;
                }
            }
            $package_addons = mdjm_get_package_addons($atts['filter_value']);
            $addons = array();
            foreach ($package_addons as $package) {
                $addons[] = mdjm_get_addon($package);
            }
        } elseif ($atts['filter_by'] == 'user') {
            $addons = mdjm_get_addons_by_employee($atts['filter_value']);
        }
    } else {
        $addons = mdjm_get_addons();
    }
    /**
     * Output the results
     */
    if (!$addons) {
        $output .= '<p>' . __('No addons available', 'mobile-dj-manager') . '</p>';
    } else {
        // Check to start bullet list
        if ($atts['list'] == 'li') {
            $output .= '<ul>';
        }
        foreach ($addons as $addon) {
            // Output the remaining addons
            if (!empty($atts['list'])) {
                $output .= '<' . $atts['list'] . '>';
            }
            if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') {
                $output = '<span class="' . $atts['addon_class'] . '">';
            }
            $output .= $addon->post_title;
            if (!empty($atts['addon_class']) && $atts['addon_class'] != 'false') {
                $output = '</span>';
            }
            $cost = mdjm_get_addon_price($addon->ID);
            if (!empty($atts['cost']) && $atts['cost'] != 'false' && !empty($cost)) {
                if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') {
                    $output = '<span class="' . $atts['cost_class'] . '">';
                }
                $output .= '&nbsp;&ndash;&nbsp;' . mdjm_currency_filter(mdjm_format_amount($cost));
                if (!empty($atts['cost_class']) && $atts['cost_class'] != 'false') {
                    $output = '</span>';
                }
            }
            $desc = mdjm_get_addon_excerpt($addon->ID, $atts['desc_length']);
            if (!empty($atts['desc']) && $atts['desc'] != 'false' && !empty($desc)) {
                $output .= '<br />';
                if (!empty($atts['desc_class']) && $atts['desc_class'] != 'false') {
                    $output = '<span class="' . $atts['desc_class'] . '">';
                } else {
                    $output .= '<span style="font-style: italic; font-size: smaller;">';
                }
                $output .= $desc;
                $output .= '</span>';
            }
            if (!empty($atts['list'])) {
                $output .= '</' . $atts['list'] . '>';
            }
        }
        // Check to end bullet list
        if ($atts['list'] == 'li') {
            $output .= '</ul>';
        }
    }
    echo apply_filters('mdjm_shortcode_addons_list', $output);
    return ob_get_clean();
}