コード例 #1
0
 public static function check_server_connectivity()
 {
     $test_host = 'rest.akismet.com';
     // Some web hosts may disable one or both functions
     if (!function_exists('fsockopen') || !function_exists('gethostbynamel')) {
         return array();
     }
     $ips = gethostbynamel($test_host);
     if (!$ips || !is_array($ips) || !count($ips)) {
         return array();
     }
     $api_key = Akismet::get_api_key();
     $servers = array();
     foreach ($ips as $ip) {
         $response = Akismet::verify_key($api_key, $ip);
         // even if the key is invalid, at least we know we have connectivity
         if ($response == 'valid' || $response == 'invalid') {
             $servers[$ip] = true;
         } else {
             $servers[$ip] = false;
         }
     }
     return $servers;
 }
コード例 #2
0
 public static function display_notice()
 {
     global $hook_suffix;
     if (in_array($hook_suffix, array('jetpack_page_akismet-key-config', 'settings_page_akismet-key-config', 'edit-comments.php')) && (int) get_option('akismet_alert_code') > 0) {
         Akismet::verify_key(Akismet::get_api_key());
         //verify that the key is still in alert state
         if (get_option('akismet_alert_code') > 0) {
             self::display_alert();
         }
     } elseif ($hook_suffix == 'plugins.php' && !Akismet::get_api_key()) {
         self::display_api_key_warning();
     } elseif ($hook_suffix == 'edit-comments.php' && wp_next_scheduled('akismet_schedule_cron_recheck')) {
         self::display_spam_check_warning();
     } elseif (in_array($hook_suffix, array('jetpack_page_akismet-key-config', 'settings_page_akismet-key-config')) && Akismet::get_api_key()) {
         self::display_status();
     }
 }
コード例 #3
0
    static function akismet_settings_callback()
    {
        ?>
		<div class="clear"></div>
		<fieldset class="fscf_settings_group">


		<strong><?php 
        _e('Akismet Spam Prevention', 'si-contact-form');
        ?>
</strong>

		<a style="cursor:pointer;" title="<?php 
        esc_attr_e('Click for Help!', 'si-contact-form');
        ?>
" onclick="toggleVisibility('si_contact_akismet_tip');"><?php 
        _e('help', 'si-contact-form');
        ?>
</a>
		<div class="fscf_tip" id="si_contact_akismet_tip">
		<?php 
        _e('Akismet is a WordPress spam prevention plugin. When Akismet is installed and active, this form will be checked with Akismet to help prevent spam.', 'si-contact-form');
        ?>
		</div>
		<br /><br />

		<?php 
        $akismet_installed = 0;
        if (self::$form_options['akismet_disable'] == 'false') {
            if (is_callable(array('Akismet', 'verify_key')) || function_exists('akismet_verify_key')) {
                if (!isset(self::$form_options['akismet_check'])) {
                    echo '<span style="background-color:#99CC99;">' . __('Akismet is installed.', 'si-contact-form') . '</span>';
                    $akismet_installed = 1;
                }
                // Has an Akismet check been requested?
                if (strpos($_SERVER['REQUEST_URI'], 'akismet_check') !== false) {
                    $key_status = 'failed';
                    $key = get_option('wordpress_api_key');
                    if (empty($key)) {
                        $key_status = 'empty';
                    } else {
                        if (is_callable(array('Akismet', 'verify_key'))) {
                            $key_status = Akismet::verify_key($key);
                        } else {
                            $key_status = akismet_verify_key($key);
                        }
                        // akismet 2.xx
                    }
                    if ($key_status == 'valid') {
                        $akismet_installed = 1;
                        ?>
<div id="message" class="updated"><strong><?php 
                        echo __('Akismet is enabled and the key is valid. This form will be checked with Akismet to help prevent spam', 'si-contact-form');
                        ?>
</strong></div><?php 
                        echo '<div class="fsc-notice">' . __('Akismet is installed and the key is valid. This form will be checked with Akismet to help prevent spam.', 'si-contact-form') . '</strong></div>';
                    } else {
                        if ($key_status == 'invalid') {
                            ?>
<div id="message" class="error"><strong><?php 
                            echo __('Akismet plugin is enabled but key needs to be activated', 'si-contact-form');
                            ?>
</strong></div><?php 
                            echo '<div class="fsc-error">' . __('Akismet plugin is installed but key needs to be activated.', 'si-contact-form') . '</div>';
                        } else {
                            if (!empty($key) && $key_status == 'failed') {
                                ?>
<div id="message" class="error"><strong><?php 
                                echo __('Akismet plugin is enabled but key failed to verify', 'si-contact-form');
                                ?>
</strong></div><?php 
                                echo '<div class="fsc-error">' . __('Akismet plugin is installed but key failed to verify.', 'si-contact-form') . '</div>';
                            } else {
                                ?>
<div id="message" class="error"><strong><?php 
                                echo __('Akismet plugin is installed but key has not been entered.', 'si-contact-form');
                                ?>
</strong></div><?php 
                                echo '<div class="fsc-error">' . __('Akismet plugin is installed but key has not been entered.', 'si-contact-form') . '</div>';
                            }
                        }
                    }
                }
                ?>
				<br />
				  <input name="<?php 
                echo self::$form_option_name;
                ?>
[akismet_check]" id="si_contact_akismet_check" type="checkbox" value="true" />
				  <label for="<?php 
                echo self::$form_option_name;
                ?>
[akismet_check]"><?php 
                _e('Check this and click "Save Changes" to determine if Akismet key is active.', 'si-contact-form');
                ?>
</label>
				<br />
				<?php 
                echo '<a href="' . admin_url("options-general.php?page=akismet-key-config") . '">' . __('Configure Akismet', 'si-contact-form') . '</a>';
                ?>
				<?php 
            } else {
                echo '<div class="fsc-notice">' . __('Akismet plugin is not installed or is deactivated.', 'si-contact-form') . '</div>';
            }
        } else {
            echo '<div class="fsc-notice">' . __('Akismet is turned off for this form.', 'si-contact-form') . '</div>';
        }
        if (self::$form_options['akismet_disable'] == 'false') {
            ?>
			<br />
			<label for="<?php 
            echo self::$form_option_name;
            ?>
[akismet_send_anyway]"><?php 
            _e('What should happen if Akismet determines the message is spam?', 'si-contact-form');
            ?>
</label>
			<select id="si_contact_akismet_send_anyway" name="<?php 
            echo self::$form_option_name;
            ?>
[akismet_send_anyway]">
			<?php 
            $akismet_send_anyway_array = array('false' => __('Block spam messages', 'si-contact-form'), 'true' => __('Tag as spam and send anyway', 'si-contact-form'));
            $selected = '';
            foreach ($akismet_send_anyway_array as $k => $v) {
                if (self::$form_options['akismet_send_anyway'] == "{$k}") {
                    $selected = ' selected="selected"';
                }
                echo '<option value="' . esc_attr($k) . '"' . $selected . '>' . esc_html($v) . '</option>' . "\n";
                $selected = '';
            }
            ?>
			</select>
			<a style="cursor:pointer;" title="<?php 
            esc_attr_e('Click for Help!', 'si-contact-form');
            ?>
" onclick="toggleVisibility('si_contact_akismet_send_anyway_tip');"><?php 
            _e('help', 'si-contact-form');
            ?>
</a>
			<div class="fscf_tip" id="si_contact_akismet_send_anyway_tip">
			<?php 
            _e('If you select "block spam messages". If Akismet determines the message is spam: An error will display "Invalid Input - Spam?" and the form will not send.', 'si-contact-form');
            ?>
			<?php 
            echo ' ';
            _e('If you select "tag as spam and send anyway". If Akismet determines the message is spam: The message will send and the subject wil begin with "Akismet: Spam". This way you can have Akismet on and be sure not to miss a message.', 'si-contact-form');
            ?>
			</div>
			<?php 
        } else {
            echo '<input name="' . self::$form_option_name . '[akismet_send_anyway]" type="hidden" value="' . self::$form_options['akismet_send_anyway'] . '" />';
        }
        ?>
		<br />
		<input name="<?php 
        echo self::$form_option_name;
        ?>
[akismet_disable]" id="si_contact_akismet_disable" type="checkbox" <?php 
        if (self::$form_options['akismet_disable'] == 'true') {
            echo 'checked="checked"';
        }
        ?>
 value="true" />
		<label for="<?php 
        echo self::$form_option_name;
        ?>
[akismet_disable]"><?php 
        _e('Turn off Akismet for this form.', 'si-contact-form');
        ?>
</label>

		</fieldset>
		<?php 
    }
コード例 #4
0
 public static function check_server_ip_connectivity()
 {
     $servers = $ips = array();
     // Some web hosts may disable this function
     if (function_exists('gethostbynamel')) {
         $ips = gethostbynamel('rest.akismet.com');
         if ($ips && is_array($ips) && count($ips)) {
             $api_key = Akismet::get_api_key();
             foreach ($ips as $ip) {
                 $response = Akismet::verify_key($api_key, $ip);
                 // even if the key is invalid, at least we know we have connectivity
                 if ($response == 'valid' || $response == 'invalid') {
                     $servers[$ip] = 'connected';
                 } else {
                     $servers[$ip] = $response ? $response : 'unable to connect';
                 }
             }
         }
     }
     return $servers;
 }
コード例 #5
0
ファイル: wrapper.php プロジェクト: Didox/beminfinito
function akismet_verify_key($key, $ip = null)
{
    _deprecated_function(__FUNCTION__, '3.0', 'Akismet::verify_key()');
    return Akismet::verify_key($key, $ip);
}
コード例 #6
0
function akismet_verify_key($key, $ip = null)
{
    return Akismet::verify_key($key, $ip);
}
コード例 #7
0
    ?>
  <input name="si_captcha_akismet_check" id="si_captcha_akismet_check" type="checkbox" value="1" />
  <label for="si_captcha_akismet_check"><?php 
    _e('Check this and click "Update Options" to determine if Akismet key is active.', 'si-captcha');
    ?>
</label>
   <?php 
    if (isset($_POST['si_captcha_akismet_check'])) {
        echo '<br/>';
        $key_status = 'failed';
        $key = get_option('wordpress_api_key');
        if (empty($key)) {
            $key_status = 'empty';
        } else {
            if (is_callable(array('Akismet', 'verify_key'))) {
                $key_status = Akismet::verify_key($key);
            } else {
                $key_status = akismet_verify_key($key);
            }
            // akismet 2.xx
        }
        if ($key_status == 'valid') {
            echo '<span style="background-color:#99CC99; padding:4px;">' . __('Akismet is installed and the key is valid. Comment posts will be checked with Akismet to help prevent spam.', 'si-captcha') . '</strong></span>';
        } else {
            if ($key_status == 'invalid') {
                echo '<span style="background-color:#FFE991; padding:4px;">' . __('Akismet plugin is installed but key needs to be activated.', 'si-captcha') . '</span>';
            } else {
                if (!empty($key) && $key_status == 'failed') {
                    echo '<span style="background-color:#FFE991; padding:4px;">' . __('Akismet plugin is installed but key failed to verify.', 'si-captcha') . '</span>';
                }
            }
コード例 #8
0
function render_main_page_area($user)
{
    global $admin_password;
    $page_url = PA::$url . "/comment_management.php";
    $paging_url = "{$page_url}?";
    // url to pass to the pager object
    $msg = "";
    $path_info = @$_SERVER['PATH_INFO'];
    // see if the user is logged in as an admin
    if ($path_info == "/login") {
        if (@$_REQUEST['admin_password'] == $admin_password) {
            $_SESSION['comment_management_is_admin'] = TRUE;
        } else {
            $msg = "Incorrect password!  Try again...";
        }
    } else {
        if ($path_info == "/logout") {
            $_SESSION['comment_management_is_admin'] = FALSE;
            $msg = "You are now logged out (of admin mode).";
        }
    }
    $is_admin = @$_SESSION['comment_management_is_admin'];
    $limit_set = NULL;
    // set this to an array with keys 'comment_id' to limit display to those keys
    $current_search_terms = NULL;
    // current search terms
    switch ($path_info) {
        case '/analyze_comment':
            $comment_id = (int) @$_REQUEST['comment'];
            if (!$is_admin) {
                $msg = "Sorry, only administrators can analyze comments at the moment :(";
            } elseif ($comment_id) {
                $cmt = new Comment();
                $cmt->load($comment_id);
                $cmt->index_spam_domains();
                $msg = "<p>Analysis of comment {$comment_id}:</p><hr/><p>" . nl2br(htmlspecialchars($cmt->comment)) . "</p><hr/><ul>";
                $hosts = $cmt->get_link_hosts();
                foreach ($hosts as $domain => $links) {
                    $msg .= "<li><b>" . htmlspecialchars($domain) . "</b> (<a href=\"{$page_url}/analyze_domain?domain=" . htmlspecialchars($domain) . "\">analyze</a>): ";
                    $dom = new SpamDomain($domain);
                    if ($dom->blacklisted) {
                        $msg .= " BLACKLISTED";
                    }
                    $msg .= "<ul>";
                    foreach ($links as $link) {
                        list($url, $linktexts) = $link;
                        $msg .= "<li>" . htmlspecialchars($url) . " -> " . implode(" | ", array_map("htmlspecialchars", $linktexts)) . "</li>";
                    }
                    $msg .= "</ul></li>";
                }
                $msg .= "</ul><hr/>";
            }
            break;
        case '/search':
            $current_search_terms = @$_REQUEST['q'];
            if (!$is_admin) {
                $msg = "Sorry, only administrators can search comments at the moment :(";
            } elseif ($current_search_terms) {
                $paging_url = "{$page_url}/search?q=" . urlencode($current_search_terms) . "&";
                $limit_set = Comment::search($current_search_terms);
            }
            break;
        case '/stats':
            $msg = "<p>Stats:</p>";
            list($n) = Dal::query_one("SELECT COUNT(*) FROM {comments}");
            list($n_deleted) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=0");
            $n_active = $n - $n_deleted;
            $msg .= "<li>{$n} comments ({$n_active} active / {$n_deleted} deleted)</li>";
            list($n_ham) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=1 AND spam_state=0");
            $n_spam = $n_active - $n_ham;
            $msg .= "<li>{$n_spam} active+spam / {$n_ham} active+not spam</li>";
            list($n_no_class) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=1 AND akismet_spam IS NULL");
            $msg .= "<li>{$n_no_class} active comments not (yet?) classified by Akismet</li>";
            list($n_akismet_del) = Dal::query_one("SELECT COUNT(*) FROM {comments} WHERE is_active=0 AND akismet_spam=1");
            $msg .= "<li>{$n_akismet_del} comments flagged as spam by akismet and deleted</li>";
            break;
        case '/add_spam_term':
            $spam_term = @$_REQUEST['term'];
            if (!$is_admin) {
                $msg = "Sorry, only administrators can add spam terms at the moment.";
            } elseif ($spam_term) {
                // find the comments
                $matches = Comment::search($spam_term);
                $n_deleted = count($matches);
                // add the term
                Comment::add_spam_term($spam_term);
                // and delete the comments
                $blk_size = 1000;
                $F_fetch_ids = create_function('$item', 'return $item["comment_id"];');
                for ($i = 0; $i < count($matches); $i += $blk_size) {
                    Comment::set_spam_state(array_map($F_fetch_ids, array_slice($matches, $i, $blk_size)), SPAM_STATE_SPAM_WORDS);
                }
                $msg = "Added <b>" . htmlspecialchars($spam_term) . '</b> to the spam term database, and deleted ' . $n_deleted . ' comments containing it.';
            }
            break;
        case '/analyze_domain':
            $domain = @$_REQUEST['domain'];
            if (!$is_admin) {
                $msg = "Sorry, only administrators can analyze domains.";
            } else {
                $msg .= "<p>analysis of domain " . htmlspecialchars($domain) . ":</p><ul>";
                $domain = new SpamDomain($domain);
                foreach ($domain->find_associated_domains() as $r) {
                    $msg .= "<li>" . $r['domain'] . " (" . $r['domain_id'] . "): " . $r['match_count'] . " matches</li>";
                }
                $msg .= "</ul>";
            }
            break;
        case '/blacklist_domain':
            $domain = @$_REQUEST['domain'];
            if (!$is_admin) {
                $msg = "Sorry, only administrators can blacklist domains.";
            } elseif (!trim($domain)) {
                $msg = "Invalid domain";
            } else {
                $dom = new SpamDomain($domain);
                $dom->set_blacklisted(DOMAIN_BLACKLISTED_MANUALLY);
                foreach ($dom->find_associated_domains() as $assoc_domain) {
                    SpamDomain::recalculate_link_counts_for_domain_id($assoc_domain['domain_id']);
                }
            }
            // FALL THROUGH TO /common_domains
        // FALL THROUGH TO /common_domains
        case '/common_domains':
            if (!$is_admin) {
                $msg = "Sorry, only administrators can do this.";
            } else {
                list($total_domains, $total_blacklisted_domains) = SpamDomain::count_domains();
                $msg .= "<p>Most common domains (out of total {$total_domains}, {$total_blacklisted_domains} blacklisted) in comments:</p><ul>";
                foreach (SpamDomain::get_most_common_domains() as $dom) {
                    $msg .= "<li>" . $dom['active_count'] . " times: " . $dom['domain'] . ' ' . ($dom['blacklisted'] ? 'BLACKLISTED' : '') . ' (<a href="' . $page_url . '/blacklist_domain?domain=' . $dom['domain'] . '">blacklist domain</a> | <a href="' . $page_url . '/analyze_domain?domain=' . $dom['domain'] . '">analyze domain</a>)</li>';
                }
                $msg .= "</ul>";
            }
            break;
        case '/akismet_verify_key':
            global $akismet_key;
            if (!$is_admin) {
                $msg = "Sorry, only administrators can access Akismet at the moment.";
            } elseif (!$akismet_key) {
                $msg .= '<p>No Akismet key has been configured - Akismet is not active.</p>';
            } else {
                // global var $_base_url has been removed - please, use PA::$url static variable
                $msg .= "<p>verifying akismet key: {$akismet_key}</p>";
                $ak = new Akismet($akismet_key);
                $msg .= "<p>result: " . var_export($ak->verify_key(PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $user->user_id), TRUE) . "</p>";
            }
            break;
        case '/akismet_check_spam':
            if (!$is_admin) {
                $msg = "Sorry, only administrators can access Akismet at the moment.";
            } else {
                global $akismet_key;
                $msg .= "<p>checking comment for spam</p>";
                $cmt = new Comment();
                try {
                    $cmt->load((int) $_REQUEST['comment']);
                } catch (PAException $e) {
                    if ($e->getCode() != COMMENT_NOT_EXIST) {
                        throw $e;
                    }
                    $msg .= "<p>Comment already deleted.</p>";
                    break;
                }
                $cmt->akismet_check();
                $msg .= "<p>result: " . var_export($cmt->akismet_spam, TRUE) . "</p>";
            }
            break;
        default:
            if (preg_match("~^/delete/(\\d+)\$~", $path_info, $m)) {
                list(, $cid) = $m;
                if (!$is_admin) {
                    $msg = "Sorry, only administrators can delete comments at the moment :(";
                } else {
                    try {
                        $c = new Comment();
                        $c->load((int) $cid);
                        $c->delete();
                        $msg = "Comment deleted.";
                    } catch (PAException $e) {
                        if ($e->code == COMMENT_NOT_EXIST) {
                            $msg = "Comment already deleted.";
                        } else {
                            throw $e;
                        }
                    }
                }
            }
    }
    $per_page = 20;
    // how many comments to show on a page
    // paging
    if ($limit_set !== NULL) {
        $total_comments = count($limit_set);
    } else {
        $total_comments = Comment::count_all_comments($is_admin ? 0 : $user->user_id);
    }
    $pager = new pager($total_comments, $per_page, $paging_url);
    $paging = $pager->getButList(8) . " (total {$total_comments} comments)";
    // main comment list
    if ($limit_set !== NULL) {
        $show_start = max(0, min(($pager->page - 1) * $per_page, $total_comments));
        $show_count = min($per_page, $total_comments - $show_start);
        $limit_set_ids = array_map(create_function('$item', 'return $item["comment_id"];'), array_slice($limit_set, $show_start, $show_count));
        $cmts = Comment::get_selected($limit_set_ids);
    } else {
        $cmts = Comment::get_all_comments($is_admin ? 0 : $user->user_id, $per_page, $pager->page);
    }
    $comments = "";
    foreach ($cmts as $cmt) {
        //      $comments .= "<li>".htmlspecialchars(var_export($cmt, TRUE))."</li>";
        $akismet_result = $cmt['akismet_spam'] ? "spam" : "?";
        $comments .= "<tr><td>" . $cmt['comment_id'] . "</td><td>" . $cmt['content_id'] . "</td><td>" . esc_wbr($cmt['name']) . "</td><td>" . esc_wbr($cmt['email']) . "</td><td>" . esc_wbr($cmt['homepage']) . "</td><td>" . esc_wbr($cmt['subject']) . "</td><td>" . esc_wbr($cmt['comment']) . " {$akismet_result} <a href=\"{$page_url}/analyze_comment?comment=" . $cmt['comment_id'] . "\">analyze</a></td><td>" . esc_wbr($cmt['ip_addr']) . "</td><td>" . '<form method="POST" action="' . PA::$url . '/comment_management.php/delete/' . $cmt['comment_id'] . '?page=' . $pager->page . '"><input type="submit" value="X"></form> <a href="' . $page_url . '/akismet_check_spam?comment=' . $cmt['comment_id'] . '">ak</a></td></tr>';
    }
    if ($is_admin) {
        if ($current_search_terms) {
            $current_search = '<form method="POST" action="' . $page_url . '/add_spam_term"><p>Currently displaying results for: <b>' . htmlspecialchars($current_search_terms) . '</b>. <a href="' . $page_url . '">Show all comments</a>.  <input type="hidden" name="term" value="' . htmlspecialchars($current_search_terms) . '"><input type="submit" value="Blacklist this term"></p></form>';
        } else {
            $current_search = "";
        }
        $your_permissions = <<<EOS
\t<form method="POST" action="{$page_url}/logout"><p>You are an administrator, so all comments in the site will be displayed.  <input type="submit" value="Log out"></p></form>

\t<p><a href="{$page_url}/akismet_verify_key">Verify Akismet key</a> | <a href="{$page_url}/common_domains">Show most common domains</a> | <a href="{$page_url}/stats">Spam statistics</a></p>

\t<form method="GET" action="{$page_url}/search"><p>Search comment content: <input type="text" id="search_q" name="q" size="20"><input type="submit" value="Search"/></p></form>
\t<script language="javascript"><!--
\t    document.getElementById("search_q").focus();
        // --></script>
        {$current_search}
EOS;
    } else {
        $your_permissions = <<<EOS
<p>Showing comments on your blog and groups for which you are moderator.</p>

<form method="POST" action="{$page_url}/login"><p>Or enter the admin password here to adminster the whole site: <input type="password" name="admin_password" size="20"/><input type="submit" value="Log in"/></p></form>
EOS;
    }
    $page_title = "Manage comments";
    global $akismet_key;
    if ($akismet_key) {
        $page_title .= " (Akismet active)";
    } else {
        $page_title .= " (Akismet not configured)";
    }
    $page_html = <<<EOS
<div class="pane comment_manage_pane">

<h1>{$page_title}</h1>

<div id="msg" class="fade">{$msg}</div>

{$your_permissions}

<p>{$paging}</p>

<table class="bulk_comment_summary"><tr>
<td>ID</td>
<td>Post</td>
<td>Name</td>
<td>Email</td>
<td>Website</td>
<td>Subject</td>
<td>Comment</td>
<td>IP</td>
<td>X</td>
</tr>
{$comments}
</table>

</div><!-- comment_manage_pane -->
EOS;
    return $page_html;
}
コード例 #9
0
ファイル: WPametuCommand.php プロジェクト: hametuha/wpametu
 /**
  * Check if akismet is available
  *
  * ## OPTIONS
  *
  * ## EXAMPLES
  *
  *     wp ametu akismet
  *
  * @synopsis
  */
 public function akismet()
 {
     try {
         if (!class_exists('Akismet')) {
             throw new \Exception('Akismet is not installed.');
         }
         if (!($key = \Akismet::get_api_key())) {
             throw new \Exception('Akismet API key is not set.');
         }
         if ('valid' !== \Akismet::verify_key($key)) {
             throw new \Exception('Akismet API key is invalid.');
         }
         static::s('Akismet is available!');
     } catch (\Exception $e) {
         static::e($e->getMessage());
     }
 }
コード例 #10
0
 /**
  * Is Akismet registered and active?
  *
  * @since 4.3.0
  *
  * @return bool|WP_Error True if Akismet is active and registered. Otherwise, a WP_Error instance with the corresponding error.
  */
 private function akismet_is_active_and_registered()
 {
     if (!file_exists(WP_PLUGIN_DIR . '/akismet/class.akismet.php')) {
         return new WP_Error('not_installed', esc_html__('Please install Akismet.', 'jetpack'), array('status' => 400));
     }
     if (!class_exists('Akismet')) {
         return new WP_Error('not_active', esc_html__('Please activate Akismet.', 'jetpack'), array('status' => 400));
     }
     // What about if Akismet is put in a sub-directory or maybe in mu-plugins?
     require_once WP_PLUGIN_DIR . '/akismet/class.akismet.php';
     require_once WP_PLUGIN_DIR . '/akismet/class.akismet-admin.php';
     $akismet_key = Akismet::verify_key(Akismet::get_api_key());
     if (!$akismet_key || 'invalid' === $akismet_key || 'failed' === $akismet_key) {
         return new WP_Error('invalid_key', esc_html__('Invalid Akismet key. Please contact support.', 'jetpack'), array('status' => 400));
     }
     return true;
 }