Skip to content

Instantly share code, notes, and snippets.

@ddbs
ddbs / functions.php
Last active August 29, 2015 13:56
wordpress functions.php: remove core and plugin update messages
// remove plugin update messages
remove_action( 'load-update-core.php', 'wp_update_plugins' );
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
@ddbs
ddbs / gist:9238149
Created February 26, 2014 20:44
sql: insert only new records
INSERT IGNORE INTO _customers (`User ID`, Username)
SELECT `User ID`, Username
FROM _customers_import
@ddbs
ddbs / gist:9239403
Last active August 29, 2015 13:56
sql: insert on duplicate key update (update only specific columns if a unique key already exists; insert new rows if unique key does not exist)
INSERT INTO _customers (`User ID`, Username, `Billing: Full Name` )
SELECT `User ID`, Username, `Billing: Full Name`
FROM _customers_import
ON DUPLICATE KEY UPDATE Username=values(Username), `Billing: Full Name`=values(`Billing: Full Name`)
@ddbs
ddbs / functions.php
Last active August 12, 2019 21:10
woocommerce: make checkout fields not required
//make billing fields not required in checkout
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
function wc_npr_filter_phone( $address_fields ) {
$address_fields['billing_phone']['required'] = false;
return $address_fields;
}
//make shipping fields not required in checkout
add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_shipping_fields', 10, 1 );
function wc_npr_filter_shipping_fields( $address_fields ) {
@ddbs
ddbs / gist:9403910
Last active August 29, 2015 13:57
wordpress security: avoid requests from malicious urls
global $user_ID;
if($user_ID) {
if(!current_user_can('administrator')) {
if (strlen($_SERVER['REQUEST_URI']) > 255 ||
stripos($_SERVER['REQUEST_URI'], "eval(") ||
stripos($_SERVER['REQUEST_URI'], "CONCAT") ||
stripos($_SERVER['REQUEST_URI'], "UNION+SELECT") ||
stripos($_SERVER['REQUEST_URI'], "base64")) {
@header("HTTP/1.1 414 Request-URI Too Long");
@header("Status: 414 Request-URI Too Long");
@ddbs
ddbs / gist:9403929
Created March 7, 2014 02:27
wordpress security: remove error log messages
add_filter('login_errors',create_function('$a', "return null;"));
@ddbs
ddbs / gist:9403938
Created March 7, 2014 02:28
wordpress security: force SSL usage
define('FORCE_SSL_ADMIN', true);
<?php
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
<?php
// Copies woocommerce orders and users over from source to target.
// I use this on my local machine - loading both db's up there side by side
// could easily adjust the connect strings to connect elsewhere if needed.
// will change order ids
// My use case for this is when I've got a staging/test version of a site with new posts/products/pages etc, that needs
// to go live without the loss of any orders placed on the site site since we copied it to the staging site.
<?php
/*
Template Name: Print Processing Orders :)
*/
if (!is_user_logged_in() || !current_user_can('manage_options')) wp_die('This page is private.');
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />