Skip to content

Instantly share code, notes, and snippets.

@msigley
Created August 7, 2014 15:42
Show Gist options
  • Save msigley/390fd888651818312c0e to your computer and use it in GitHub Desktop.
Save msigley/390fd888651818312c0e to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Simple Security
Plugin URI: https://github.com/msigley
Description: Simple Security for preventing comment spam and brute force attacks.
Version: 1.0.1
Author: Matthew Sigley
License: GPL2
*/
//Removes the WordPress version from your header for security
add_filter('the_generator', 'wb_remove_version');
//Removes detailed login error information for security
add_filter('login_errors',create_function('$a', "return null;"));
//Completely Disable Trackbacks
add_filter('pings_open', 'disable_all_trackbacks', 10, 2);
//Removes Trackbacks from the comment cout
add_filter('get_comments_number', 'comment_count', 0);
//Removes insecure information on dependancy includes
add_action('wp_print_scripts', 'sanitize_scripts', 9999);
add_action('wp_print_styles', 'sanitize_styles', 9999);
function sanitize_scripts() {
global $wp_scripts;
//Set version numbers to YYYYMMDD. This allows for better browser caching and easier maintenance.
$version = date('Ymd', current_time('timestamp'));
foreach( $wp_scripts->queue as $enqueued_script ) {
$wp_scripts->registered[$enqueued_script]->ver = $version;
}
}
function sanitize_styles() {
global $wp_styles;
//Set version numbers to YYYYMMDD. This allows for better browser caching and easier maintenance.
$version = date('Ymd', current_time('timestamp'));
foreach( $wp_styles->queue as $enqueued_style ) {
$wp_styles->registered[$enqueued_style]->ver = $version;
}
}
function wb_remove_version() {
return '';
}
function disable_all_trackbacks($open, $post_id) {
return false;
}
function comment_count( $count ) {
if ( ! is_admin() ) {
global $id;
$comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
return count($comments_by_type['comment']);
} else {
return $count;
}
}
@ericnakagawa
Copy link

have a coffee on me thank you. @changetip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment