Пример #1
0
/**
 * Load Scripts
 *
 * Enqueues the required scripts.
 *
 * @since	1.0
 * @return	void
 */
function kbs_load_scripts()
{
    global $post;
    $js_dir = KBS_PLUGIN_URL . 'assets/js/';
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '';
    //'.min';
    // Load AJAX scripts
    wp_register_script('kbs-ajax', $js_dir . 'kbs-ajax' . $suffix . '.js', array('jquery'), KBS_VERSION);
    wp_enqueue_script('kbs-ajax');
    wp_localize_script('kbs-ajax', 'kbs_scripts', apply_filters('kbs_ajax_script_vars', array('ajaxurl' => kbs_get_ajax_url(), 'ajax_loader' => KBS_PLUGIN_URL . 'assets/images/loading.gif', 'permalinks' => get_option('permalink_structure') ? '1' : '0', 'submit_ticket_loading' => __('Please Wait...', 'kb-support'), 'submit_ticket' => kbs_get_form_submit_label(), 'honeypot_fail' => __('Honeypot validation error', 'kb-support'))));
    if (!empty($post)) {
        if (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'kbs_submit')) {
            add_thickbox();
        }
    }
}
Пример #2
0
/**
 * Check if AJAX works as expected
 *
 * @since	1.0
 * @return	bool	True if AJAX works, false otherwise
 */
function kbs_test_ajax_works()
{
    // Check if the Airplane Mode plugin is installed
    if (class_exists('Airplane_Mode_Core')) {
        $airplane = Airplane_Mode_Core::getInstance();
        if (method_exists($airplane, 'enabled')) {
            if ($airplane->enabled()) {
                return true;
            }
        } else {
            if ($airplane->check_status() == 'on') {
                return true;
            }
        }
    }
    add_filter('block_local_requests', '__return_false');
    if (get_transient('_kbs_ajax_works')) {
        return true;
    }
    $params = array('sslverify' => false, 'timeout' => 30, 'body' => array('action' => 'kbs_test_ajax'));
    $ajax = wp_remote_post(kbs_get_ajax_url(), $params);
    $works = true;
    if (is_wp_error($ajax)) {
        $works = false;
    } else {
        if (empty($ajax['response'])) {
            $works = false;
        }
        if (empty($ajax['response']['code']) || 200 !== (int) $ajax['response']['code']) {
            $works = false;
        }
        if (empty($ajax['response']['message']) || 'OK' !== $ajax['response']['message']) {
            $works = false;
        }
        if (!isset($ajax['body']) || 0 !== (int) $ajax['body']) {
            $works = false;
        }
    }
    if ($works) {
        set_transient('_kbs_ajax_works', '1', DAY_IN_SECONDS);
    }
    return $works;
}