コード例 #1
0
ファイル: scripts.php プロジェクト: mdjm/mobile-dj-manager
/**
 * Load Admin Scripts
 *
 * Enqueues the required scripts for admin.
 *
 * @since	1.3
 * @return	void
 */
function mdjm_register_admin_scripts($hook)
{
    $js_dir = MDJM_PLUGIN_URL . '/assets/js/';
    wp_register_script('jquery-chosen', $js_dir . 'chosen.jquery.js', array('jquery'), MDJM_VERSION_NUM);
    wp_enqueue_script('jquery-chosen');
    wp_enqueue_script('jquery-ui-datepicker', array('jquery'));
    if (strpos($hook, 'mdjm')) {
        wp_enqueue_script('jquery');
    }
    $editing_event = false;
    $require_validation = array('mdjm-event_page_mdjm-comms');
    $sortable = array('admin_page_mdjm-custom-event-fields', 'admin_page_mdjm-custom-client-fields');
    if ('post.php' == $hook || 'post-new.php' == $hook) {
        if (isset($_GET['post']) && 'mdjm-addon' == get_post_type($_GET['post'])) {
            $sortable[] = 'post.php';
            $sortable[] = 'post-new.php';
        }
        if (isset($_GET['post']) && 'mdjm-event' == get_post_type($_GET['post'])) {
            $editing_event = true;
        }
        if (isset($_GET['post_type']) && 'mdjm-event' == $_GET['post_type']) {
            $editing_event = true;
        }
        if ($editing_event) {
            $require_validation[] = 'post.php';
            $require_validation[] = 'post-new.php';
        }
    }
    if (in_array($hook, $require_validation)) {
        wp_register_script('jquery-validation-plugin', '//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js', false);
        wp_enqueue_script('jquery-validation-plugin');
    }
    if (in_array($hook, $sortable)) {
        wp_enqueue_script('jquery-ui-sortable');
    }
    wp_register_script('mdjm-admin-scripts', $js_dir . 'admin-scripts.js', array('jquery'), MDJM_VERSION_NUM);
    wp_enqueue_script('mdjm-admin-scripts');
    wp_localize_script('mdjm-admin-scripts', 'mdjm_admin_vars', apply_filters('mdjm_admin_script_vars', array('ajaxurl' => mdjm_get_ajax_url(), 'current_page' => $hook, 'editing_event' => $editing_event, 'load_recipient' => isset($_GET['recipient']) ? $_GET['recipient'] : false, 'ajax_loader' => MDJM_PLUGIN_URL . '/assets/images/loading.gif', 'no_client_first_name' => __('Enter a first name for the client', 'mobile-dj-manager'), 'no_client_email' => __('Enter an email address for the client', 'mobile-dj-manager'), 'no_txn_amount' => __('Enter a transaction value', 'mobile-dj-manager'), 'no_txn_date' => __('Enter a transaction date', 'mobile-dj-manager'), 'no_txn_for' => __('What is the transaction for?', 'mobile-dj-manager'), 'no_txn_src' => __('Enter a transaction source', 'mobile-dj-manager'), 'no_venue_name' => __('Enter a name for the venue', 'mobile-dj-manager'), 'currency' => mdjm_get_currency(), 'currency_symbol' => mdjm_currency_symbol(), 'currency_sign' => mdjm_currency_filter(''), 'currency_position' => mdjm_get_option('currency_format', 'before'), 'currency_decimals' => mdjm_currency_decimal_filter(), 'deposit_is_pct' => 'percentage' == mdjm_get_event_deposit_type() ? true : false, 'update_deposit' => 'percentage' == mdjm_get_event_deposit_type() ? true : false, 'select_months' => __('Select Months', 'mobile-dj-manager'), 'one_month_min' => __('You must have a pricing option for at least one month', 'mobile-dj-manager'), 'one_item_min' => __('Select at least one Add-on', 'mobile-dj-manager'), 'min_travel_distance' => mdjm_get_option('travel_min_distance'), 'update_travel_cost' => mdjm_get_option('travel_add_cost', false))));
    wp_register_script('jquery-flot', $js_dir . 'jquery.flot.js');
    wp_enqueue_script('jquery-flot');
}
コード例 #2
0
/**
 * Determine the event deposit value based upon event cost and
 * payment settings
 *
 * @param	int|str		$price	Current price of event.
 */
function mdjm_calculate_deposit($price = '')
{
    $deposit_type = mdjm_get_event_deposit_type();
    if (empty($price) && 'fixed' != $deposit_type) {
        $deposit = 0;
    }
    if (empty($deposit_type)) {
        $deposit = '0';
    } elseif ($deposit_type == 'fixed') {
        $deposit = mdjm_get_option('deposit_amount');
    } elseif ($deposit_type == 'percentage') {
        $percentage = mdjm_get_option('deposit_amount');
        $deposit = !empty($price) && $price > 0 ? round($percentage * ($price / 100), 2) : 0;
    }
    apply_filters('mdjm_calculate_deposit', $deposit, $price);
    return mdjm_sanitize_amount($deposit);
}