/**
 * Check if AJAX works as expected
 *
 * @since 2.2
 * @return bool True if AJAX works, false otherwise
 */
function edd_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('_edd_ajax_works')) {
        return true;
    }
    $params = array('sslverify' => false, 'timeout' => 30, 'body' => array('action' => 'edd_test_ajax'));
    $ajax = wp_remote_post(edd_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('_edd_ajax_works', '1', DAY_IN_SECONDS);
    }
    return $works;
}
Пример #2
0
 /**
  * Set default options on admin_init if option doesn't exist
  *
  * @since       1.0.0
  * @access      public
  * @return      void
  */
 private function _default_cleanup()
 {
     // Fix the global variable name
     if ($this->args['global_variable'] == "" && $this->args['global_variable'] !== false) {
         $this->args['global_variable'] = str_replace('-', '_', $this->args['opt_name']);
     }
     // Force dev_mode on WP_DEBUG = true and if it's a local server
     if (Redux_Helpers::isLocalHost() || Redux_Helpers::isWpDebug()) {
         if ($this->args['dev_mode'] != true) {
             $this->args['update_notice'] = false;
         }
         $this->dev_mode_forced = true;
         $this->args['dev_mode'] = true;
         if (isset($this->args['forced_dev_mode_off']) && $this->args['forced_dev_mode_off'] == true) {
             $this->dev_mode_forced = false;
             $this->args['dev_mode'] = false;
         }
     }
     // Auto create the page_slug appropriately
     if (empty($this->args['page_slug'])) {
         if (!empty($this->args['display_name'])) {
             $this->args['page_slug'] = sanitize_html_class($this->args['display_name']);
         } else {
             if (!empty($this->args['page_title'])) {
                 $this->args['page_slug'] = sanitize_html_class($this->args['page_title']);
             } else {
                 if (!empty($this->args['menu_title'])) {
                     $this->args['page_slug'] = sanitize_html_class($this->args['menu_title']);
                 } else {
                     $this->args['page_slug'] = str_replace('-', '_', $this->args['opt_name']);
                 }
             }
         }
     }
     if (isset($this->args['customizer_only']) && $this->args['customizer_only'] == true) {
         $this->args['menu_type'] = 'hidden';
         $this->args['customizer'] = true;
         $this->args['admin_bar'] = false;
         $this->args['allow_sub_menu'] = false;
     }
     // 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()) {
                 $this->args['use_cdn'] = false;
             }
         } else {
             if ($airplane->check_status() == 'on') {
                 $this->args['use_cdn'] = false;
             }
         }
     }
 }
Пример #3
0
 /**
  * If an instance exists, this returns it.  If not, it creates one and
  * returns it.
  *
  * @return $instance
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }