wp/wp-content/plugins/akismet/class.akismet-admin.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    72 
    72 
    73 		if ( class_exists( 'Jetpack' ) ) {
    73 		if ( class_exists( 'Jetpack' ) ) {
    74 			add_filter( 'akismet_comment_form_privacy_notice_url_display',  array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
    74 			add_filter( 'akismet_comment_form_privacy_notice_url_display',  array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
    75 			add_filter( 'akismet_comment_form_privacy_notice_url_hide',     array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
    75 			add_filter( 'akismet_comment_form_privacy_notice_url_hide',     array( 'Akismet_Admin', 'jetpack_comment_form_privacy_notice_url' ) );
    76 		}
    76 		}
       
    77 
       
    78 		// priority=1 because we need ours to run before core's comment anonymizer runs, and that's registered at priority=10
       
    79 		add_filter( 'wp_privacy_personal_data_erasers', array( 'Akismet_Admin', 'register_personal_data_eraser' ), 1 );
    77 	}
    80 	}
    78 
    81 
    79 	public static function admin_init() {
    82 	public static function admin_init() {
    80 		load_plugin_textdomain( 'akismet' );
    83 		load_plugin_textdomain( 'akismet' );
    81 		add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
    84 		add_meta_box( 'akismet-status', __('Comment History', 'akismet'), array( 'Akismet_Admin', 'comment_status_meta_box' ), 'comment', 'normal' );
   385 		$link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
   388 		$link = add_query_arg( array( 'action' => 'akismet_recheck_queue' ), admin_url( 'admin.php' ) );
   386 
   389 
   387 		$comments_count = wp_count_comments();
   390 		$comments_count = wp_count_comments();
   388 		
   391 		
   389 		echo '</div>';
   392 		echo '</div>';
   390 		echo '<div class="alignleft">';
   393 		echo '<div class="alignleft actions">';
   391 		echo '<a
   394 		echo '<a
   392 				class="button-secondary checkforspam"
   395 				class="button-secondary checkforspam' . ( $comments_count->moderated == 0 ? ' button-disabled' : '' ) . '"
   393 				href="' . esc_url( $link ) . '"
   396 				href="' . esc_url( $link ) . '"
   394 				data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '"
   397 				data-active-label="' . esc_attr( __( 'Checking for Spam', 'akismet' ) ) . '"
   395 				data-progress-label-format="' . esc_attr( __( '(%1$s%)', 'akismet' ) ) . '"
   398 				data-progress-label-format="' . esc_attr( __( '(%1$s%)', 'akismet' ) ) . '"
   396 				data-success-url="' . esc_attr( remove_query_arg( 'akismet_recheck', add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
   399 				data-success-url="' . esc_attr( remove_query_arg( 'akismet_recheck', add_query_arg( array( 'akismet_recheck_complete' => 1, 'recheck_count' => urlencode( '__recheck_count__' ), 'spam_count' => urlencode( '__spam_count__' ) ) ) ) ) . '"
   397 				data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '"
   400 				data-pending-comment-count="' . esc_attr( $comments_count->moderated ) . '"
  1047 			else {
  1050 			else {
  1048 				$message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) );
  1051 				$message = sprintf( _n( 'Akismet checked %s comment.', 'Akismet checked %s comments.', $recheck_count, 'akismet' ), number_format( $recheck_count ) );
  1049 				$message .= ' ';
  1052 				$message .= ' ';
  1050 			
  1053 			
  1051 				if ( $spam_count === 0 ) {
  1054 				if ( $spam_count === 0 ) {
  1052 					$message .= __( 'No comments were caught as spam.' );
  1055 					$message .= __( 'No comments were caught as spam.', 'akismet' );
  1053 				}
  1056 				}
  1054 				else {
  1057 				else {
  1055 					$message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) );
  1058 					$message .= sprintf( _n( '%s comment was caught as spam.', '%s comments were caught as spam.', $spam_count, 'akismet' ), number_format( $spam_count ) );
  1056 				}
  1059 				}
  1057 			}
  1060 			}
  1178 	}
  1181 	}
  1179 
  1182 
  1180 	public static function jetpack_comment_form_privacy_notice_url( $url ) {
  1183 	public static function jetpack_comment_form_privacy_notice_url( $url ) {
  1181 		return str_replace( 'options-general.php', 'admin.php', $url );
  1184 		return str_replace( 'options-general.php', 'admin.php', $url );
  1182 	}
  1185 	}
       
  1186 	
       
  1187 	public static function register_personal_data_eraser( $erasers ) {
       
  1188 		$erasers['akismet'] = array(
       
  1189 			'eraser_friendly_name' => __( 'Akismet', 'akismet' ),
       
  1190 			'callback' => array( 'Akismet_Admin', 'erase_personal_data' ),
       
  1191 		);
       
  1192 
       
  1193 		return $erasers;
       
  1194 	}
       
  1195 	
       
  1196 	/**
       
  1197 	 * When a user requests that their personal data be removed, Akismet has a duty to discard
       
  1198 	 * any personal data we store outside of the comment itself. Right now, that is limited
       
  1199 	 * to the copy of the comment we store in the akismet_as_submitted commentmeta.
       
  1200 	 *
       
  1201 	 * FWIW, this information would be automatically deleted after 15 days.
       
  1202 	 * 
       
  1203 	 * @param $email_address string The email address of the user who has requested erasure.
       
  1204 	 * @param $page int This function can (and will) be called multiple times to prevent timeouts,
       
  1205 	 *                  so this argument is used for pagination.
       
  1206 	 * @return array
       
  1207 	 * @see https://developer.wordpress.org/plugins/privacy/adding-the-personal-data-eraser-to-your-plugin/
       
  1208 	 */
       
  1209 	public static function erase_personal_data( $email_address, $page = 1 ) {
       
  1210 		$items_removed = false;
       
  1211 		
       
  1212 		$number = 50;
       
  1213 		$page = (int) $page;
       
  1214 
       
  1215 		$comments = get_comments(
       
  1216 			array(
       
  1217 				'author_email' => $email_address,
       
  1218 				'number'       => $number,
       
  1219 				'paged'        => $page,
       
  1220 				'order_by'     => 'comment_ID',
       
  1221 				'order'        => 'ASC',
       
  1222 			)
       
  1223 		);
       
  1224 
       
  1225 		foreach ( (array) $comments as $comment ) {
       
  1226 			$comment_as_submitted = get_comment_meta( $comment->comment_ID, 'akismet_as_submitted', true );
       
  1227 			
       
  1228 			if ( $comment_as_submitted ) {
       
  1229 				delete_comment_meta( $comment->comment_ID, 'akismet_as_submitted' );
       
  1230 				$items_removed = true;
       
  1231 			}
       
  1232 		}
       
  1233 
       
  1234 		// Tell core if we have more comments to work on still
       
  1235 		$done = count( $comments ) < $number;
       
  1236 		
       
  1237 		return array(
       
  1238 			'items_removed' => $items_removed,
       
  1239 			'items_retained' => false, // always false in this example
       
  1240 			'messages' => array(), // no messages in this example
       
  1241 			'done' => $done,
       
  1242 		);
       
  1243 	}
  1183 }
  1244 }