Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
rafaehlers / gv_age.php
Last active May 21, 2018 20:06
Calculate a person's age based on a date field
<?php
add_shortcode( 'gv_age', 'gv_calculate_age' );
/**
* Calculate age in years based on entry data
*
* Usage inside a Custom Content field (Replace "2" with the ID of the date field):
*
* <code>
@adamcapriola
adamcapriola / wordpress-discourse-sso.php
Created February 5, 2015 04:13
WordPress --> Discourse SSO
<?php
/**
* SSO "Page"
*
*/
add_action( 'parse_request', 'ac_parse_request' );
function ac_parse_request() {
// Check for SSO request
@zmwangx
zmwangx / Postfix: sender-dependent SASL authentication.md
Last active April 15, 2024 06:34
Postfix: sender-dependent SASL authentication — relay to multiple SMTP hosts, or relay to the same host but authenticate as different users (e.g., two Gmail accounts)

This is a sequel to "Postfix: relay to authenticated SMTP".

I would like to send mail from two different Gmail accounts using Postfix. Here is the relevant section in the Postfix documentation: Configuring Sender-Dependent SASL authentication.

As a concrete example, here's how to set up two Gmail accounts (only relevant sections of the config files are listed below):

/etc/postfix/main.cf:
    # sender-dependent sasl authentication
    smtp_sender_dependent_authentication = yes

sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

@cliffordp
cliffordp / functions.php
Last active September 23, 2023 06:22
Automatically login a single WordPress user upon arrival to a specific page.
<?php
/**
* Automatically login a single WordPress user upon arrival to a specific page.
*
* Redirect to home page once logged in and prevent viewing of the login page.
* Compatible with WordPress 3.9.1+
* Updated 2014-07-18 to resolve WP_DEBUG notice: "get_userdatabylogin is deprecated since version 3.3! Use get_user_by('login') instead."
* Updated 2019-07-09 to reformat code, pass 2nd parameter to `do_action()`, and hook into priority 1.
*
@woogist
woogist / gist:f82d5132e474d510f3e8
Created June 11, 2014 15:28
unregister / enqueue Bookings styles
<?php
function woo_dequeue_booking_styles() {
wp_dequeue_style( 'wc-bookings-styles' );
wp_deregister_style( 'wc-bookings-styles' );
}
add_action( 'wp_print_styles', 'woo_dequeue_booking_styles', 100 );
@codearachnid
codearachnid / wc_customer_bought_product.php
Created February 27, 2014 21:07
WooCommerce check if user has already bought product.
<?php
// if product is already in global space
global $product;
// or fetch product attributes by ID
if( empty( $product->id ) ){
$wc_pf = new WC_Product_Factory();
$product = $wc_pf->get_product($id);
}
// Get The Page ID You Need
get_option( 'woocommerce_shop_page_id' );
get_option( 'woocommerce_cart_page_id' );
get_option( 'woocommerce_checkout_page_id' );
get_option( 'woocommerce_pay_page_id' );
get_option( 'woocommerce_thanks_page_id' );
get_option( 'woocommerce_myaccount_page_id' );
get_option( 'woocommerce_edit_address_page_id' );
get_option( 'woocommerce_view_order_page_id' );
get_option( 'woocommerce_terms_page_id' );
@codeguy
codeguy / slugify.js
Created September 24, 2013 13:19
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@jameskoster
jameskoster / functions.php
Last active July 7, 2017 23:43
WooCommerce - dequeue css (2.1+)
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
// Or just remove them all in one line