This website came in handy when I was working on a project that involved a webhook to connect two online services. It allows you to send a request and it will show the results. Nifty!
Redirecting attachment pages in WordPress
Spammers are a crafty bunch, using a variety of techniques to spread their unwanted junk. One way they do this is by submitting comments to the special pages WordPress creates for each image that has been uploaded. Spammers find these pages and submit spam. But there are ways to thwart their misdeeds!
7 Ways to Redirect WordPress Attachment Pages
Lately we’ve been using the Redirect Attachment Pages plugin, if the client does not have it available through an SEO plugin.
Finding large files on Linux
I had a client running out of disk space, and support gave me the command to find all the big stuff. This is to find files larger than 10MB. It prints a list ordered by smallest to largest.
sudo find / -mount -noleaf -type f -size +10000k -print0 | xargs -0 ls -lhSr | perl -ne ‘/(\S+\s+){4}(\S+)\s+(\S+\s+){3}(.*)/ and printf(“%*s %s\n”,7,$2.”:”,$4);’
One thing to note is that this didn’t include mailboxes… they must be stored somewhere else on this particular server. The culprit in this case turned out to be a mailbox that was 15GB (!!).
Logo creator
I found two pretty nice logo creators… the Adobe site made creating a new website logo a snap!
Validating fields in Gravity Forms
Despite CAPTCHA, spammers have been submitting spam forms on a few of our client’s websites. The submissions usually have the same first and last name, and often contain a website address in the message. I was able to add a little code to the theme’s functions.php to prevent this type of thing.
add_filter( 'gform_validation_1', 'validate_contact_fields_1' );
function validate_contact_fields_1( $validation_result ) {
$form = $validation_result['form'];
// first and last name can't be the same
if ( rgpost( 'input_1' ) == rgpost( 'input_2' ) ) {
// set the form validation to false
$validation_result['is_valid'] = false;
//finding Field with ID of 1 and marking it as failed validation
foreach( $form['fields'] as &$field ) {
//NOTE: replace 1 with the field you would like to validate
if ( $field->id == '1' ) {
$field->failed_validation = true;
$field->validation_message = 'First and Last Name can not be the same.';
break;
}
}
}
// Message can't contain a URL
$nourl_pattern = '(http|https)';
if ( preg_match( $nourl_pattern, rgpost( 'input_4' ) ) ) {
$validation_result['is_valid'] = false;
foreach( $form['fields'] as &$field ) {
if ( $field->id == '4' ) {
$field->failed_validation = true;
$field->validation_message = 'Message can not contain website addresses.';
break;
}
}
}
//Assign modified $form object back to the validation result
$validation_result['form'] = $form;
return $validation_result;
} // end function validate_contact_fields_1
Plugins for phpList
These plugins add the ability to more effectively manage campaigns, and sorely needed housekeeping functions.
Campaign Management: https://github.com/bramley/phplist-plugin-campaigns
Housekeeping: https://resources.phplist.com/plugin/housekeeping
Fixing anchor links that scroll too far down the page
For the second time, I needed to adjust the CSS for a site that is using anchor links. The problem was, the page would scroll down too far because of a fixed menu at the top of the page, and the anchor link area ended up underneath the menu.
The fix is to add this to the site’s CSS:
:target:before {
content:””;
display:block;
height:55px; /* fixed header height*/
margin:-55px 0 0; /* negative fixed header height */
}
Change the height and margin to match the height of the fixed menu. Sometimes the display setting needs a little tweaking, too. Woo!
Dejunking WordPress options
While investigating a slow WordPress installation, I came across this post on how to check if autoloaded options are a factor in the slowdown.
How To Remove Unwanted Autoloaded Data on a WordPress Website
I had no idea that plugins would leave so much junk behind! Here are the two queries to investigate. One to see how big the total options are, and the second to find the worst offenders.
SELECT SUM(LENGTH(option_value)) as autoload_size FROM wp_options WHERE autoload=’yes’;
SELECT LENGTH(option_value),option_name FROM wp_options WHERE autoload=’yes’ ORDER BY length(option_value) DESC LIMIT 15;
For the site I was working on, I set the unnecessary options to autoload=’no’ … just in case it would affect the site.
Google Slides
I recently learned how to make presentations with Google Slides. It’s pretty nice! Easy to use and you can export slides as JPG files. It’s also easy to embed a slide show into WordPress. Some sites may strip out the iframe, though.
https://gretathemes.com/embed-google-slides-into-wordpress/
Thanks, GretaThemes!
Emergency Recovery Script for WordPress
One of my newsletters had an article about this script, and I don’t want to forget about it, should I ever need it! Fingers crossed I never do.