Skip to content

Instantly share code, notes, and snippets.

View chuckreynolds's full-sized avatar
🤖
building things

Chuck Reynolds chuckreynolds

🤖
building things
View GitHub Profile
@chuckreynolds
chuckreynolds / wp-clean-transients-trackbacks-revisions.sql
Created February 28, 2013 09:28
removes transients temporary stuff - removes all pingbacks/trackbacks - removes all post revisions 1. comment out or just don't copy certain lines if you don't want to remove that stuff 2. remember to change the wp_ prefix to whatever yours is if you've modified it from default
DELETE FROM wp_options WHERE option_name LIKE '_transient_%';
DELETE FROM wp_comments WHERE wp_comments.comment_type = 'pingback';
DELETE FROM wp_comments WHERE wp_comments.comment_type = 'trackback';
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';
@chuckreynolds
chuckreynolds / wp-change-db-table-prefix.sql
Created February 28, 2013 09:35
Change Table Prefix's on WordPress Database Most client sites I redo have the default "wp_" table prefix and I like to change that to something random like "wp_fE4se_" (or whatever) for security reasons. 1) run the RENAME table on each and every table in your wordpress database to rename the table itself 2) Run the next two lines and change NEWP…
RENAME table wp_commentmeta TO wp_NEWPREFIX_commentmeta;
RENAME table wp_comments TO wp_NEWPREFIX_comments;
RENAME table wp_links TO wp_NEWPREFIX_links;
RENAME table wp_options TO wp_NEWPREFIX_options;
RENAME table wp_postmeta TO wp_NEWPREFIX_postmeta;
RENAME table wp_posts TO wp_NEWPREFIX_posts;
RENAME table wp_terms TO wp_NEWPREFIX_terms;
RENAME table wp_term_relationships TO wp_NEWPREFIX_term_relationships;
RENAME table wp_term_taxonomy TO wp_NEWPREFIX_term_taxonomy;
RENAME table wp_usermeta TO wp_NEWPREFIX_usermeta;
@chuckreynolds
chuckreynolds / wp-fix-curly-quotes.sql
Created February 28, 2013 09:36
SQL Statement Replace Smart Curly Quotes with Regular Quotes in WordPress. I was migrating an old wp site with a ton of content I noticed a lot of curly quotes / smart quotes and the curly single quotes. My OCD hates that and it's not proper and looks bad to bots so I wanted to batch change them all to regular ascii quotes. This statement handle…
UPDATE wp_posts SET post_content = replace(replace(replace(post_content, '“', '"'), '”', '"'), '’', '''');
@chuckreynolds
chuckreynolds / wp-user-custom-fields.php
Created February 28, 2013 09:39
Custom WordPress User Profile Fields. Who EVER fills out the yim/aim/jabber fields in their wordpress profile? not me and not clients lol... in this, it removes those three fields and adds twitter, facebook and google+ profile url fields. How to add those those new fields to the front end is included in comments
// Add custom fields to user profiles
function vuurr_sm_contactmethods( $contactmethods ) {
// Add
$contactmethods['twitter'] = 'Twitter';
$contactmethods['facebook'] = 'Facebook';
$contactmethods['googleplus'] = 'Google+ About';
// Remove
unset($contactmethods['yim']);
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
@chuckreynolds
chuckreynolds / wp-rem-update-notify-admins.php
Created February 28, 2013 09:45
Remove WordPress Update Notifications Except for Admins
global $user_login;
get_currentuserinfo();
if (!current_user_can('update_plugins')) { /* checks to see if current user can update plugins */
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
@chuckreynolds
chuckreynolds / wp-null-search-redirect.htaccess
Created March 7, 2013 15:49
Redirect empty searches in WordPress back to root. Empty ?s= suck and WP doesn't handle them. You should.
# Redirect Empty Searches to root
RewriteCond %{QUERY_STRING} ^s=$
RewriteRule ^ /? [L,R=301]
@chuckreynolds
chuckreynolds / yoast-wpseo-default-setup.ini
Last active December 14, 2015 15:39
For now this is my base setup for Yoast's WordPress SEO plugin - good import for basic technical setup in WP. NOTE: This is not an import and forget it type of thing. I HIGHLY STRESS that you still go through EVERY settings page and Tab in the Yoast SEO plugin settings and make sure you set it up for your exact needs. This is a good start but do…
; This is a settings export file for the WordPress SEO plugin by Yoast.com - http://yoast.com/wordpress/seo/
[wpseo]
ignore_blog_public_warning =
ignore_tour = "ignore"
ignore_page_comments =
ignore_permalink =
ms_defaults_set =
version = "1.4.1"
tracking_popup = "done"
@chuckreynolds
chuckreynolds / wordpress-activate-link-manager.php
Created March 25, 2013 22:47
In WordPress 3.5+ the removed what used to be known as "links" in the admin. For now... in order to reenable that... use this filter
@chuckreynolds
chuckreynolds / wordpress-redirect-post-single-query.php
Created April 4, 2013 20:11
Redirect to post if a search only returns one post.. Just paste the following code snippet into your functions.php file:
add_action('template_redirect', 'redirect_single_post');
function redirect_single_post() {
if (is_search()) {
global $wp_query;
if ($wp_query->post_count == 1) {
wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
}
}
}
@chuckreynolds
chuckreynolds / wp-block-updates-after-time.php
Created April 26, 2013 23:05
Block WordPress Post Updates and Deletion After a Set Period. ganked from here as may need this in future.... http://www.wpbeginner.com/wp-tutorials/how-to-block-wordpress-post-updates-and-deletion-after-a-set-period/
function wpbeginner_restrict_editing( $allcaps, $cap, $args ) {
// Bail out if we're not asking to edit or delete a post ...
if( 'edit_post' != $args[0] && 'delete_post' != $args[0]
// ... or user is admin
|| !empty( $allcaps['manage_options'] )
// ... or user already cannot edit the post
|| empty( $allcaps['edit_posts'] ) )
return $allcaps;