Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@kimcoleman
kimcoleman / add_specific_menu_utm_parameters.php
Created August 31, 2022 11:02
Add UTM tracking to footer menu use case links.
<?php
/**
* Add UTM tracking to footer menu use case links.
*/
function add_specific_menu_utm_parameters( $atts, $item, $args ) {
if ( $args->menu->slug == 'footer-menu-use-cases' ) {
$atts['href'] .= '?utm_source=footer&utm_medium=' . $atts['title'] . '&utm_campaign=use-cases';
}
return $atts;
}
@kimcoleman
kimcoleman / load_my_jquery_datepicker_script_for_pmpro.php
Created August 27, 2022 16:09
Script to load a datepicker that targets the custom user field with class name 'my-datepicker'
<?php
/**
* Load datepicker script for specific pages.
*/
function load_my_jquery_datepicker_script_for_pmpro() {
global $pmpro_pages;
if ( is_page( array( $pmpro_pages['checkout'], $pmpro_pages['member_profile_edit'] ) ) ||
defined( 'IS_PROFILE_PAGE' ) ||
( is_admin() &&
@kimcoleman
kimcoleman / my_swsales_swsales_banner_dismiss_link_html.php
Created July 23, 2022 12:49
Hide the banner dismiss link on banners in Sitewide Sales. Requires Sitewide Sales v1.3+
@kimcoleman
kimcoleman / my_memberlite_show_author_avatar.php
Created July 21, 2022 16:37
Hide author avatars in loop views and on single masthead view.
<?php
/**
* Hide author avatars in loop views and on single masthead view.
*/
function my_memberlite_show_author_avatar( ) {
return false;
}
add_filter( 'memberlite_show_author_avatar', 'my_memberlite_show_author_avatar' );
@kimcoleman
kimcoleman / my_reusable_blocks_screen_add_column.php
Created July 18, 2022 20:23
Add a column to the Reusable Blocks screen to show the posts the block is used in.
<?php
/**
* Add column to show all posts a reusable block is used in.
*/
function my_reusable_blocks_screen_add_column( $columns ) {
$columns['posts_used_in'] = esc_html__( 'Used In', 'textdomain' );
return $columns;
}
add_filter( 'manage_wp_block_posts_columns', 'my_reusable_blocks_screen_add_column' );
@kimcoleman
kimcoleman / my_custom_editor_color_palette_extended.php
Created July 14, 2022 14:11
Add additional colors to the Block Editor color palette.
<?php
/**
* Add additional colors to the Block Editor color palette.
* Update and insert additional colors into the $new_colors array.
*
*/
function my_custom_editor_color_palette_extended() {
$editor_settings = get_block_editor_settings( array(), 'core/edit-post' );
$new_colors = array(
array(
@kimcoleman
kimcoleman / my_custom_colors_block_editor.php
Last active July 14, 2022 13:59
Add colors to block editor color palette.
<?php
/**
* Add colors to block editor color palette.
*
*/
function my_custom_colors_block_editor( $editor_settings, $editor_context ) {
$my_custom_colors = array(
array(
'name' => __( 'New Color 1', 'textdomain' ),
'slug' => 'my-new-color-1',
@kimcoleman
kimcoleman / my_pmpro_remove_subscription_delay_for_renewals.php
Created July 11, 2022 14:07
Remove subscription delay for existing/past members. Charge them the full level price immediately at checkout. Update the level cost text.
<?php
/**
* Remove subscription delay for existing/past members.
*/
function my_pmpro_remove_subscription_delay_for_renewals() {
if ( is_admin() || ! is_user_logged_in() ) {
return;
}
$order = new MemberOrder();
@kimcoleman
kimcoleman / my_single_product_auto_discount_woocommerce_shop.php
Last active June 29, 2022 14:22
A collection of recipes to force add a single product to the WooCommerce cart and redirect from the shop, single product, and cart pages right to checkout.
<?php
/**
* Always add my single product by ID to the cart if it isn't already there.
*/
function my_woocommerce_force_add_product_to_cart() {
$product_id = 325;
$product_cart_id = WC()->cart->generate_cart_id( $product_id );
if ( ! WC()->cart->find_product_in_cart( $product_cart_id ) ) {
// Yep, the product with ID is NOT in the cart, let's add it then!
WC()->cart->add_to_cart( $product_id );
@kimcoleman
kimcoleman / my_edd_remove_discount_field.php
Last active June 23, 2022 12:06
Hide the Discount Code field on Easy Digital Downloads checkout.
<?php
/**
* Hide the Discount Code field on Easy Digital Downloads checkout.
* Customers can only apply coupons using a URL attribute like:
* http://sitewidesales.local/checkout/?discount=loyal.
*/
function my_edd_no_discount_code_on_checkout() {
remove_action( 'edd_checkout_form_top', 'edd_discount_field', -1 );
}
add_action( 'init', 'my_edd_no_discount_code_on_checkout' );