Skip to content

Instantly share code, notes, and snippets.

View topmask's full-sized avatar
🤩
Out sick

Allen Smith topmask

🤩
Out sick
View GitHub Profile
@topmask
topmask / _common.conf
Created October 15, 2021 00:06 — forked from Daniel15/_common.conf
WordPress config with WP Super Cache for Nginx
# /etc/nginx/snippets/wordpress/common.conf
index index.php;
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
}
# Block PHP files in uploads, content, and includes directory.
location ~* /(?:uploads|files|wp-content|wp-includes)/.*\.php$ {
@topmask
topmask / page-contact-form.php
Created October 19, 2021 08:03 — forked from tmblog/page-contact-form.php
Simple WordPress Contact Form without Plugin - Bootstrap ready.
<?php /* Template Name: Contact Page */
$response = "";
//function to generate response
function my_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='alert alert-success'>{$message}</div>";
else $response = "<div class='alert alert-danger'>{$message}</div>";
#!/usr/bin/env bash
# WP-CLI Back up Script to Amazon S3
# Source: https://www.jonathan.vc
# Author: Jonathan Dingman
# Adapted from Mike at WP Bullet
#define local path for backups
BACKUPPATH=/tmp/backups
#path to WordPress installations
@topmask
topmask / disable automatic updates
Created October 27, 2021 05:27
disable automatic updates
add_filter( 'plugins_auto_update_enabled', '__return_false' );
add_filter( 'themes_auto_update_enabled', '__return_false' );
define( 'automatic_updater_disabled', true );
define( 'wp_auto_update_core', false );
@topmask
topmask / checkout remove coupon form
Created October 27, 2021 05:24
checkout remove coupon form
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
@topmask
topmask / Enable preview thumbnail for webp image files
Last active October 27, 2021 05:33
Enable upload for webp image files
function webp_is_displayable($result, $path) {
if ($result === false) {
$displayable_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
@topmask
topmask / Disable bad robots from registering
Last active October 27, 2021 05:37
Disable bad robots register
function add_security_question_fields() {
$num1=rand(1,9);
$num2=rand(2,9);
echo "<p><label for='math' class='small'>Captcha:$num1 + $num2 = ? </label><input type='text' name='sum' class='input' value='' size='25'>"
."<input type='hidden' name='num1' value='$num1'>"
."<input type='hidden' name='num2' value='$num2'></p>";}
add_action('register_form','add_security_question_fields');
add_action( 'register_post', 'add_security_question_validate', 10, 3 );
function add_security_question_validate( $sanitized_user_login, $user_email, $errors){
@topmask
topmask / Fix for “Sold Individually” Products
Created October 27, 2021 05:18
Fix for “Sold Individually” Products
add_filter( 'woocommerce_product_add_to_cart_url', 'elftoy_fix_for_individual_products', 10, 2 );
function elftoy_fix_for_individual_products( $add_to_cart_url, $product ){
if( $product->get_sold_individually() // if individual product
&& WC()->cart->find_product_in_cart( WC()->cart->generate_cart_id( $product->id ) ) // if in the cart
&& $product->is_purchasable() // we also need these two conditions
&& $product->is_in_stock() ) {
$add_to_cart_url = wc_get_checkout_url();
}
@topmask
topmask / Add-to-cart redirection to checkout
Created October 27, 2021 05:13
Add-to-cart redirection to checkout
add_filter( 'woocommerce_add_to_cart_redirect', function( $wc_cart_url ) {
return wc_get_checkout_url();
} );
@topmask
topmask / disable Self-Pingbacks
Created October 27, 2021 05:10
disable Self-Pingbacks
function wpsites_disable_self_pingbacks( &$links ) {
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, get_option( 'home' ) ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'wpsites_disable_self_pingbacks' );