PageRenderTime 62ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/akismet/admin.php

https://github.com/bsantana/jfelicio
PHP | 925 lines | 772 code | 115 blank | 38 comment | 185 complexity | 6ea136449430a16f0d4675b6af5aa7d8 MD5 | raw file
  1. <?php
  2. add_action( 'admin_menu', 'akismet_admin_menu' );
  3. akismet_admin_warnings();
  4. function akismet_admin_init() {
  5. global $wp_version;
  6. // all admin functions are disabled in old versions
  7. if ( !function_exists('is_multisite') && version_compare( $wp_version, '3.0', '<' ) ) {
  8. function akismet_version_warning() {
  9. echo '
  10. <div id="akismet-warning" class="updated fade"><p><strong>'.sprintf(__('Akismet %s requires WordPress 3.0 or higher.'), AKISMET_VERSION) .'</strong> '.sprintf(__('Please <a href="%s">upgrade WordPress</a> to a current version, or <a href="%s">downgrade to version 2.4 of the Akismet plugin</a>.'), 'http://codex.wordpress.org/Upgrading_WordPress', 'http://wordpress.org/extend/plugins/akismet/download/'). '</p></div>
  11. ';
  12. }
  13. add_action('admin_notices', 'akismet_version_warning');
  14. return;
  15. }
  16. if ( function_exists( 'get_plugin_page_hook' ) )
  17. $hook = get_plugin_page_hook( 'akismet-stats-display', 'index.php' );
  18. else
  19. $hook = 'dashboard_page_akismet-stats-display';
  20. add_meta_box('akismet-status', __('Comment History'), 'akismet_comment_status_meta_box', 'comment', 'normal');
  21. }
  22. add_action('admin_init', 'akismet_admin_init');
  23. add_action( 'admin_enqueue_scripts', 'akismet_load_js_and_css' );
  24. function akismet_load_js_and_css() {
  25. global $hook_suffix;
  26. if ( in_array( $hook_suffix, array(
  27. 'index.php', # dashboard
  28. 'edit-comments.php',
  29. 'comment.php',
  30. 'post.php',
  31. 'plugins_page_akismet-key-config',
  32. 'jetpack_page_akismet-key-config',
  33. ) ) ) {
  34. wp_register_style( 'akismet.css', AKISMET_PLUGIN_URL . 'akismet.css', array(), '2.5.9' );
  35. wp_enqueue_style( 'akismet.css');
  36. wp_register_script( 'akismet.js', AKISMET_PLUGIN_URL . 'akismet.js', array('jquery'), '2.5.9' );
  37. wp_enqueue_script( 'akismet.js' );
  38. wp_localize_script( 'akismet.js', 'WPAkismet', array(
  39. 'comment_author_url_nonce' => wp_create_nonce( 'comment_author_url_nonce' )
  40. ) );
  41. }
  42. }
  43. function akismet_nonce_field($action = -1) { return wp_nonce_field($action); }
  44. $akismet_nonce = 'akismet-update-key';
  45. function akismet_plugin_action_links( $links, $file ) {
  46. if ( $file == plugin_basename( dirname(__FILE__).'/akismet.php' ) ) {
  47. $links[] = '<a href="' . admin_url( 'admin.php?page=akismet-key-config' ) . '">'.__( 'Settings' ).'</a>';
  48. }
  49. return $links;
  50. }
  51. add_filter( 'plugin_action_links', 'akismet_plugin_action_links', 10, 2 );
  52. function akismet_conf() {
  53. global $akismet_nonce, $current_user;
  54. $new_key_link = 'https://akismet.com/get/';
  55. $config_link = esc_url( add_query_arg( array( 'page' => 'akismet-key-config', 'show' => 'enter-api-key' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'plugins.php' ) ) );
  56. $stats_link = esc_url( add_query_arg( array( 'page' => 'akismet-stats-display' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'index.php' ) ) );
  57. $api_key = akismet_get_key();
  58. $show_key_form = $api_key;
  59. $key_status = 'empty';
  60. $saved_ok = false;
  61. $key_status_text = '';
  62. $ms = array();
  63. if ( isset( $_POST['submit'] ) ) {
  64. if ( function_exists('current_user_can') && !current_user_can('manage_options') )
  65. die(__('Cheatin&#8217; uh?'));
  66. $show_key_form = true;
  67. check_admin_referer( $akismet_nonce );
  68. $key = preg_replace( '/[^a-h0-9]/i', '', $_POST['key'] );
  69. $home_url = parse_url( get_bloginfo('url') );
  70. if ( empty( $home_url['host'] ) )
  71. $ms[] = 'bad_home_url';
  72. if ( empty( $key ) ) {
  73. if ( $api_key ) {
  74. delete_option('wordpress_api_key');
  75. $saved_ok = true;
  76. $ms[] = 'new_key_empty';
  77. }
  78. else
  79. $ms[] = 'key_empty';
  80. }
  81. else
  82. $key_status = akismet_verify_key( $key );
  83. if ( $key != $api_key && $key_status == 'valid' ) {
  84. $ms[] = 'new_key_valid';
  85. update_option('wordpress_api_key', $key);
  86. }
  87. elseif ( $key_status == 'invalid' )
  88. $ms[] = 'new_key_invalid';
  89. elseif ( $key_status == 'failed' )
  90. $ms[] = 'new_key_failed';
  91. $api_key = $key_status == 'valid' ? $key : false;
  92. if ( isset( $_POST['akismet_discard_month'] ) )
  93. update_option( 'akismet_discard_month', 'true' );
  94. else
  95. update_option( 'akismet_discard_month', 'false' );
  96. if ( isset( $_POST['akismet_show_user_comments_approved'] ) )
  97. update_option( 'akismet_show_user_comments_approved', 'true' );
  98. else
  99. update_option( 'akismet_show_user_comments_approved', 'false' );
  100. if ( empty( $ms ) )
  101. $saved_ok = true;
  102. }
  103. elseif ( isset( $_POST['check'] ) ) {
  104. $show_key_form = true;
  105. check_admin_referer( $akismet_nonce );
  106. akismet_get_server_connectivity(0);
  107. }
  108. elseif ( isset( $_GET['show'] ) && $_GET['show'] == 'enter-api-key' ) {
  109. $show_key_form = true;
  110. }
  111. if ( $show_key_form ) {
  112. //check current key status
  113. //only get this if showing the key form otherwise takes longer for page to load for new user
  114. //no need to get it if we already know it and its valid
  115. if ( in_array( $key_status, array( 'invalid', 'failed', 'empty' ) ) ) {
  116. $key = get_option('wordpress_api_key');
  117. if ( empty( $key ) ) {
  118. //no key saved yet - maybe connection to Akismet down?
  119. if ( in_array( $key_status, array( 'invalid', 'empty' ) ) ) {
  120. if ( akismet_verify_key( '1234567890ab' ) == 'failed' )
  121. $ms[] = 'no_connection';
  122. }
  123. }
  124. else
  125. $key_status = akismet_verify_key( $key );
  126. }
  127. if ( !isset( $_POST['submit'] ) ) {
  128. if ( $key_status == 'invalid' )
  129. $ms[] = 'key_invalid';
  130. elseif ( !empty( $key ) && $key_status == 'failed' )
  131. $ms[] = 'key_failed';
  132. }
  133. }
  134. $key_status_strings = array(
  135. 'empty' => __( 'Empty' ),
  136. 'valid' => __( 'Valid' ),
  137. 'invalid' => __( 'Invalid' ),
  138. 'failed' => __( 'Failed' ),
  139. );
  140. $messages = array(
  141. 'new_key_empty' => array( 'class' => 'updated fade', 'text' => __('Your key has been cleared.' ) ),
  142. 'new_key_valid' => array( 'class' => 'updated fade', 'text' => __('Your Akismet account has been successfully set up and activated. Happy blogging!' ) ),
  143. 'new_key_invalid' => array( 'class' => 'error', 'text' => __('The key you entered is invalid. Please double-check it.' ) ),
  144. 'new_key_failed' => array( 'class' => 'error', 'text' => __('The key you entered could not be verified because a connection to akismet.com could not be established. Please check your server configuration.' ) ),
  145. 'no_connection' => array( 'class' => 'error', 'text' => __('There was a problem connecting to the Akismet server. Please check your server configuration.' ) ),
  146. 'key_empty' => array( 'class' => 'updated fade', 'text' => __('Please enter an API key' ) ),
  147. 'key_invalid' => array( 'class' => 'error', 'text' => __('This key is invalid.' ) ),
  148. 'key_failed' => array( 'class' => 'error', 'text' => __('The key below was previously validated but a connection to akismet.com can not be established at this time. Please check your server configuration.' ) ),
  149. 'bad_home_url' => array( 'class' => 'error', 'text' => sprintf( __('Your WordPress home URL %s is invalid. Please fix the <a href="%s">home option</a>.'), esc_html( get_bloginfo('url') ), admin_url('options.php#home') ) )
  150. );
  151. ?>
  152. <div class="wrap">
  153. <?php if ( !$api_key ) : ?>
  154. <h2 class="ak-header"><?php _e('Akismet'); ?></h2>
  155. <?php else: ?>
  156. <h2 class="ak-header"><?php printf( __( 'Akismet <a href="%s" class="add-new-h2">Stats</a>' ), $stats_link ); ?></h2>
  157. <?php endif; ?>
  158. <div class="no-key <?php echo $show_key_form ? 'hidden' : '';?>">
  159. <p><?php _e('Akismet eliminates the comment and trackback spam you get on your site. To use Akismet you may need to sign up for an API key. Click the button below to get started.'); ?></p>
  160. <form name="akismet_activate" action="https://akismet.com/get/" method="POST">
  161. <input type="hidden" name="return" value="1"/>
  162. <input type="hidden" name="jetpack" value="<?php echo (string) class_exists( 'Jetpack' );?>"/>
  163. <input type="hidden" name="user" value="<?php echo esc_attr( $current_user->user_login );?>"/>
  164. <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Create a new Akismet Key' ); ?>"/>
  165. </form>
  166. <br/>
  167. <a href="<?php echo $config_link;?>"><?php _e('I already have a key'); ?></a>
  168. </div>
  169. <div class="have-key <?php echo $show_key_form ? '' : 'hidden';?>">
  170. <?php if ( !empty($_POST['submit'] ) && $saved_ok ) : ?>
  171. <div id="message" class="updated fade"><p><strong><?php _e('Settings saved.') ?></strong></p></div>
  172. <?php endif; ?>
  173. <?php if ( isset($_GET['message']) && $_GET['message'] == 'success' ) : ?>
  174. <div id="message" class="updated fade"><p><?php _e('<strong>Sign up success!</strong> Please check your email for your Akismet API Key and enter it below.') ?></p></div>
  175. <?php endif; ?>
  176. <?php foreach( $ms as $m ) : ?>
  177. <div class="<?php echo $messages[$m]['class']; ?>"><p><strong><?php echo $messages[$m]['text']; ?></strong></p></div>
  178. <?php endforeach; ?>
  179. <form action="" method="post" id="akismet-conf">
  180. <table class="form-table">
  181. <tbody>
  182. <tr>
  183. <th><label for="key"><?php _e('Akismet API Key');?></label></th>
  184. <td>
  185. <input id="key" name="key" type="text" size="15" maxlength="12" value="<?php echo esc_attr( get_option('wordpress_api_key') ); ?>" class="regular-text code <?php echo $key_status;?>"><div class="under-input key-status <?php echo $key_status;?>"><?php echo isset( $key_status_strings[ $key_status ] ) ? $key_status_strings[ $key_status ] : '';?></div>
  186. <p class="need-key description"><?php printf( __('You must enter a valid Akismet API key here. If you need an API key, you can <a href="%s">create one here</a>'), '#' );?></p>
  187. </td>
  188. </tr>
  189. <?php if ( $api_key ):?>
  190. <tr valign="top">
  191. <th scope="row"><?php _e('Settings');?></th>
  192. <td>
  193. <fieldset><legend class="screen-reader-text"><span><?php _e('Settings');?></span></legend>
  194. <label for="akismet_discard_month" title="<?php esc_attr_e( 'Auto-detete old spam' ); ?>"><input name="akismet_discard_month" id="akismet_discard_month" value="true" type="checkbox" <?php echo get_option('akismet_discard_month') == 'true' ? 'checked="checked"':''; ?>> <span><?php _e('Auto-delete spam submitted on posts more than a month old.'); ?></span></label><br>
  195. <label for="akismet_show_user_comments_approved" title="<?php esc_attr_e( 'Show approved comments' ); ?>"><input name="akismet_show_user_comments_approved" id="akismet_show_user_comments_approved" value="true" type="checkbox" <?php echo get_option('akismet_show_user_comments_approved') == 'true' ? 'checked="checked"':''; ?>> <span><?php _e('Show the number of comments you\'ve approved beside each comment author.'); ?></span></label>
  196. </fieldset>
  197. </td>
  198. </tr>
  199. <?php endif; ?>
  200. </tbody>
  201. </table>
  202. <?php akismet_nonce_field($akismet_nonce) ?>
  203. <p class="submit">
  204. <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes');?>">
  205. </p>
  206. </form>
  207. <?php if ( $api_key ) : ?>
  208. <h3><?php _e('Server Connectivity'); ?></h3>
  209. <form action="" method="post" id="akismet-connectivity">
  210. <table class="form-table">
  211. <tbody>
  212. <tr>
  213. <th><label for="key"><?php _e('Server Status');?></label></th>
  214. <td>
  215. <?php if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') ) : ?>
  216. <p class="key-status failed"><?php _e('Network functions are disabled.'); ?></p>
  217. <p class="description"><?php echo sprintf( __('Your web host or server administrator has disabled PHP\'s <code>fsockopen</code> or <code>gethostbynamel</code> functions. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet\'s system requirements</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
  218. <?php else :
  219. $servers = akismet_get_server_connectivity();
  220. $fail_count = count( $servers ) - count( array_filter( $servers ) );
  221. if ( is_array( $servers ) && count( $servers ) > 0 ) {
  222. if ( $fail_count > 0 && $fail_count < count( $servers ) ) { // some connections work, some fail ?>
  223. <p class="key-status some"><?php _e('Unable to reach some Akismet servers.'); ?></p>
  224. <p class="description"><?php echo sprintf( __('A network problem or firewall is blocking some connections from your web server to Akismet.com. Akismet is working but this may cause problems during times of network congestion. Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
  225. <?php } elseif ( $fail_count > 0 ) { // all connections fail ?>
  226. <p class="key-status failed"><?php _e('Unable to reach any Akismet servers.'); ?></p>
  227. <p class="description"><?php echo sprintf( __('A network problem or firewall is blocking all connections from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
  228. <?php } else { // all connections work ?>
  229. <p class="key-status valid"><?php _e('All Akismet servers are available.'); ?></p>
  230. <p class="description"><?php _e('Akismet is working correctly. All servers are accessible.'); ?></p>
  231. <?php }
  232. } else { //can't connect to any server ?>
  233. <p class="key-status failed"><?php _e('Unable to find Akismet servers.'); ?></p>
  234. <p class="description"><?php echo sprintf( __('A DNS problem or firewall is preventing all access from your web server to Akismet.com. <strong>Akismet cannot work correctly until this is fixed.</strong> Please contact your web host or firewall administrator and give them <a href="%s" target="_blank">this information about Akismet and firewalls</a>.'), 'http://blog.akismet.com/akismet-hosting-faq/'); ?></p>
  235. <?php }
  236. endif; ?>
  237. </td>
  238. </tr>
  239. <?php if ( !empty( $servers ) ) : ?>
  240. <tr valign="top">
  241. <th scope="row"><?php _e('Network Status');?></th>
  242. <td>
  243. <table class="network-status">
  244. <thead>
  245. <th><?php _e('Akismet server'); ?></th><th><?php _e('Network Status'); ?></th>
  246. </thead>
  247. <tbody>
  248. <?php
  249. asort($servers);
  250. foreach ( $servers as $ip => $status ) : ?>
  251. <tr>
  252. <td align="center"><?php echo esc_html( $ip ); ?></td>
  253. <td class="key-status <?php echo $status ? 'valid' : 'failed'; ?>"><?php echo $status ? __('Accessible') : __('Re-trying'); ?></td>
  254. </tr>
  255. <?php endforeach; ?>
  256. </tbody>
  257. </table>
  258. <br/>
  259. <input type="submit" name="check" id="submit" class="button" style="margin-left: 13.3em;" value="<?php _e('Check Network Status');?>">
  260. </td>
  261. </tr>
  262. <?php endif; ?>
  263. <tr valign="top">
  264. <th scope="row"><?php _e('Last Checked');?></th>
  265. <td>
  266. <p><strong><?php echo get_option('akismet_connectivity_time') ? sprintf( __('%s Ago'), ucwords( human_time_diff( get_option('akismet_connectivity_time') ) ) ) : __( 'Not yet' ); ?></strong></p>
  267. <p class="description"><?php printf( __('You can confirm that Akismet.com is up by <a href="%s" target="_blank">clicking here</a>.'), 'http://status.automattic.com/9931/136079/Akismet-API' ); ?></p>
  268. </td>
  269. </tbody>
  270. </table>
  271. <?php akismet_nonce_field($akismet_nonce) ?>
  272. </form>
  273. <?php endif;?>
  274. </div>
  275. </div>
  276. <?php
  277. }
  278. function akismet_stats_display() {
  279. global $akismet_api_host, $akismet_api_port;
  280. $blog = urlencode( get_bloginfo('url') );
  281. $api_key = akismet_get_key();
  282. $config_link = esc_url( add_query_arg( array( 'page' => 'akismet-key-config' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'plugins.php' ) ) );?>
  283. <div class="wrap"><?php
  284. if ( !$api_key ) :?>
  285. <div id="akismet-warning" class="updated fade"><p><strong><?php _e('Akismet is almost ready.');?></strong> <?php printf( __( 'You must <a href="%1$s">enter your Akismet API key</a> for it to work.' ), $config_link );?></p></div><?php
  286. else :?>
  287. <iframe src="<?php echo esc_url( sprintf( '%s://akismet.com/web/1.0/user-stats.php?blog=%s&api_key=%s', is_ssl()?'https':'http', $blog, $api_key ) ); ?>" width="100%" height="2500px" frameborder="0" id="akismet-stats-frame"></iframe><?php
  288. endif;?>
  289. </div><?php
  290. }
  291. function akismet_stats() {
  292. if ( !function_exists('did_action') || did_action( 'rightnow_end' ) ) // We already displayed this info in the "Right Now" section
  293. return;
  294. if ( !$count = get_option('akismet_spam_count') )
  295. return;
  296. $path = plugin_basename(__FILE__);
  297. echo '<h3>' . _x( 'Spam', 'comments' ) . '</h3>';
  298. global $submenu;
  299. if ( isset( $submenu['edit-comments.php'] ) )
  300. $link = 'edit-comments.php';
  301. else
  302. $link = 'edit.php';
  303. echo '<p>'.sprintf( _n( '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', '<a href="%1$s">Akismet</a> has protected your site from <a href="%2$s">%3$s spam comments</a>.', $count ), 'http://akismet.com/?return=true', clean_url("$link?page=akismet-admin"), number_format_i18n($count) ).'</p>';
  304. }
  305. add_action('activity_box_end', 'akismet_stats');
  306. function akismet_admin_warnings() {
  307. global $wpcom_api_key, $pagenow;
  308. if (
  309. $pagenow == 'edit-comments.php'
  310. || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-key-config' )
  311. || ( !empty( $_GET['page'] ) && $_GET['page'] == 'akismet-stats-display' )
  312. ) {
  313. if ( get_option( 'akismet_alert_code' ) ) {
  314. function akismet_alert() {
  315. $alert = array(
  316. 'code' => (int) get_option( 'akismet_alert_code' ),
  317. 'msg' => get_option( 'akismet_alert_msg' )
  318. );
  319. ?>
  320. <div class='error'>
  321. <p><strong><?php _e( 'Akismet Error Code');?>: <?php echo $alert['code']; ?></strong></p>
  322. <p><?php esc_html_e( $alert['msg'] ); ?></p>
  323. <p><?php //FIXME: need to revert this to using __() in next version
  324. printf( translate( 'For more information:' ) . ' <a href="%s">%s</a>' , 'https://akismet.com/errors/'.$alert['code'], 'https://akismet.com/errors/'.$alert['code'] );?>
  325. </p>
  326. </div>
  327. <?php
  328. }
  329. add_action( 'admin_notices', 'akismet_alert' );
  330. }
  331. }
  332. if ( !get_option('wordpress_api_key') && !$wpcom_api_key && !isset($_POST['submit']) ) {
  333. function akismet_warning() {
  334. global $hook_suffix, $current_user;
  335. if ( $hook_suffix == 'plugins.php' ) {
  336. echo '
  337. <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
  338. <style type="text/css">
  339. .akismet_activate{min-width:825px;border:1px solid #4F800D;padding:5px;margin:15px 0;background:#83AF24;background-image:-webkit-gradient(linear,0% 0,80% 100%,from(#83AF24),to(#4F800D));background-image:-moz-linear-gradient(80% 100% 120deg,#4F800D,#83AF24);-moz-border-radius:3px;border-radius:3px;-webkit-border-radius:3px;position:relative;overflow:hidden}.akismet_activate .aa_a{position:absolute;top:-5px;right:10px;font-size:140px;color:#769F33;font-family:Georgia, "Times New Roman", Times, serif;z-index:1}.akismet_activate .aa_button{font-weight:bold;border:1px solid #029DD6;border-top:1px solid #06B9FD;font-size:15px;text-align:center;padding:9px 0 8px 0;color:#FFF;background:#029DD6;background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#029DD6),to(#0079B1));background-image:-moz-linear-gradient(0% 100% 90deg,#0079B1,#029DD6);-moz-border-radius:2px;border-radius:2px;-webkit-border-radius:2px}.akismet_activate .aa_button:hover{text-decoration:none !important;border:1px solid #029DD6;border-bottom:1px solid #00A8EF;font-size:15px;text-align:center;padding:9px 0 8px 0;color:#F0F8FB;background:#0079B1;background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#0079B1),to(#0092BF));background-image:-moz-linear-gradient(0% 100% 90deg,#0092BF,#0079B1);-moz-border-radius:2px;border-radius:2px;-webkit-border-radius:2px}.akismet_activate .aa_button_border{border:1px solid #006699;-moz-border-radius:2px;border-radius:2px;-webkit-border-radius:2px;background:#029DD6;background-image:-webkit-gradient(linear,0% 0,0% 100%,from(#029DD6),to(#0079B1));background-image:-moz-linear-gradient(0% 100% 90deg,#0079B1,#029DD6)}.akismet_activate .aa_button_container{cursor:pointer;display:inline-block;background:#DEF1B8;padding:5px;-moz-border-radius:2px;border-radius:2px;-webkit-border-radius:2px;width:266px}.akismet_activate .aa_description{position:absolute;top:22px;left:285px;margin-left:25px;color:#E5F2B1;font-size:15px;z-index:1000}.akismet_activate .aa_description strong{color:#FFF;font-weight:normal}
  340. </style>
  341. <form name="akismet_activate" action="'.esc_url( add_query_arg( array( 'page' => 'akismet-key-config' ), class_exists( 'Jetpack' ) ? admin_url( 'admin.php' ) : admin_url( 'plugins.php' ) ) ).'" method="POST">
  342. <input type="hidden" name="return" value="1"/>
  343. <input type="hidden" name="jetpack" value="'.(string) class_exists( 'Jetpack' ).'"/>
  344. <input type="hidden" name="user" value="'.esc_attr( $current_user->user_login ).'"/>
  345. <div class="akismet_activate">
  346. <div class="aa_a">A</div>
  347. <div class="aa_button_container" onclick="document.akismet_activate.submit();">
  348. <div class="aa_button_border">
  349. <div class="aa_button">'.__('Activate your Akismet account').'</div>
  350. </div>
  351. </div>
  352. <div class="aa_description">'.__('<strong>Almost done</strong> - activate your account and say goodbye to comment spam').'</div>
  353. </div>
  354. </form>
  355. </div>
  356. ';
  357. }
  358. }
  359. add_action('admin_notices', 'akismet_warning');
  360. return;
  361. } elseif ( ( empty($_SERVER['SCRIPT_FILENAME']) || basename($_SERVER['SCRIPT_FILENAME']) == 'edit-comments.php' ) && wp_next_scheduled('akismet_schedule_cron_recheck') ) {
  362. function akismet_warning() {
  363. global $wpdb;
  364. akismet_fix_scheduled_recheck();
  365. $waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->commentmeta WHERE meta_key = 'akismet_error'" );
  366. $next_check = wp_next_scheduled('akismet_schedule_cron_recheck');
  367. if ( $waiting > 0 && $next_check > time() )
  368. echo '
  369. <div id="akismet-warning" class="updated fade"><p><strong>'.__('Akismet has detected a problem.').'</strong> '.sprintf(__('Some comments have not yet been checked for spam by Akismet. They have been temporarily held for moderation. Please check your <a href="%s">Akismet configuration</a> and contact your web host if problems persist.'), 'admin.php?page=akismet-key-config').'</p></div>
  370. ';
  371. }
  372. add_action('admin_notices', 'akismet_warning');
  373. return;
  374. }
  375. }
  376. // FIXME placeholder
  377. function akismet_comment_row_action( $a, $comment ) {
  378. // failsafe for old WP versions
  379. if ( !function_exists('add_comment_meta') )
  380. return $a;
  381. $akismet_result = get_comment_meta( $comment->comment_ID, 'akismet_result', true );
  382. $akismet_error = get_comment_meta( $comment->comment_ID, 'akismet_error', true );
  383. $user_result = get_comment_meta( $comment->comment_ID, 'akismet_user_result', true);
  384. $comment_status = wp_get_comment_status( $comment->comment_ID );
  385. $desc = null;
  386. if ( $akismet_error ) {
  387. $desc = __( 'Awaiting spam check' );
  388. } elseif ( !$user_result || $user_result == $akismet_result ) {
  389. // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
  390. if ( $akismet_result == 'true' && $comment_status != 'spam' && $comment_status != 'trash' )
  391. $desc = __( 'Flagged as spam by Akismet' );
  392. elseif ( $akismet_result == 'false' && $comment_status == 'spam' )
  393. $desc = __( 'Cleared by Akismet' );
  394. } else {
  395. $who = get_comment_meta( $comment->comment_ID, 'akismet_user', true );
  396. if ( $user_result == 'true' )
  397. $desc = sprintf( __('Flagged as spam by %s'), $who );
  398. else
  399. $desc = sprintf( __('Un-spammed by %s'), $who );
  400. }
  401. // add a History item to the hover links, just after Edit
  402. if ( $akismet_result ) {
  403. $b = array();
  404. foreach ( $a as $k => $item ) {
  405. $b[ $k ] = $item;
  406. if (
  407. $k == 'edit'
  408. || ( $k == 'unspam' && $GLOBALS['wp_version'] >= 3.4 )
  409. ) {
  410. $b['history'] = '<a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="'. esc_attr__( 'View comment history' ) . '"> '. __('History') . '</a>';
  411. }
  412. }
  413. $a = $b;
  414. }
  415. if ( $desc )
  416. echo '<span class="akismet-status" commentid="'.$comment->comment_ID.'"><a href="comment.php?action=editcomment&amp;c='.$comment->comment_ID.'#akismet-status" title="' . esc_attr__( 'View comment history' ) . '">'.esc_html( $desc ).'</a></span>';
  417. if ( apply_filters( 'akismet_show_user_comments_approved', get_option('akismet_show_user_comments_approved') ) == 'true' ) {
  418. $comment_count = akismet_get_user_comments_approved( $comment->user_id, $comment->comment_author_email, $comment->comment_author, $comment->comment_author_url );
  419. $comment_count = intval( $comment_count );
  420. echo '<span class="akismet-user-comment-count" commentid="'.$comment->comment_ID.'" style="display:none;"><br><span class="akismet-user-comment-counts">'.sprintf( _n( '%s approved', '%s approved', $comment_count ), number_format_i18n( $comment_count ) ) . '</span></span>';
  421. }
  422. return $a;
  423. }
  424. add_filter( 'comment_row_actions', 'akismet_comment_row_action', 10, 2 );
  425. function akismet_comment_status_meta_box($comment) {
  426. $history = akismet_get_comment_history( $comment->comment_ID );
  427. if ( $history ) {
  428. echo '<div class="akismet-history" style="margin: 13px;">';
  429. foreach ( $history as $row ) {
  430. $time = date( 'D d M Y @ h:i:m a', $row['time'] ) . ' GMT';
  431. echo '<div style="margin-bottom: 13px;"><span style="color: #999;" alt="' . $time . '" title="' . $time . '">' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</span> - ';
  432. echo esc_html( $row['message'] ) . '</div>';
  433. }
  434. echo '</div>';
  435. }
  436. }
  437. // add an extra column header to the comments screen
  438. function akismet_comments_columns( $columns ) {
  439. $columns[ 'akismet' ] = __( 'Akismet' );
  440. return $columns;
  441. }
  442. #add_filter( 'manage_edit-comments_columns', 'akismet_comments_columns' );
  443. // Show stuff in the extra column
  444. function akismet_comment_column_row( $column, $comment_id ) {
  445. if ( $column != 'akismet' )
  446. return;
  447. $history = akismet_get_comment_history( $comment_id );
  448. if ( $history ) {
  449. echo '<dl class="akismet-history">';
  450. foreach ( $history as $row ) {
  451. echo '<dt>' . sprintf( __('%s ago'), human_time_diff( $row['time'] ) ) . '</dt>';
  452. echo '<dd>' . esc_html( $row['message'] ) . '</dd>';
  453. }
  454. echo '</dl>';
  455. }
  456. }
  457. #add_action( 'manage_comments_custom_column', 'akismet_comment_column_row', 10, 2 );
  458. // END FIXME
  459. // call out URLS in comments
  460. function akismet_text_add_link_callback( $m ) {
  461. // bare link?
  462. if ( $m[4] == $m[2] )
  463. return '<a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a>';
  464. else
  465. return '<span title="'.$m[2].'" class="comment-link"><a '.$m[1].' href="'.$m[2].'" '.$m[3].' class="comment-link">'.$m[4].'</a></span>';
  466. }
  467. function akismet_text_add_link_class( $comment_text ) {
  468. return preg_replace_callback( '#<a ([^>]*)href="([^"]+)"([^>]*)>(.*?)</a>#i', 'akismet_text_add_link_callback', $comment_text );
  469. }
  470. add_filter('comment_text', 'akismet_text_add_link_class');
  471. // WP 2.5+
  472. function akismet_rightnow() {
  473. global $submenu, $wp_db_version;
  474. if ( 8645 < $wp_db_version ) // 2.7
  475. $link = 'edit-comments.php?comment_status=spam';
  476. elseif ( isset( $submenu['edit-comments.php'] ) )
  477. $link = 'edit-comments.php?page=akismet-admin';
  478. else
  479. $link = 'edit.php?page=akismet-admin';
  480. if ( $count = get_option('akismet_spam_count') ) {
  481. $intro = sprintf( _n(
  482. '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comment already. ',
  483. '<a href="%1$s">Akismet</a> has protected your site from %2$s spam comments already. ',
  484. $count
  485. ), 'http://akismet.com/?return=true', number_format_i18n( $count ) );
  486. } else {
  487. $intro = sprintf( __('<a href="%1$s">Akismet</a> blocks spam from getting to your blog. '), 'http://akismet.com/?return=true' );
  488. }
  489. $link = function_exists( 'esc_url' ) ? esc_url( $link ) : clean_url( $link );
  490. if ( $queue_count = akismet_spam_count() ) {
  491. $queue_text = sprintf( _n(
  492. 'There\'s <a href="%2$s">%1$s comment</a> in your spam queue right now.',
  493. 'There are <a href="%2$s">%1$s comments</a> in your spam queue right now.',
  494. $queue_count
  495. ), number_format_i18n( $queue_count ), $link );
  496. } else {
  497. $queue_text = sprintf( __( "There's nothing in your <a href='%1\$s'>spam queue</a> at the moment." ), $link );
  498. }
  499. $text = $intro . '<br />' . $queue_text;
  500. echo "<p class='akismet-right-now'>$text</p>\n";
  501. }
  502. add_action('rightnow_end', 'akismet_rightnow');
  503. // For WP >= 2.5
  504. function akismet_check_for_spam_button($comment_status) {
  505. if ( 'approved' == $comment_status )
  506. return;
  507. if ( function_exists('plugins_url') )
  508. $link = 'admin.php?action=akismet_recheck_queue';
  509. else
  510. $link = 'edit-comments.php?page=akismet-admin&amp;recheckqueue=true&amp;noheader=true';
  511. echo "</div><div class='alignleft'><a class='button-secondary checkforspam' href='$link'>" . __('Check for Spam') . "</a>";
  512. }
  513. add_action('manage_comments_nav', 'akismet_check_for_spam_button');
  514. function akismet_submit_nonspam_comment ( $comment_id ) {
  515. global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
  516. $comment_id = (int) $comment_id;
  517. $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
  518. if ( !$comment ) // it was deleted
  519. return;
  520. // use the original version stored in comment_meta if available
  521. $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
  522. if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
  523. $comment = (object) array_merge( (array)$comment, $as_submitted );
  524. }
  525. $comment->blog = get_bloginfo('url');
  526. $comment->blog_lang = get_locale();
  527. $comment->blog_charset = get_option('blog_charset');
  528. $comment->permalink = get_permalink($comment->comment_post_ID);
  529. if ( is_object($current_user) ) {
  530. $comment->reporter = $current_user->user_login;
  531. }
  532. if ( is_object($current_site) ) {
  533. $comment->site_domain = $current_site->domain;
  534. }
  535. $comment->user_role = '';
  536. if ( isset( $comment->user_ID ) )
  537. $comment->user_role = akismet_get_user_roles($comment->user_ID);
  538. if ( akismet_test_mode() )
  539. $comment->is_test = 'true';
  540. $post = get_post( $comment->comment_post_ID );
  541. $comment->comment_post_modified_gmt = $post->post_modified_gmt;
  542. $query_string = '';
  543. foreach ( $comment as $key => $data )
  544. $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
  545. $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-ham", $akismet_api_port);
  546. if ( $comment->reporter ) {
  547. akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as not spam'), $comment->reporter ), 'report-ham' );
  548. update_comment_meta( $comment_id, 'akismet_user_result', 'false' );
  549. update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
  550. }
  551. do_action('akismet_submit_nonspam_comment', $comment_id, $response[1]);
  552. }
  553. function akismet_submit_spam_comment ( $comment_id ) {
  554. global $wpdb, $akismet_api_host, $akismet_api_port, $current_user, $current_site;
  555. $comment_id = (int) $comment_id;
  556. $comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_id'");
  557. if ( !$comment ) // it was deleted
  558. return;
  559. if ( 'spam' != $comment->comment_approved )
  560. return;
  561. // use the original version stored in comment_meta if available
  562. $as_submitted = get_comment_meta( $comment_id, 'akismet_as_submitted', true);
  563. if ( $as_submitted && is_array($as_submitted) && isset($as_submitted['comment_content']) ) {
  564. $comment = (object) array_merge( (array)$comment, $as_submitted );
  565. }
  566. $comment->blog = get_bloginfo('url');
  567. $comment->blog_lang = get_locale();
  568. $comment->blog_charset = get_option('blog_charset');
  569. $comment->permalink = get_permalink($comment->comment_post_ID);
  570. if ( is_object($current_user) ) {
  571. $comment->reporter = $current_user->user_login;
  572. }
  573. if ( is_object($current_site) ) {
  574. $comment->site_domain = $current_site->domain;
  575. }
  576. $comment->user_role = '';
  577. if ( isset( $comment->user_ID ) )
  578. $comment->user_role = akismet_get_user_roles($comment->user_ID);
  579. if ( akismet_test_mode() )
  580. $comment->is_test = 'true';
  581. $post = get_post( $comment->comment_post_ID );
  582. $comment->comment_post_modified_gmt = $post->post_modified_gmt;
  583. $query_string = '';
  584. foreach ( $comment as $key => $data )
  585. $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
  586. $response = akismet_http_post($query_string, $akismet_api_host, "/1.1/submit-spam", $akismet_api_port);
  587. if ( $comment->reporter ) {
  588. akismet_update_comment_history( $comment_id, sprintf( __('%s reported this comment as spam'), $comment->reporter ), 'report-spam' );
  589. update_comment_meta( $comment_id, 'akismet_user_result', 'true' );
  590. update_comment_meta( $comment_id, 'akismet_user', $comment->reporter );
  591. }
  592. do_action('akismet_submit_spam_comment', $comment_id, $response[1]);
  593. }
  594. // For WP 2.7+
  595. function akismet_transition_comment_status( $new_status, $old_status, $comment ) {
  596. if ( $new_status == $old_status )
  597. return;
  598. # we don't need to record a history item for deleted comments
  599. if ( $new_status == 'delete' )
  600. return;
  601. if ( !is_admin() )
  602. return;
  603. if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
  604. return;
  605. if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
  606. return;
  607. // if this is present, it means the status has been changed by a re-check, not an explicit user action
  608. if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
  609. return;
  610. global $current_user;
  611. $reporter = '';
  612. if ( is_object( $current_user ) )
  613. $reporter = $current_user->user_login;
  614. // Assumption alert:
  615. // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
  616. // is changed automatically by another plugin. Unfortunately WordPress doesn't provide an unambiguous way to
  617. // determine why the transition_comment_status action was triggered. And there are several different ways by which
  618. // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
  619. // We'll assume that this is an explicit user action if POST or GET has an 'action' key.
  620. if ( isset($_POST['action']) || isset($_GET['action']) ) {
  621. if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
  622. return akismet_submit_spam_comment( $comment->comment_ID );
  623. } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
  624. return akismet_submit_nonspam_comment( $comment->comment_ID );
  625. }
  626. }
  627. akismet_update_comment_history( $comment->comment_ID, sprintf( __('%s changed the comment status to %s'), $reporter, $new_status ), 'status-' . $new_status );
  628. }
  629. add_action( 'transition_comment_status', 'akismet_transition_comment_status', 10, 3 );
  630. // Total spam in queue
  631. // get_option( 'akismet_spam_count' ) is the total caught ever
  632. function akismet_spam_count( $type = false ) {
  633. global $wpdb;
  634. if ( !$type ) { // total
  635. $count = wp_cache_get( 'akismet_spam_count', 'widget' );
  636. if ( false === $count ) {
  637. if ( function_exists('wp_count_comments') ) {
  638. $count = wp_count_comments();
  639. $count = $count->spam;
  640. } else {
  641. $count = (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam'");
  642. }
  643. wp_cache_set( 'akismet_spam_count', $count, 'widget', 3600 );
  644. }
  645. return $count;
  646. } elseif ( 'comments' == $type || 'comment' == $type ) { // comments
  647. $type = '';
  648. } else { // pingback, trackback, ...
  649. $type = $wpdb->escape( $type );
  650. }
  651. return (int) $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = 'spam' AND comment_type='$type'");
  652. }
  653. function akismet_recheck_queue() {
  654. global $wpdb, $akismet_api_host, $akismet_api_port;
  655. akismet_fix_scheduled_recheck();
  656. if ( ! ( isset( $_GET['recheckqueue'] ) || ( isset( $_REQUEST['action'] ) && 'akismet_recheck_queue' == $_REQUEST['action'] ) ) )
  657. return;
  658. $moderation = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE comment_approved = '0'", ARRAY_A );
  659. foreach ( (array) $moderation as $c ) {
  660. $c['user_ip'] = $c['comment_author_IP'];
  661. $c['user_agent'] = $c['comment_agent'];
  662. $c['referrer'] = '';
  663. $c['blog'] = get_bloginfo('url');
  664. $c['blog_lang'] = get_locale();
  665. $c['blog_charset'] = get_option('blog_charset');
  666. $c['permalink'] = get_permalink($c['comment_post_ID']);
  667. $c['user_role'] = '';
  668. if ( isset( $c['user_ID'] ) )
  669. $c['user_role'] = akismet_get_user_roles($c['user_ID']);
  670. if ( akismet_test_mode() )
  671. $c['is_test'] = 'true';
  672. $id = (int) $c['comment_ID'];
  673. $query_string = '';
  674. foreach ( $c as $key => $data )
  675. $query_string .= $key . '=' . urlencode( stripslashes($data) ) . '&';
  676. add_comment_meta( $c['comment_ID'], 'akismet_rechecking', true );
  677. $response = akismet_http_post($query_string, $akismet_api_host, '/1.1/comment-check', $akismet_api_port);
  678. if ( 'true' == $response[1] ) {
  679. wp_set_comment_status($c['comment_ID'], 'spam');
  680. update_comment_meta( $c['comment_ID'], 'akismet_result', 'true' );
  681. delete_comment_meta( $c['comment_ID'], 'akismet_error' );
  682. akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and caught this comment as spam'), 'check-spam' );
  683. } elseif ( 'false' == $response[1] ) {
  684. update_comment_meta( $c['comment_ID'], 'akismet_result', 'false' );
  685. delete_comment_meta( $c['comment_ID'], 'akismet_error' );
  686. akismet_update_comment_history( $c['comment_ID'], __('Akismet re-checked and cleared this comment'), 'check-ham' );
  687. // abnormal result: error
  688. } else {
  689. update_comment_meta( $c['comment_ID'], 'akismet_result', 'error' );
  690. akismet_update_comment_history( $c['comment_ID'], sprintf( __('Akismet was unable to re-check this comment (response: %s)'), substr($response[1], 0, 50)), 'check-error' );
  691. }
  692. delete_comment_meta( $c['comment_ID'], 'akismet_rechecking' );
  693. }
  694. $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url( 'edit-comments.php' );
  695. wp_safe_redirect( $redirect_to );
  696. exit;
  697. }
  698. add_action('admin_action_akismet_recheck_queue', 'akismet_recheck_queue');
  699. // Adds an 'x' link next to author URLs, clicking will remove the author URL and show an undo link
  700. function akismet_remove_comment_author_url() {
  701. if ( !empty($_POST['id'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
  702. global $wpdb;
  703. $comment = get_comment( intval($_POST['id']), ARRAY_A );
  704. if (current_user_can('edit_comment', $comment['comment_ID'])) {
  705. $comment['comment_author_url'] = '';
  706. do_action( 'comment_remove_author_url' );
  707. print(wp_update_comment( $comment ));
  708. die();
  709. }
  710. }
  711. }
  712. add_action('wp_ajax_comment_author_deurl', 'akismet_remove_comment_author_url');
  713. function akismet_add_comment_author_url() {
  714. if ( !empty( $_POST['id'] ) && !empty( $_POST['url'] ) && check_admin_referer( 'comment_author_url_nonce' ) ) {
  715. global $wpdb;
  716. $comment = get_comment( intval($_POST['id']), ARRAY_A );
  717. if (current_user_can('edit_comment', $comment['comment_ID'])) {
  718. $comment['comment_author_url'] = esc_url($_POST['url']);
  719. do_action( 'comment_add_author_url' );
  720. print(wp_update_comment( $comment ));
  721. die();
  722. }
  723. }
  724. }
  725. add_action('wp_ajax_comment_author_reurl', 'akismet_add_comment_author_url');
  726. // Check connectivity between the WordPress blog and Akismet's servers.
  727. // Returns an associative array of server IP addresses, where the key is the IP address, and value is true (available) or false (unable to connect).
  728. function akismet_check_server_connectivity() {
  729. global $akismet_api_host, $akismet_api_port, $wpcom_api_key;
  730. $test_host = 'rest.akismet.com';
  731. // Some web hosts may disable one or both functions
  732. if ( !function_exists('fsockopen') || !function_exists('gethostbynamel') )
  733. return array();
  734. $ips = gethostbynamel($test_host);
  735. if ( !$ips || !is_array($ips) || !count($ips) )
  736. return array();
  737. $servers = array();
  738. foreach ( $ips as $ip ) {
  739. $response = akismet_verify_key( akismet_get_key(), $ip );
  740. // even if the key is invalid, at least we know we have connectivity
  741. if ( $response == 'valid' || $response == 'invalid' )
  742. $servers[$ip] = true;
  743. else
  744. $servers[$ip] = false;
  745. }
  746. return $servers;
  747. }
  748. // Check the server connectivity and store the results in an option.
  749. // Cached results will be used if not older than the specified timeout in seconds; use $cache_timeout = 0 to force an update.
  750. // Returns the same associative array as akismet_check_server_connectivity()
  751. function akismet_get_server_connectivity( $cache_timeout = 86400 ) {
  752. $servers = get_option('akismet_available_servers');
  753. if ( (time() - get_option('akismet_connectivity_time') < $cache_timeout) && $servers !== false )
  754. return $servers;
  755. // There's a race condition here but the effect is harmless.
  756. $servers = akismet_check_server_connectivity();
  757. update_option('akismet_available_servers', $servers);
  758. update_option('akismet_connectivity_time', time());
  759. return $servers;
  760. }
  761. // Returns true if server connectivity was OK at the last check, false if there was a problem that needs to be fixed.
  762. function akismet_server_connectivity_ok() {
  763. // skip the check on WPMU because the status page is hidden
  764. global $wpcom_api_key;
  765. if ( $wpcom_api_key )
  766. return true;
  767. $servers = akismet_get_server_connectivity();
  768. return !( empty($servers) || !count($servers) || count( array_filter($servers) ) < count($servers) );
  769. }
  770. function akismet_admin_menu() {
  771. if ( class_exists( 'Jetpack' ) ) {
  772. add_action( 'jetpack_admin_menu', 'akismet_load_menu' );
  773. } else {
  774. akismet_load_menu();
  775. }
  776. }
  777. function akismet_load_menu() {
  778. if ( class_exists( 'Jetpack' ) ) {
  779. add_submenu_page( 'jetpack', __( 'Akismet' ), __( 'Akismet' ), 'manage_options', 'akismet-key-config', 'akismet_conf' );
  780. add_submenu_page( 'jetpack', __( 'Akismet Stats' ), __( 'Akismet Stats' ), 'manage_options', 'akismet-stats-display', 'akismet_stats_display' );
  781. } else {
  782. add_submenu_page('plugins.php', __('Akismet'), __('Akismet'), 'manage_options', 'akismet-key-config', 'akismet_conf');
  783. add_submenu_page('index.php', __('Akismet Stats'), __('Akismet Stats'), 'manage_options', 'akismet-stats-display', 'akismet_stats_display');
  784. }
  785. }