Skip to content

Instantly share code, notes, and snippets.

View doubleedesign's full-sized avatar

Leesa Ward doubleedesign

View GitHub Profile
@doubleedesign
doubleedesign / shortcode-button.js
Created December 12, 2018 04:23
WordPress button shortcode builder
(function() {
tinymce.PluginManager.add('button', function( editor, url ) {
// Add button to the editor
editor.addButton('button', {
icon: 'link',
text: 'Button',
tooltip: 'Insert button',
onclick: function() {
@doubleedesign
doubleedesign / convert-milliseconds.js
Last active April 22, 2021 01:34
Timed pop-up using Zurb Foundation Reveal (modal); stores whether the user has dismissed it or already subscribed in local storage. This example is built in WordPress using ACF to get values of what to store, when to show up etc (and Ninja Forms for the form but of course it doesn't have to be used for a form).
/**
* Convert milliseconds to the desired format
* @param milliseconds
* @param format
* @returns {*}
* @see https://gist.github.com/flangofas/714f401b63a1c3d84aaa
*/
function convertMilliseconds(milliseconds, format) {
var total_days, total_hours, total_minutes, total_seconds;
@doubleedesign
doubleedesign / register-customised-woocommerce-filter-widgets.php
Last active April 22, 2019 12:30
Customise HTML markup of WooCommerce filter widgets: Add class according to the attribute it's being used for; add logo (using ACF field on the attribute terms) if it's the "brand" attribute filter. Could be modified to display differently, output additional data according to which attribtue it is, etc.
/**
* Widget areas
*
* @package WordPress
* @subpackage Promo Printing
* @since Promo Printing 1.0
*/
if (class_exists('Woocommerce')) {
@doubleedesign
doubleedesign / ninja-group-signup.php
Created April 22, 2019 13:02
Ninja Forms + Groups. When a user registers for an account using Ninja Forms User Management (https://ninjaforms.com/extensions/user-management), assign them to a group (https://wordpress.org/plugins/groups) according to the value of a drop-down selection which matches the "slug" format equivalent of the group name.
<?php
/**
* Get all groups
* Utility function
* @author Antonio Blanco
* @see https://github.com/eggemplo/Groups-Utilities/blob/master/get_groups.php
*/
function doublee_get_all_groups() {
global $wpdb;
$groups_table = _groups_get_tablename('group');
@doubleedesign
doubleedesign / checkout-functions.php
Created May 17, 2019 06:50
Add reCaptcha v2 to WooCommerce Checkout
<?php
/**
* Add reCaptcha to checkout form
* Note: Can't place within the payment part of the form, WooCommerce just won't show it, choose an appropriate action to add it to accordingly
* @param $checkout
*/
function doublee_show_me_the_checkout_captcha($checkout) {
echo '<div class="g-recaptcha" data-sitekey="YOUR_KEY_HERE"></div>';
}
add_action('woocommerce_checkout_order_review', 'doublee_show_me_the_checkout_captcha', 18);
@doubleedesign
doubleedesign / query.php
Last active January 8, 2020 06:01
Wordpress Event CPT: Filter archive by ACF date field, with month from and two selected by the user
<?php
/**
* Archive filter queries using the drop-downs on each archive
*
* @see filters.php
* @param $query
*/
function wh_filter_archives($query) {
// Do not modify queries in the admin
@doubleedesign
doubleedesign / scripts.js
Created May 18, 2020 09:05
Use Animate.css for Slick slider transitions
// Note: This assumes you already have the CSS set up for the classes you want to use.
function initCarousel() {
$('.my-carousel').slick({
slidesToShow: 1,
slidesToScroll: 1,
autoplay: false,
adaptiveHeight: false,
fade: true,
@doubleedesign
doubleedesign / add-base-tier-option.php
Last active January 18, 2021 01:11
Automatically downgrade a WooCommerce subscription (to a free, no-expiry variation) instead of expiring it
<?php
/**
* Add base tier option to Advanced tab of subscription product
*/
function doublee_subscription_product_advanced_settings() {
$product = wc_get_product(get_the_id());
if($product->get_type() === 'variable-subscription') {
$variations = $product->get_available_variations();
$variation_options = array();
foreach ($variations as $variation) {
@doubleedesign
doubleedesign / user-join-date-column.php
Created December 22, 2020 10:14
Add a join date column to the users table in wp-admin
<?php
/**
* Add custom columns in Users area in the CMS
* @param $columns
*
* @return mixed
*/
function doublee_manage_users_columns($columns) {
$columns['join_date'] = 'Join date';
@doubleedesign
doubleedesign / current-menu-item.php
Created January 3, 2021 07:26
Add class to CPT archive link in menus when viewing a post of that type
<?php
// Add current-menu-item to post type archive link for this post's type
function doublee_menu_classes($classes, $item) {
global $post;
$id = (isset($post->ID) ? get_the_ID() : NULL);
if(isset($id) && $item->type == 'post_type_archive') {
$current_post_type = get_post_type($id);
$link_post_type = $item->object;
if($current_post_type == $link_post_type) {