Skip to content

Instantly share code, notes, and snippets.

View kimcoleman's full-sized avatar

Kim Coleman kimcoleman

View GitHub Profile
@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' );
@kimcoleman
kimcoleman / my_woocommerce_coupons_enabled.php
Created June 23, 2022 11:10
Hide the Coupon field on WooCommerce cart page.
<?php
/**
* Hide the Coupon field on WooCommerce cart page.
*/
function my_woocommerce_coupons_enabled( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
@kimcoleman
kimcoleman / my_woocommerce_apply_cart_coupon_in_url.php
Created June 23, 2022 11:10
Apply a WooCommerce discount code to cart via URL parameter.
<?php
/**
* Apply a WooCommerce discount code to cart via URL parameter.
* This code is adapted from: https://www.webroomtech.com/apply-coupon-via-url-in-woocommerce/
*/
function my_woocommerce_apply_cart_coupon_in_url() {
// Return early if WooCommerce or sessions aren't available.
if ( ! function_exists( 'WC' ) || ! WC()->session ) {
return;
}
@kimcoleman
kimcoleman / my_reusable_blocks_admin_menu.php
Created June 16, 2022 10:32
Add an admin menu link for Reusable Blocks
<?php
/**
* Add an admin menu link for Reusable Blocks
*/
function my_reusable_blocks_admin_menu() {
add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'my_reusable_blocks_admin_menu' );