Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Plugin Name: Customizations for My Awesome Site
Plugin URI: https://example.com/about/
Description: Private customizations for my site.
Author: Me McWebmaster
Version: 1.0
Author URI: https://example.com/
*/
@DangitRick
DangitRick / self.php
Created February 13, 2018 07:57
Minimum requirement for a WordPress plugin.
<?php
/*
Plugin Name: Customizations for My Awesome Site
Plugin URI: https://example.com/about/
Description: Private customizations for my site.
Author: Me McWebmaster
Version: 1.0
Author URI: https://example.com/
*/
@DangitRick
DangitRick / expiring-keys-and-salts.php
Last active February 12, 2018 18:55
By default, WordPress' setup process asks uses to set a block of keys and salts with (preferably long and randomized) custom values. This default behavior allows you to log into your site and stay logged in forever. Using this block of code (or similar to it), you can force the keys and salts to update a few times a year.
<?php # Ignore this line when inserting this code into `wp-config.php`.
# Get the current month.
$month = date('n');
# Determine which quarter of the year we are in.
if ( 4 > $month ) {
$quarter = 1;
} elseif ( 4 <= $month && 7 > $month ) {
$quarter = 2;
@DangitRick
DangitRick / genericize_wordpress_login_errors.php
Last active April 5, 2017 05:53
Improve WordPress' login system by genericizing its login errors, preventing unauthorized users from discovering valid login names during brute force attacks or similar.This code is meant to be added to your theme's functions.php file or Thesis 1.8.5's custom_functions.php file.
<?php
/**
* Genericize login error messages
*/
function brazenly_genericize_login_errors( $error ) {
$new_message = 'The credentials provided are incorrect.';
$error = str_replace( 'Invalid username.', $new_message, $error );
$error = preg_replace( '{The password you entered for the username <strong>.*</strong> is incorrect\.}', $new_message, $error );
@DangitRick
DangitRick / sitename_shortcode.php
Created April 6, 2013 18:52
A quick & simple shortcode for use within WordPress posts which outputs the current, correct name of the site.
/**
* Sitename shortcode
*/
add_shortcode( 'sitename', function() { return get_bloginfo(); } );
@DangitRick
DangitRick / brazenly_delete_spam.php
Created April 2, 2013 22:55
Add this to your theme's functions.php file (or custom_functions.php if you're using Thesis 1.8.5) to enable auto-deletion of your spam comments on a twice daily basis. (Change "twicedaily" to "hourly" or "daily" to adjust how often spam is deleted. Do this prior to adding this to your site. Changing the frequency after you've already added it a…
/**
* Register deleting spam on a daily basis
*/
function brazenly_activate_spam_cleaning() {
if ( ! wp_next_scheduled( 'brazenly_deleting_spam' ) )
wp_schedule_event( time(), 'twicedaily', 'brazenly_deleting_spam' );
}
add_action( 'wp', 'brazenly_activate_spam_cleaning' );
@DangitRick
DangitRick / gravatar_profile_data.php
Last active December 15, 2015 16:29
The PHP required for Thesis 1.8.5's custom_functions.php file in order to pull open Gravatar profile data into your WordPress comments feed. All data is cached for an hour to prevent exploding your server. Tested on posts with a few hundred comments. Your mileage may vary on exceptionally well-commented posts.
/**
* Fetch & cache Gravatar profile information for commenters
*/
function brazenly_get_social_info( $data = false ) {
$email_hash = md5( strtolower( trim( get_comment_author_email() ) ) ); # Get the hash of comment author's email
$transient = 'brazenly-social-' . $email_hash; # Our cache/transient ID
# Check if our data is cached; otherwise, pull new from Gravatar
if ( false === ( $gravatar_profile = get_transient( $transient ) ) ) {
@DangitRick
DangitRick / gravatar_profile_data.css
Last active December 15, 2015 16:29
Custom CSS for including Gravatar profile data in the comments of a Thesis-enhanced WordPress site.
.comment_author_about {
color: #888;
display: block;
margin-left: 1em;
}
.comment_author_accounts {
display: block;
margin-left: 1em;
}