Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
@cameronjonesweb
cameronjonesweb / custom-admin-dashboard.php
Created October 3, 2023 03:41
Wipe the WordPress admin dashboard and replace with your own custom template
<?php
add_action(
'all_admin_notices',
function() {
$screen = get_current_screen();
if ( 'dashboard' === $screen->base ) {
/* Your code goes here */
ob_start();
}
},
@cameronjonesweb
cameronjonesweb / adding-a-variation-that-doesnt-work.js
Last active August 6, 2024 22:16
The painful efforts of adding a custom icon to the social links block
import { Path, SVG } from '@wordpress/primitives';
export const PlayHqIcon = () => (
<SVG width="24" height="24" viewBox="0 0 24 24" version="1.1">
<Path fill="#4897D2" d="M23.3,5.4l-0.1,0.8C16.7,2.5,8.8,2.2,2,5.4v0c2.9-2.1,6.2-3.5,9.7-4.1c0.3-0.1,0.6-0.1,0.9-0.1 c3.6-0.5,7.3-0.1,10.8,1.1C23.4,3.3,23.4,4.3,23.3,5.4L23.3,5.4z"/>
<Path fill="#9057A3" d="M2,5.4C2,5.4,2,5.4,2,5.4C2,5.5,2,5.4,2,5.4L2,5.4z"/>
<Path fill="#9057A3" d="M12.6,1.1c-0.3,0-0.6,0.1-0.9,0.1C8.2,1.9,4.9,3.3,2,5.4C1.9,4.3,1.9,3.3,2,2.2C5.4,1,9,0.7,12.6,1.1z"/>
<Path d="M11.9,3.2C8.5,3.2,5.1,4,2,5.4c0,0-0.1,0-0.1,0C1.5,5.7,1,5.9,0.6,6.2c0.4,3.1,1.4,6.1,3,8.8l1-8.2 c0,0,0-0.1,0.1-0.1s0.1-0.1,0.1-0.1h2c0.1,0,0.2,0.1,0.2,0.2l-0.5,3.7c0,0,0,0.1,0.1,0.1h2.6c0,0,0,0,0.1,0c0,0,0,0,0-0.1l0.5-3.7 c0,0,0-0.1,0.1-0.1c0,0,0.1-0.1,0.1-0.1h2c0,0,0.1,0,0.1,0.1c0,0,0,0.1,0,0.1l-1.2,9.6c0,0,0,0.1-0.1,0.1c0,0-0.1,0.1-0.1,0.1h-2 c0,0-0.1,0-0.1-0.1c0,0,0-0.1,0-0.1l0.5-3.8c0,0,0-0.1-0.1-0.1H6.3c0,0-0.1,0-0.1,0.1l-0.6,5.1c1.8,2.2,3.9,4,6.3,5.4 c2.6-1.5,5-
@cameronjonesweb
cameronjonesweb / functions.php
Created September 21, 2022 08:46
Bootstrapify `the_posts_pagination()`
<?php
/**
* Update `the_posts_pagination()` markup for Bootstrap 4 styles
*
* Does this monstrosity work? Yes! Should you use it? Probably not.
*
* @param $markup string Original markup.
* @return string Updated markup.
*/
function cameronjonesweb_bootstrapify_posts_pagination( $markup ) {
@cameronjonesweb
cameronjonesweb / add-location-class-to-menus.php
Created May 26, 2022 11:32
Add a location class to WordPress menus
<?php
/**
* Add a class with the menu location to the WordPress menu wrapper
*
* @param array $args Menu arguments.
* @return array
*/
function cameronjonesweb_add_location_class_to_menus( $args ) {
if ( ! empty( $args['theme_location'] ) ) {
$args['items_wrap'] = str_replace( '%2$s', '%2$s menu--' . sanitize_html_class( $args['theme_location'] ), $args['items_wrap'] );
@cameronjonesweb
cameronjonesweb / demos.php
Created March 18, 2022 06:13
Inject an element into an array at a specific position
<?php
/* Returns:
array(5) {
["red"]=>
string(3) "Red"
["green"]=>
string(5) "Green"
["purple"]=>
string(6) "Purple"
["blue"]=>
<?php
add_filter( 'user_contactmethods', 'add_kofi_user_contactmehod' );
function add_kofi_user_contactmehod( $methods ) {
$methods['kofi'] = 'Ko-fi Username';
return $methods;
}
function create_kofi_button_from_user_meta() {
$kofi = get_the_author_meta( 'kofi', get_the_author_ID() );
@cameronjonesweb
cameronjonesweb / get-excerpt-by-id.php
Created October 23, 2021 00:38
Get the excerpt of a post by ID, and generate one if not set manually
<?php
/**
* Get the excerpt of a post by it's ID
*
* @param int $post_id Post ID.
* @return string
*/
function cameronjonesweb_get_excerpt_by_id( $post_id ) {
return apply_filters( 'get_the_excerpt', wp_trim_excerpt( get_post_field( 'post_excerpt', $post_id ), $post_id ), $post_id );
}
@cameronjonesweb
cameronjonesweb / php.ini.hbs
Created September 13, 2021 11:40
Prevent var_dump being truncated using Local by Flywheel
xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
@cameronjonesweb
cameronjonesweb / cameronjonesweb-create-admin.php
Last active July 5, 2021 06:17
Automatically create admin user
<?php
/**
* Create an admin user
*/
function cameronjonesweb_create_admin_user() {
$username = 'username';
$password = 'password';
$email = 'email@example.com';
if ( ! username_exists( $username ) && ! email_exists( $email ) ) {
<?php
/**
* Add the custom column to the exporter and the exporter column menu.
*
* @link https://github.com/woocommerce/woocommerce/wiki/Product-CSV-Importer-&-Exporter#adding-custom-export-columns-developers
*
* @param array $columns.
* @return array $columns.
*/
function cameronjonesweb_add_export_columns( $columns ) {