Skip to content

Instantly share code, notes, and snippets.

View butlerblog's full-sized avatar

Chad Butler butlerblog

View GitHub Profile
@anthonyeden
anthonyeden / wordpress-date.php
Last active May 8, 2023 07:38
Wordpress Date() and StrToTime() Functions
<?php
function wp_date_localised($format, $timestamp = null) {
// This function behaves a bit like PHP's Date() function, but taking into account the Wordpress site's timezone
// CAUTION: It will throw an exception when it receives invalid input - please catch it accordingly
// From https://mediarealm.com.au/
$tz_string = get_option('timezone_string');
$tz_offset = get_option('gmt_offset', 0);
@carlodaniele
carlodaniele / custom-queries.php
Last active January 23, 2024 01:35
An example plugin showing how to add custom query vars, rewrite tags and rewrite rules to WordPress
<?php
/**
* @package Custom_queries
* @version 1.0
*/
/*
Plugin Name: Custom queries
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin
Author: Carlo Daniele
@asharirfan
asharirfan / remove-woocommerce-select2-styles-scripts.php
Last active February 19, 2018 14:40
This function removes select2 JS and CSS of WooCommerce so that theme can use its own.
<?php
if ( ! function_exists( 'remove_select2_wc' ) ) {
/**
* remove_select2_wc.
*
* This function removes select2 JS and CSS so that
* theme can use its own.
*/
function remove_select2_wc() {
@bananana
bananana / wp-update.sh
Last active September 17, 2023 21:07
Bash script to run automatic updates and backups using wp-cli
#!/bin/bash
#
# Backup and update WordPress using wp-cli
#
# Set the -e shell option so the script exits immediately if any command within
# it exits with a non-zero status.
set -e
# Set PATH environment variable
@bekarice
bekarice / wc-memberships-change-restricted-price.php
Last active February 4, 2019 22:42
WooCommerce Memberships: Change the price for purchase-restricted products that non-members will see
<?php
/**
* Modify membership product pricing display for non-members
* changes pricing display if purchasing is restricted to members;
* active members will see the price instead of a message
*
* @param string $price the WC price HTML
* @return string $price the updated price HTML
*/
function sv_change_member_product_price_display( $price ) {
@Aziz-Rahman
Aziz-Rahman / ajax-registration.js
Last active September 17, 2020 21:11
Register user with ajax (WP)
jQuery(document).ready(function($) {
/**
* When user clicks on button...
*
*/
$('#btn-new-user').on("click",function() {
/**
* Prevent default action, so when user clicks button he doesn't navigate away from page
@bekarice
bekarice / wc-free-checkout-fields.php
Last active October 31, 2021 19:10
Simplify WooCommerce checkout fields for free checkouts
<?php // only copy if needed
/**
* Removes coupon form, order notes, and several billing fields if the checkout doesn't require payment.
*
* REQUIRES PHP 5.3+
*
* Tutorial: http://skyver.ge/c
*/
function sv_free_checkout_fields() {
@slushman
slushman / jquery-datepicker-wp-admin
Last active October 19, 2022 14:25
How to Add the jQuery UI Datepicker to the WordPress Admin
/**
* Adds the datepicker settings to the admin footer.
* Only loads on the plugin-name settings page
*/
function admin_footer() {
$screen = get_current_screen();
if ( $screen->id == 'settings_page_plugin-name' ) {
@tommcfarlin
tommcfarlin / ajax-reg.js
Last active August 26, 2017 14:08 — forked from csknk/ajax-reg.js
/**
* This file is enqueued by means of wp_enqueue_script() - variables are passed
* in from PHP by means of wp_localize_script()
*
*/
/* TM: We use an anonymous function to invoke the JavaScript. Also refactored for proper
* WordPress coding standards.
*/
(function( $ ) {
@mildred
mildred / download.sh
Created October 20, 2014 10:03
Download from archive.org Wayback Machine
#!/bin/bash
url=http://redefininggod.com
webarchive=https://web.archive.org
wget="wget -e robots=off -nv"
tab="$(printf '\t')"
additional_url=url.list
# Construct listing.txt from url.list
# The list of archived pages, including some wildcard url