function wped_verify_spf()
{
    if (empty($_POST['domain'])) {
        die('-1');
    } else {
        $domain = $_POST['domain'];
    }
    if (!current_user_can('manage_options')) {
        die('-1');
    }
    $url = 'https://gateway.wped.co/';
    //$url = 'http://spnl.dev/';
    $verify_ssl = true;
    if (wped_get_option('enable_nossl')) {
        $verify_ssl = false;
        $url = 'http://api.wped.co/';
        $info['X-WPED'] = "nossl";
    }
    $url = $url . 'domain/spf/' . $domain;
    $response = wp_remote_get($url);
    $body = '';
    if (is_array($response)) {
        $header = $response['headers'];
        // array of http header lines
        $body = $response['body'];
        // use the content
        $b2 = json_decode($body);
    }
    if ($b2->success == true) {
        wped_set_option('spf_verified', $domain);
    } else {
        wped_set_option('spf_verified', false);
    }
    echo $body;
    die;
}
 /**
  * Build settings fields
  * @return array Fields to be displayed on settings page
  */
 private function settings_fields()
 {
     $settings['standard'] = array('title' => __('Setup', 'wp-email-delivery'), 'description' => __('Just enter your API key and enjoy sending via our API. You don\'t even need to worry about your hosting provider blocking SMTP ports. <br>WPED doesn\'t use SMTP so your hosting provider can\'t block it.', 'wp-email-delivery'), 'fields' => array(array('id' => 'license_key', 'label' => __('License Key', 'wp-email-delivery'), 'description' => __('Please enter your key from <a href="https://www.wpemaildelivery.com">https://www.wpemaildelivery.com</a>.', 'wp-email-delivery'), 'type' => 'text', 'default' => '', 'placeholder' => __('WPED-XXXXXXXXXXXXXXXXXXXXXXXXXX', 'wp-email-delivery')), array('id' => 'enable_sending', 'label' => __('Enable', 'wp-email-delivery'), 'description' => __('Allow <b>WP Email Delivery</b> to override the default wp_mail() function to send emails. ( We recommend you send a few tests firsts )', 'wp-email-delivery'), 'type' => 'checkbox', 'default' => '', 'disable' => !WPED()->connections->is_setup())));
     if (WPED()->connections->is_setup()) {
         $settings['extra'] = array('title' => __('Advanced', 'wp-email-delivery'), 'description' => __('Some extra features to make WP Email Delivery even better.', 'wp-email-delivery'), 'fields' => array(array('id' => 'custom_name', 'label' => __('From Name', 'wp-email-delivery'), 'description' => __('This from name wil be used if one is not set when emails are sent to wp_mail() ', 'wp-email-delivery'), 'type' => 'text', 'default' => '', 'placeholder' => ''), array('id' => 'custom_from', 'label' => __('From Email', 'wp-email-delivery'), 'description' => __('This from email address wil be used if one is not set when emails are sent to wp_mail() ', 'wp-email-delivery'), 'type' => 'text', 'default' => '', 'placeholder' => ''), array('id' => 'enable_nossl', 'label' => __('Disable SSL Sending', 'wp-email-delivery'), 'description' => __('This may be required if your host can not connect over https to the WP Email Delivery API', 'wp-email-delivery'), 'type' => 'checkbox', 'default' => '')));
         $settings['testing'] = array('title' => __('Testing', 'wp-email-delivery'), 'description' => __('Test WP Email Delivery sending before you activate it.', 'wp-email-delivery'), 'custom_save' => __('Save & Send Test Email', 'wp-email-delivery'), 'fields' => array(array('id' => 'test_email', 'label' => __('Email', 'wp-email-delivery'), 'description' => __('Email address to send test to.', 'wp-email-delivery'), 'type' => 'text', 'default' => '', 'placeholder' => __('*****@*****.**', 'wp-email-delivery'))));
         $s = wped_get_option('sending');
         $inline_button = '';
         if ($s) {
             $inline_button = '<a href="#wped/status" id="sending_verify" class="button-primary">Verify</a>';
         }
         $stat = '';
         $spf = wped_get_option('spf_verified');
         $stat .= '<br>SPF: ';
         if ($spf != false && $spf == $s) {
             $stat .= '<span id="spf_check" class="dashicons dashicons-yes" style="color:green;"></span>';
         } else {
             $stat .= '<span id="spf_check" class="dashicons dashicons-yes" style="color:red;"></span>';
         }
         $dkim = wped_get_option('dkim_verified');
         $stat .= '<br>DKIM: ';
         if ($dkim != false && $dkim == $s) {
             $stat .= '<span id="dkim_check" class="dashicons dashicons-yes" style="color:green;"></span>';
         } else {
             $stat .= '<span id="dkim_check" class="dashicons dashicons-yes" style="color:red;"></span>';
         }
         $settings['DNS'] = array('title' => __('DNS ( SPF & DKIM )', 'wp-email-delivery'), 'description' => __('Setting up SPF and DKIM require access to your DNS records. Even if you don\'t have access to these records you can still use WP Email Delivery.', 'wp-email-delivery'), 'fields' => array(array('id' => 'sending', 'label' => __('Sending Domain', 'wp-email-delivery'), 'description' => __('<br>This is the domain the WPED will create a DKIM record for.', 'wp-email-delivery') . $stat, 'type' => 'text', 'default' => '', 'placeholder' => 'example.com', 'extra' => $inline_button), array('id' => 'spf', 'label' => __('SPF Record', 'wp-email-delivery'), 'description' => __('<br>If you don\'t yet have an SPF record, you\'ll want to add one for your domain. At a minimum, the value should be the entry above if you\'re only sending mail through WP Email Delivery for that domain.<br><br>If you already have a TXT record with SPF information, you\'ll need to add WPED\'s servers to that record by adding <strong>include:spf.wped.co</strong> in the record (before the last operator, which is usually ?all, ~all, or -all).', 'wp-email-delivery'), 'type' => 'readonly', 'default' => 'v=spf1 include:spf.wped.co ?all', 'placeholder' => ''), array('id' => 'dkim', 'pre_text' => 'Create a TXT record. Enter:<br><br><strong>Host/Name:</strong> api._domainkey', 'label' => __('DKIM Record', 'wp-email-delivery'), 'type' => 'readonlytextarea', 'always' => 'k=rsa;t=s;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbmGbQMzYeMvxwtNQoXN0waGYaciuKx8mtMh5czguT4EZlJXuCt6V+l56mmt3t68FEX5JJ0q4ijG71BGoFRkl87uJi7LrQt1ZZmZCvrEII0YO4mp8sDLXC8g1aUAoi8TJgxq2MJqCaMyj5kAm3Fdy2tzftPCV/lbdiJqmBnWKjtwIDAQAB')));
     }
     $settings = apply_filters($this->parent->_token . '_settings_fields', $settings);
     return $settings;
 }
 public function message_send($message)
 {
     $info = array("X-WPED" => "ssl", "X-WPED-DOMAIN" => home_url());
     $url = self::SSL_END_POINT;
     //$url = 'http://spnl.dev/';
     $verify_ssl = true;
     if (wped_get_option('enable_nossl')) {
         $verify_ssl = false;
         $url = self::NOSSL_END_POINT;
         $info['X-WPED'] = "nossl";
     }
     if (defined('SPNL_TESTING')) {
         $url = 'http://spnl.io/';
     }
     $message['headers'] = array_merge($info, $message['headers']);
     $message['subaccount'] = wped_get_option('license_key');
     $message['metadata'] = array('return' => home_url());
     $message_encoded = json_encode($message);
     switch (json_last_error()) {
         case JSON_ERROR_UTF8:
             $message_encoded = json_encode($this->utf8_encode_recursive($message));
             break;
     }
     $response = wp_remote_post($url, array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array('Content-Type' => 'application/json'), 'body' => $message_encoded, 'sslverify' => $verify_ssl, 'cookies' => array()));
     if (is_wp_error($response)) {
         $error_message = $response->get_error_message();
         error_log(date('Y-m-d H:i:s') . " wped::message_send: Exception Caught => " . $error_message . "\n");
         return false;
     } else {
         return true;
     }
     return false;
 }
    /**
     * Generate HTML for displaying fields
     * @param  array   $field Field data
     * @param  boolean $echo  Whether to echo the field HTML or return it
     * @return void
     */
    public function display_field($data = array(), $post = false, $echo = true)
    {
        // Get field info
        if (isset($data['field'])) {
            $field = $data['field'];
        } else {
            $field = $data;
        }
        // Check for prefix on option name
        $option_name = '';
        if (isset($data['prefix'])) {
            $option_name = $data['prefix'];
        }
        // Get saved data
        $data = '';
        if ($post) {
            // Get saved field data
            $option_name .= $field['id'];
            $option = get_post_meta($post->ID, $field['id'], true);
            // Get data to display in field
            if (isset($option)) {
                $data = $option;
            }
        } else {
            // Get saved option
            $option_name .= $field['id'];
            $option = wped_get_option($option_name);
            // Get data to display in field
            if (isset($option)) {
                $data = $option;
            }
        }
        // Show default data if no option saved and default is supplied
        if ($data === false && isset($field['default'])) {
            $data = $field['default'];
        } elseif ($data === false) {
            $data = '';
        }
        $html = '';
        switch ($field['type']) {
            case 'button':
                $classes = '';
                if (isset($field['classes'])) {
                    $classes = $field['classes'];
                }
                $html .= '<button class="' . $classes . '" id="' . esc_attr($field['id']) . '" >' . esc_attr($field['display']) . '</button>';
                break;
            case 'link':
                $classes = '';
                if (isset($field['classes'])) {
                    $classes = $field['classes'];
                }
                $html .= '<a href="' . $field['url'] . '" class="' . $classes . '" id="' . esc_attr($field['id']) . '" >' . esc_attr($field['display']) . '</a>';
                break;
            case 'readonly':
                $html .= '<input onclick="this.focus();this.select()" id="' . esc_attr($field['id']) . '" class="regular-text code" readonly type="text" name="' . esc_attr($option_name) . '" placeholder="' . esc_attr($field['placeholder']) . '" value="' . esc_attr($data) . '" />' . "\n";
                break;
            case 'readonlytextarea':
                if ($field['pre_text']) {
                    $html .= '<span class="description">' . $field['pre_text'] . '</span><br><br>' . "\n";
                }
                $html .= '<textarea onclick="this.focus();this.select()" rows="10" cols="50" id="' . esc_attr($field['id']) . '" class="regular-text code" readonly="readonly" >' . $field['always'] . '</textarea>' . "\n";
                break;
            case 'text':
            case 'url':
            case 'email':
                $html .= '<input id="' . esc_attr($field['id']) . '" class="regular-text code"  type="text" name="' . esc_attr($option_name) . '" placeholder="' . esc_attr($field['placeholder']) . '" value="' . esc_attr($data) . '" />';
                if (isset($field['extra'])) {
                    $html .= $field['extra'];
                }
                $html .= "\n";
                break;
            case 'password':
            case 'number':
            case 'hidden':
                $min = '';
                if (isset($field['min'])) {
                    $min = ' min="' . esc_attr($field['min']) . '"';
                }
                $max = '';
                if (isset($field['max'])) {
                    $max = ' max="' . esc_attr($field['max']) . '"';
                }
                $html .= '<input id="' . esc_attr($field['id']) . '" type="' . esc_attr($field['type']) . '" name="' . esc_attr($option_name) . '" placeholder="' . esc_attr($field['placeholder']) . '" value="' . esc_attr($data) . '"' . $min . '' . $max . '/>' . "\n";
                break;
            case 'text_secret':
                $html .= '<input id="' . esc_attr($field['id']) . '" type="text" name="' . esc_attr($option_name) . '" placeholder="' . esc_attr($field['placeholder']) . '" value="" />' . "\n";
                break;
            case 'textarea':
                $html .= '<textarea id="' . esc_attr($field['id']) . '" rows="5" cols="50" name="' . esc_attr($option_name) . '" placeholder="' . esc_attr($field['placeholder']) . '">' . $data . '</textarea><br/>' . "\n";
                break;
            case 'checkbox':
                $checked = '';
                if ($data && 'on' == $data) {
                    $checked = 'checked="checked"';
                }
                $disable = '';
                if (isset($field['disable']) && $field['disable']) {
                    $disable = ' disabled ';
                }
                $html .= '<input ' . $disable . ' id="' . esc_attr($field['id']) . '" type="' . esc_attr($field['type']) . '" name="' . esc_attr($option_name) . '" ' . $checked . '/>' . "\n";
                $disable = '';
                break;
            case 'checkbox_multi':
                foreach ($field['options'] as $k => $v) {
                    $checked = false;
                    if (in_array($k, $data)) {
                        $checked = true;
                    }
                    $html .= '<label for="' . esc_attr($field['id'] . '_' . $k) . '" class="checkbox_multi"><input type="checkbox" ' . checked($checked, true, false) . ' name="' . esc_attr($option_name) . '[]" value="' . esc_attr($k) . '" id="' . esc_attr($field['id'] . '_' . $k) . '" /> ' . $v . '</label> ';
                }
                break;
            case 'radio':
                foreach ($field['options'] as $k => $v) {
                    $checked = false;
                    if ($k == $data) {
                        $checked = true;
                    }
                    $html .= '<label for="' . esc_attr($field['id'] . '_' . $k) . '"><input type="radio" ' . checked($checked, true, false) . ' name="' . esc_attr($option_name) . '" value="' . esc_attr($k) . '" id="' . esc_attr($field['id'] . '_' . $k) . '" /> ' . $v . '</label> ';
                }
                break;
            case 'select':
                $html .= '<select name="' . esc_attr($option_name) . '" id="' . esc_attr($field['id']) . '">';
                foreach ($field['options'] as $k => $v) {
                    $selected = false;
                    if ($k == $data) {
                        $selected = true;
                    }
                    $html .= '<option ' . selected($selected, true, false) . ' value="' . esc_attr($k) . '">' . $v . '</option>';
                }
                $html .= '</select> ';
                break;
            case 'select_multi':
                $html .= '<select name="' . esc_attr($option_name) . '[]" id="' . esc_attr($field['id']) . '" multiple="multiple">';
                foreach ($field['options'] as $k => $v) {
                    $selected = false;
                    if (in_array($k, $data)) {
                        $selected = true;
                    }
                    $html .= '<option ' . selected($selected, true, false) . ' value="' . esc_attr($k) . '">' . $v . '</option>';
                }
                $html .= '</select> ';
                break;
            case 'image':
                $image_thumb = '';
                if ($data) {
                    $image_thumb = wp_get_attachment_thumb_url($data);
                }
                $html .= '<img id="' . $option_name . '_preview" class="image_preview" src="' . $image_thumb . '" /><br/>' . "\n";
                $html .= '<input id="' . $option_name . '_button" type="button" data-uploader_title="' . __('Upload an image', 'wp-email-delivery') . '" data-uploader_button_text="' . __('Use image', 'wp-email-delivery') . '" class="image_upload_button button" value="' . __('Upload new image', 'wp-email-delivery') . '" />' . "\n";
                $html .= '<input id="' . $option_name . '_delete" type="button" class="image_delete_button button" value="' . __('Remove image', 'wp-email-delivery') . '" />' . "\n";
                $html .= '<input id="' . $option_name . '" class="image_data_field" type="hidden" name="' . $option_name . '" value="' . $data . '"/><br/>' . "\n";
                break;
            case 'color':
                ?>
<div class="color-picker" style="position:relative;">
			        <input type="text" name="<?php 
                esc_attr_e($option_name);
                ?>
" class="color" value="<?php 
                esc_attr_e($data);
                ?>
" />
			        <div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>
			    </div>
			    <?php 
                break;
        }
        switch ($field['type']) {
            case 'checkbox_multi':
            case 'radio':
            case 'select_multi':
                $html .= '<br/><span class="description">' . $field['description'] . '</span>';
                break;
            default:
                if (!$post) {
                    $html .= '<label for="' . esc_attr($field['id']) . '">' . "\n";
                }
                if (isset($field['description'])) {
                    $html .= '<span class="description">' . $field['description'] . '</span>' . "\n";
                }
                if (!$post) {
                    $html .= '</label>' . "\n";
                }
                break;
        }
        if (!$echo) {
            return $html;
        }
        echo $html;
    }