Skip to content

Instantly share code, notes, and snippets.

View JiveDig's full-sized avatar

Mike Hemberger JiveDig

View GitHub Profile
@JiveDig
JiveDig / class-woocommerce-account-tab.php
Last active April 23, 2024 14:24
A PHP class to create new WooCommerce account tabs.
<?php
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Mai_WooCommerce_Account_Tab' ) ):
/**
* A class to create new WooCommerce account tabs.
*
* @version 0.1.0
@JiveDig
JiveDig / class-cli-sitemap-importer.php
Created April 18, 2024 15:35
A PHP class for WordPress to import posts (or pages, cpt) as basic HTML, including importing images from content.
<?php
// Prevent direct file access.
defined( 'ABSPATH' ) || die;
/**
* WP-CLI to delete all content.
*
wp post delete $(wp post list --post_type=post --format=ids) --force
wp post delete $(wp post list --post_type=page --format=ids) --force
@JiveDig
JiveDig / class-user-role-base.php
Last active April 18, 2024 20:08
A PHP class for WordPress that allows you to change the author base by user role.
<?php
// Prevent direct file access.
defined( 'ABSPATH' ) || die;
if ( ! class_exists( 'Mai_User_Role_Base' ) ):
/**
* The User Role Base class.
*
* @version 0.1.0
@JiveDig
JiveDig / woocommerce-permalink-silos.php
Last active July 27, 2023 14:47
Create hierarchical permalink SEO silos for WooCommerce shop/products, product categories, and single product urls.
@JiveDig
JiveDig / on-demand-block-assets.php
Last active August 31, 2022 20:47
Testing loading block assets (scripts and styles) on demand, before the block markup.
<?php
add_action( 'enqueue_block_editor_assets', 'mai_enqueue_block_editor_assets' );
/**
* Enqueues block assets for the editor,
* since front-end assets are loaded on-demand.
*
* @since TBD
*
* @return void
@JiveDig
JiveDig / functions.php
Last active August 19, 2022 16:25
Gets a formatted array of block data from post content for use in the `template` parameter of `register_post_type()` function. This is used for a predefined block template for a post type.
<?php
/**
* Dump the data.
*/
add_action( 'wp_footer', function() {
// Get the data.
$parsed = jivedig_get_parsed_blocks_for_template();
// Dump however you'd like.
<!-- wp:acf/mai-columns {"name":"acf/mai-columns","data":{"columns":"custom","_columns":"mai_columns_columns","arrangement_0_columns":"1/2","_arrangement_0_columns":"mai_columns_arrangement_columns","arrangement":1,"_arrangement":"mai_columns_arrangement","arrangement_md_0_columns":"full","_arrangement_md_0_columns":"mai_columns_md_arrangement_columns","arrangement_md":1,"_arrangement_md":"mai_columns_md_arrangement","arrangement_sm_0_columns":"full","_arrangement_sm_0_columns":"mai_columns_sm_arrangement_columns","arrangement_sm":1,"_arrangement_sm":"mai_columns_sm_arrangement","arrangement_xs_0_columns":"full","_arrangement_xs_0_columns":"mai_columns_xs_arrangement_columns","arrangement_xs":1,"_arrangement_xs":"mai_columns_xs_arrangement","align_columns":"start","_align_columns":"mai_columns_align_columns","align_columns_vertical":"","_align_columns_vertical":"mai_columns_align_columns_vertical","column_gap":"","_column_gap":"mai_columns_column_gap","row_gap":"","_row_gap":"mai_columns_row_gap","margin_top"
@JiveDig
JiveDig / mai-banner-to-page-header.php
Last active January 27, 2022 20:14
Convert Mai Theme v1 banner images to v2 page header images.
<?php
/**
* Migrates post and term meta keys from Mai Theme v1 to v2.
*
* 1. Add this code to functions.php
* 2. Visit the front end of the website ONE time.
* 3. This code will run just by visiting the page.
* 4. Each page view or refresh will make it run again so don't do it more than once.
* 5. Immediate remove this code.
@JiveDig
JiveDig / woocommerce-remove-scripts-styles.php
Last active March 22, 2021 11:15
Remove WooCommerce scripts and styles.
<?php
/**
* Remove WooCommerce scripts and styles.
*
* Cart fragments are used for things like ajax cart menu icons,
* but it's really slow, so let's only keep them where necessary.
*
* @version 1.3.0
* @author Mike Hemberger @JiveDig
@JiveDig
JiveDig / functions.php
Created August 8, 2019 19:14
Automatically add facet label as a heading before any facets with available options to filter by.
<?php
/**
* Adds facet label as a heading before any facets with available options.
*
* @author Mike Hemberger @JiveDig.
*
* @param string $output The facet HTML.
* @param array $params The shortcode/function parameters.
*