本文整理汇总了PHP中Akismet::get_api_key方法的典型用法代码示例。如果您正苦于以下问题:PHP Akismet::get_api_key方法的具体用法?PHP Akismet::get_api_key怎么用?PHP Akismet::get_api_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Akismet
的用法示例。
在下文中一共展示了Akismet::get_api_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gwolle_gb_akismet
function gwolle_gb_akismet($entry, $action)
{
$actions = array('comment-check', 'submit-ham', 'submit-spam');
if (!in_array($action, $actions)) {
return false;
}
$akismet_active = get_option('gwolle_gb-akismet-active', 'false');
if ($akismet_active != 'true') {
// Akismet is not active, so we don't do anything
return false;
}
if (is_callable(array('Akismet', 'get_api_key'))) {
// Akismet v3.0+
$api_key = (bool) Akismet::get_api_key();
} else {
if (function_exists('akismet_get_key')) {
$api_key = (bool) akismet_get_key();
}
}
if (!$api_key) {
// No api key, no glory
return false;
}
if (!is_object($entry)) {
// No object, no fuss
return false;
}
$comment = array();
$comment['comment_author'] = $entry->get_author_name();
$comment['comment_author_email'] = $entry->get_author_email();
$comment['comment_author_origin'] = $entry->get_author_origin();
$comment['comment_author_url'] = $entry->get_author_website();
$comment['comment_content'] = gwolle_gb_bbcode_strip($entry->get_content());
$comment['blog'] = get_option('home');
$comment['blog_lang'] = get_locale();
$comment['blog_charset'] = get_option('blog_charset');
$comment['user_ip'] = preg_replace('/[^0-9., ]/', '', $_SERVER['REMOTE_ADDR']);
$comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
if (isset($_SERVER['HTTP_REFERER'])) {
$comment['referrer'] = $_SERVER['HTTP_REFERER'];
}
// http://blog.akismet.com/2012/06/19/pro-tip-tell-us-your-comment_type/
$comment['comment_type'] = 'comment';
$permalink = get_permalink(get_the_ID());
if ($permalink) {
$comment['permalink'] = $permalink;
}
$ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW');
foreach ($_SERVER as $key => $value) {
if (!in_array($key, (array) $ignore)) {
$comment["{$key}"] = $value;
}
}
// Send the thing to the Akismet service
return gwolle_gb_akismet_entry_check($comment, $action);
}
示例2: is_enable
/**
* is_enable
* @return string APIキー
*/
private function is_enable()
{
if (is_callable(array('Akismet', 'get_api_key'))) {
return Akismet::get_api_key();
}
if (function_exists('akismet_get_key')) {
return akismet_get_key();
}
return false;
}
示例3: get_api_key
public static function get_api_key()
{
if (is_callable(array('Akismet', 'get_api_key'))) {
// Akismet v3.0+
return (bool) Akismet::get_api_key();
}
if (function_exists('akismet_get_key')) {
return (bool) akismet_get_key();
}
return false;
}
示例4: is_akismet_available
protected function is_akismet_available()
{
if (!class_exists('Akismet')) {
return false;
}
$api_key = Akismet::get_api_key();
if (empty($api_key)) {
return false;
}
return true;
}
示例5: wpcf7_akismet_is_available
function wpcf7_akismet_is_available()
{
if (is_callable(array('Akismet', 'get_api_key'))) {
// Akismet v3.0+
return (bool) Akismet::get_api_key();
}
if (function_exists('akismet_get_key')) {
return (bool) akismet_get_key();
}
return false;
}
示例6: fu_akismet_check_submission
function fu_akismet_check_submission($should_process, $layout)
{
// Akismet is not enabled or not configured, or too old, just return the filter value
if (!class_exists('Akismet') || !method_exists('Akismet', 'get_api_key') || !Akismet::get_api_key()) {
return $should_process;
}
$content = array();
$content['comment_author'] = isset($_POST['post_author']) ? sanitize_text_field($_POST['post_author']) : null;
$content['comment_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : null;
// Permalink of the post with upload form, fallback to wp_get_referer()
// Fallback is used to
$content['permalink'] = isset($_POST['form_post_id']) ? get_permalink($_POST['form_post_id']) : wp_get_referer();
// Set required Akismet values
$content['user_ip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
$content['user_agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
$content['referrer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$content['blog'] = get_option('home');
$content['blog_lang'] = get_locale();
$content['blog_charset'] = get_option('blog_charset');
// Ignore these keys in POST and SERVER superglobals, add the rest to request
// This approach is stolen from Akismet::auto_check_comment()
$ignore = array('HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW', 'ff', 'fu_nonce');
foreach ($_POST as $key => $value) {
if (!in_array($key, $ignore) && is_string($value)) {
$content["POST_{$key}"] = $value;
}
}
foreach ($_SERVER as $key => $value) {
if (!in_array($key, $ignore) && is_string($value)) {
$content["{$key}"] = $value;
} else {
$content["{$key}"] = '';
}
}
// Build a query and make a request to Akismet
$request = build_query($content);
$response = Akismet::http_post($request, 'comment-check');
// It's a spam
if ($response[1] == 'true') {
$should_process = false;
}
return $should_process;
}
示例7: akismet_get_key
function akismet_get_key()
{
_deprecated_function(__FUNCTION__, '3.0', 'Akismet::get_api_key()');
return Akismet::get_api_key();
}
示例8: esc_html_e
<div class="wrap">
<h2><?php
esc_html_e('Akismet Stats', 'akismet');
if (!isset($hide_settings_link)) {
?>
<a
href="<?php
echo esc_url(Akismet_Admin::get_page_url());
?>
"
class="add-new-h2"><?php
esc_html_e('Settings', 'akismet');
?>
</a><?php
}
?>
</h2>
<iframe
src="<?php
echo esc_url(sprintf('//akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s&locale=%s', urlencode(get_bloginfo('url')), Akismet::get_api_key(), get_locale()));
?>
"
width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe>
</div>
示例9: akismet_get_key
function akismet_get_key()
{
return Akismet::get_api_key();
}
示例10: esc_html_e
<div class="option-description">
<strong><?php
esc_html_e('Manually enter an API key', 'akismet');
?>
</strong>
<p><?php
esc_html_e('If you already know your API key.', 'akismet');
?>
</p>
</div>
<form action="<?php
echo esc_url(Akismet_Admin::get_page_url());
?>
" method="post" id="akismet-enter-api-key" class="right">
<input id="key" name="key" type="text" size="15" value="<?php
echo esc_attr(Akismet::get_api_key());
?>
" class="regular-text code">
<input type="hidden" name="action" value="enter-key">
<?php
wp_nonce_field(Akismet_Admin::NONCE);
?>
<input type="submit" name="submit" id="submit" class="button button-secondary" value="<?php
esc_attr_e('Use this key', 'akismet');
?>
">
</form>
</div><?php
}
?>
</div>
示例11: esc_html_e
=======
<div class="wrap">
<h2><?php esc_html_e( 'Akismet' , 'akismet');?></h2>
<div class="have-key">
<?php if ( $stat_totals && isset( $stat_totals['all'] ) && (int) $stat_totals['all']->spam > 0 ) : ?>
<div class="new-snapshot stats">
<span style="float:right;margin:10px 15px -5px 0px">
<a href="<?php echo esc_url( Akismet_Admin::get_page_url( 'stats' ) ); ?>" class=""><?php esc_html_e( 'Summaries' , 'akismet');?></a>
</span>
<iframe allowtransparency="true" scrolling="no" frameborder="0" style="width: 100%; height: 215px; overflow: hidden;" src="<?php printf( '//akismet.com/web/1.0/snapshot.php?blog=%s&api_key=%s&height=180&locale=%s', urlencode( get_bloginfo('url') ), Akismet::get_api_key(), get_locale() );?>"></iframe>
<ul>
<li>
<h3><?php esc_html_e( 'Past six months' , 'akismet');?></h3>
<span><?php echo number_format( $stat_totals['6-months']->spam );?></span>
<?php esc_html_e( 'Spam blocked' , 'akismet');?>
</li>
<li>
<h3><?php esc_html_e( 'All time' , 'akismet');?></h3>
<span><?php echo number_format( $stat_totals['all']->spam );?></span>
<?php esc_html_e( 'Spam blocked' , 'akismet');?>
</li>
<li>
<h3><?php esc_html_e( 'Accuracy' , 'akismet');?></h3>
<span><?php echo $stat_totals['all']->accuracy; ?>%</span>
<?php printf(
示例12: akismet
/**
* 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());
}
}
示例13: akismet_is_active_and_registered
/**
* 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;
}
示例14: ap_check_spam
/**
* Check post for spam, if spam then hold it for moderation.
* @param integer $post_id Post id.
*/
function ap_check_spam($post_id)
{
// Return if akisment is not enabled.
if (!class_exists('Akismet') || is_super_admin()) {
return;
}
$post = get_post($post_id);
// Set default arguments to pass.
$defaults = array('blog' => home_url('/'), 'user_ip' => get_post_meta($post->ID, 'create_ip', true), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'referrer' => $_SERVER['HTTP_REFERER'], 'permalink' => get_permalink($post->ID), 'comment_type' => 'forum-post', 'comment_author' => get_the_author_meta('nicename', $post->post_author), 'comment_author_email' => get_the_author_meta('user_email', $post->post_author), 'comment_author_url' => get_the_author_meta('url', $post->post_author), 'comment_content' => $post->post_content);
$akismet_ua = sprintf('WordPress/%s | Akismet/%s', $GLOBALS['wp_version'], constant('AKISMET_VERSION'));
$akismet_ua = apply_filters('akismet_ua', $akismet_ua);
$content_length = strlen($request);
$api_key = Akismet::get_api_key();
$host = Akismet::API_HOST;
if (!empty($api_key)) {
$host = $api_key . '.' . $host;
}
$http_host = $host;
// Use a specific IP if provided.
// Needed by Akismet_Admin::check_server_connectivity().
if ($ip && long2ip(ip2long($ip))) {
$http_host = $ip;
}
$http_args = array('body' => $defaults, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => $akismet_ua), 'httpversion' => '1.0', 'timeout' => 15);
$akismet_url = $http_akismet_url = "http://{$http_host}/1.1/comment-check";
/**
* Try SSL first; if that fails, try without it and don't try it again for a while.
*/
$ssl = $ssl_failed = false;
// Check if SSL requests were disabled fewer than X hours ago.
$ssl_disabled = get_option('akismet_ssl_disabled');
if ($ssl_disabled && $ssl_disabled < time() - 60 * 60 * 24) {
// 24 hours
$ssl_disabled = false;
delete_option('akismet_ssl_disabled');
} else {
if ($ssl_disabled) {
do_action('akismet_ssl_disabled');
}
}
if (!$ssl_disabled && function_exists('wp_http_supports') && ($ssl = wp_http_supports(array('ssl')))) {
$akismet_url = set_url_scheme($akismet_url, 'https');
}
$response = wp_remote_post($akismet_url, $http_args);
Akismet::log(compact('akismet_url', 'http_args', 'response'));
if ($ssl && is_wp_error($response)) {
// Intermittent connection problems may cause the first HTTPS
// request to fail and subsequent HTTP requests to succeed randomly.
// Retry the HTTPS request once before disabling SSL for a time.
$response = wp_remote_post($akismet_url, $http_args);
Akismet::log(compact('akismet_url', 'http_args', 'response'));
if (is_wp_error($response)) {
$ssl_failed = true;
// Try the request again without SSL.
$response = wp_remote_post($http_akismet_url, $http_args);
Akismet::log(compact('http_akismet_url', 'http_args', 'response'));
}
}
if (is_wp_error($response)) {
return array('', '');
}
if ($ssl_failed) {
// The request failed when using SSL but succeeded without it. Disable SSL for future requests.
update_option('akismet_ssl_disabled', time());
do_action('akismet_https_disabled');
}
if ($response['body']) {
wp_update_post(array('ID' => $post_id, 'post_status' => 'moderate'));
}
}
示例15: akismet_get_stats_data
/**
* Get number of spam messages blocked by Akismet.
*
* @since 4.1.0
*
* @param WP_REST_Request $data {
* Array of parameters received by request.
*
* @type string $date Date range to restrict results to.
* }
*
* @return int|string Number of spam blocked by Akismet. Otherwise, an error message.
*/
public static function akismet_get_stats_data(WP_REST_Request $data)
{
if (!is_wp_error($status = self::akismet_is_active_and_registered())) {
return rest_ensure_response(Akismet_Admin::get_stats(Akismet::get_api_key()));
} else {
return $status->get_error_code();
}
}