Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
damiencarbery / how-not-to-use-wp-filter.php
Last active Sep 15, 2022
Use $wp_filter global to view functions attached to actions and filters
View how-not-to-use-wp-filter.php
<?php
/*
Plugin Name: wp_filter functions
Plugin URI: http://www.damiencarbery.com/2017/06/list-functions-attached-to-an-action/
Description: List functions attached to all actions and filters. DON'T DO IT!
Author: Damien Carbery
Version: 0.1
*/
add_action( 'wp_head', 'wp_filter_the_wrong_way' );
@damiencarbery
damiencarbery / delete-flamingo-data.php
Last active Sep 9, 2022
Delete Contact Form 7 Flamingo submissions - Easily delete a large number of Flamingo (Contact Form 7) messages. https://www.damiencarbery.com/2020/03/delete-contact-form-7-flamingo-submissions/
View delete-flamingo-data.php
<?php $time_start = microtime(true); ?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>Delete Flamingo messages and contacts</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1>Delete Flamingo messages and contacts</h1>
@damiencarbery
damiencarbery / cmb2-repeater-demo-display-data.php
Last active Sep 8, 2022
CMB2 Repeater Demo - a simple example
View cmb2-repeater-demo-display-data.php
<?php
add_filter( 'the_content', 'crd_append_post_links' );
function crd_append_post_links( $content ) {
if ( is_page() ) {
$post_links_data = get_post_meta( get_the_ID() );
if ( isset( $post_links_data[ 'blog_group' ][ 0 ] ) ) {
$blog_list = maybe_unserialize( $post_links_data[ 'blog_group' ][ 0 ] );
$posts_list = '<ul>';
foreach ( $blog_list as $post_info ) {
@damiencarbery
damiencarbery / cmb2-callback-front-page.php
Last active Sep 8, 2022
CMB2 only on front page - Use a custom 'show_on_cb' function to only show the CMB2 metabox when editing the front page. https://www.damiencarbery.com/2020/02/use-cmb2-on-front-page/
View cmb2-callback-front-page.php
<?php
function dcwd_show_cmb2_on_front_page( $cmb ) {
// Get ID of page set as front page, 0 if there isn't one
$front_page = get_option( 'page_on_front' );
// There is a front page set - are we editing it?
return $cmb->object_id() == $front_page;
}
@damiencarbery
damiencarbery / cmb2-add-book-info-fields.php
Last active Sep 8, 2022
Add custom product info to Additional Information tab - Use CMB2 to add a custom metabox to WooCommerce product then add data to Additional Information tab on product page. https://www.damiencarbery.com/2020/03/add-custom-product-info-to-additional-information-tab/
View cmb2-add-book-info-fields.php
<?php
/*
Plugin Name: Add custom product info to Additional Information tab
Plugin URI: https://www.damiencarbery.com/2020/03/add-custom-product-info-to-additional-information-tab/
Description: Use CMB2 to add a custom metabox to WooCommerce product then add data to Additional Information tab on product page.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.4
*/
@damiencarbery
damiencarbery / use-cmb2-block-delivery-dates.php
Last active Sep 8, 2022
Use CMB2 to block out dates in DatePicker - Create an options page with checkboxes to disable dates in DatePicker. https://www.damiencarbery.com/2020/04/use-cmb2-to-block-out-dates-in-datepicker/
View use-cmb2-block-delivery-dates.php
<?php
/*
Plugin Name: Use CMB2 to block out dates in DatePicker
Plugin URI: https://www.damiencarbery.com/2020/04/use-cmb2-to-block-out-dates-in-datepicker/
Description: Create an options page with checkboxes to disable dates in DatePicker.
Author: Damien Carbery
Version: 0.2
*/
@damiencarbery
damiencarbery / essence-pro-product-header-image-with-cmb2.php
Last active Sep 8, 2022
Use CMB2 to set product hero image in Essence Pro: Set header image on product & category pages to one set in CMB2 meta box or main product image - in Essence Pro theme. https://www.damiencarbery.com/2018/09/use-cmb2-to-set-product-hero-image-in-essence-pro/
View essence-pro-product-header-image-with-cmb2.php
<?php
/*
Plugin Name: Product Header Image for Essence Pro
Plugin URI: https://damiencarbery.com/2018/09/use-cmb2-to-set-product-hero-image-in-essence-pro/
Description: Set the header image to a product image in Essence Pro.
Author: Damien Carbery
Version: 0.6
*/
@damiencarbery
damiencarbery / course-dates-cmb2.php
Last active Sep 8, 2022
Order posts by post meta dates: Storing dates in post meta enables easy grouping of posts into current, future and past. This automatic grouping simplifies the client workflow and helps site visitors. https://www.damiencarbery.com/2018/12/order-posts-by-post-meta-dates/
View course-dates-cmb2.php
<?php
/*
Plugin Name: Order posts by post meta dates
Plugin URI: https://www.damiencarbery.com/2018/12/order-posts-by-post-meta-dates/
Description: Storing dates in post meta enables easy grouping of posts into current, future and past. This automatic grouping simplifies the client workflow and helps site visitors.
Author: Damien Carbery
Version: 0.2
*/
@damiencarbery
damiencarbery / amforanpr-cmb2.php
Last active Sep 6, 2022
CMB2 Options page to generate a list of services - Another example of using CMB2 repeater fields to replace ACF Pro repeater feature. https://www.damiencarbery.com/2019/04/cmb2-options-page-to-generate-a-list-of-services/
View amforanpr-cmb2.php
<?php
/*
Plugin Name: AMForanPR PR Services with CMB2
Plugin URI: http://www.damiencarbery.com
Description: Use CMB2 for the PR Services page.
Author: Damien Carbery
Version: 0.2
*/
add_action( 'cmb2_admin_init', 'dcwd_pr_services_options' );
@damiencarbery
damiencarbery / cmb2-options-page.php
Last active Sep 6, 2022
Use a CMB2 options page to populate Ninja Forms dropdown: Use an options page to create dynamic select options for a Ninja Forms. Easier for a client to manage. https://www.damiencarbery.com/2019/01/use-a-cmb2-options-page-to-populate-ninja-forms-dropdown/
View cmb2-options-page.php
<?php
/*
Plugin Name: CMB2 Options Page
Plugin URI: https://www.damiencarbery.com/2019/01/use-a-cmb2-options-page-to-populate-ninja-forms-dropdown/
Description: Use CMB2 to add an options page with repeater fields.
Author: Damien Carbery
Version: 0.2
*/
// Create an options page.