Skip to content

Instantly share code, notes, and snippets.

👨‍👦
I'd have more time for coding if I wasn't a parent!

Cameron Jones cameronjonesweb

👨‍👦
I'd have more time for coding if I wasn't a parent!
Block or report user

Report or block cameronjonesweb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cameronjonesweb
cameronjonesweb / functions.php
Last active Aug 27, 2019
Helper function to generate post type labels
View functions.php
<?php
/**
* Generates the post type labels
*
* @param string $single Singular name of the post type.
* @param string $plural Plural name of the post type.
* @param array $overrides Override any generated labels.
* @return array The post type labels
*/
function cameronjonesweb_generate_post_type_labels( $single, $plural, $overrides = [] ) {
@cameronjonesweb
cameronjonesweb / taxonomy-radio-buttons.php
Created Jul 20, 2019
Converts the category checkboxes to radio buttons
View taxonomy-radio-buttons.php
<?php
function cameronjonesweb_radio_taxonomy_meta_box( $post, $box ) {
ob_start();
post_categories_meta_box( $post, $box );
$meta_box = ob_get_clean();
echo str_replace( 'checkbox', 'radio', $meta_box );
}
@cameronjonesweb
cameronjonesweb / functions.php
Created May 30, 2019
Preserve taxonomy heirarchy on edit post page
View functions.php
<?php
add_filter('wp_terms_checklist_args', function ($args){
$args['checked_ontop'] = false;
return $args;
});
@cameronjonesweb
cameronjonesweb / default.css
Created May 10, 2019
Comment parsing proof of concept
View default.css
/*
Skin Name: Default
Author: Cameron Jones
Author URI: https://cameronjonesweb.com.au
*/
@cameronjonesweb
cameronjonesweb / examples.php
Created Jan 29, 2019
Generate a style tag based on an associative array of styles
View examples.php
<?php
$styles = [
'color' => '#f00',
'background' => '#fff',
];
cameronjonesweb_generate_style_attribute( $styles );
@cameronjonesweb
cameronjonesweb / functions.php
Created Jan 28, 2019
Removes buttons from WooCommerce notices
View functions.php
<?php
add_action( 'init', 'cameronjonesweb_remove_button_from_notice_setup' );
function cameronjonesweb_remove_button_from_notice( $message ) {
$message = preg_replace('#<(a)(?:[^>]+)?>.*?</\1>#s', '', $message );
return $message;
}
function cameronjonesweb_remove_button_from_notice_setup() {
$notice_types = apply_filters( 'woocommerce_notice_types', [ 'error', 'success', 'notice' ] );
@cameronjonesweb
cameronjonesweb / examples.php
Last active Jan 21, 2019
Accurately check if a string contains a phrase
View examples.php
<?php
$string = 'Hello world!';
$phrase = 'He';
if ( strpos( $string, $phrase ) ) {
// This code won't run.
}
if ( cameronjonesweb_string_contains_phrase( $string, $phrase ) ) {
// This code will run.
@cameronjonesweb
cameronjonesweb / custom.sublime-keymap
Last active Jan 1, 2019
My personal sublime text key mappings
View custom.sublime-keymap
[
{ "keys": ["ctrl+shift+o"], "command": "prompt_open_folder" },
{ "keys": ["ctrl+pagedown"], "command": "next_view_in_stack" },
{ "keys": ["ctrl+pageup"], "command": "prev_view_in_stack" },
{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
{ "keys": ["alt+`"], "command": "toggle_terminus_panel" }
@cameronjonesweb
cameronjonesweb / clamp-js-recursive.js
Created Dec 18, 2018
Clamps all instances of a class
View clamp-js-recursive.js
jQuery( document ).ready( function() {
jQuery( '.clampThis' ).each( function( index, element ) {
$clamp(
element,
{
clamp: 1,
useNativeClamp: false
}
);
});
@cameronjonesweb
cameronjonesweb / fix-vide-js-safari.js
Created Nov 30, 2018
Fixes Vide.js videos not autoplaying on Safari
View fix-vide-js-safari.js
/**
* @link https://github.com/vodkabears/Vide/issues/206
*/
function cameronjoneswebAutoPlayVideo( video ) {
if ( video.readyState === 4 ) {
video.play();
} else {
setTimeout( cameronjoneswebAutoPlayVideo, 100, video );
}
}
You can’t perform that action at this time.