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

View GitHub Profile
@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 );
}
}
@cameronjonesweb
cameronjonesweb / jetpack-cookie-widget-without-widget-areas.php
Last active Nov 18, 2018
Display Jetpack's cookie notice on themes without a widget area
View jetpack-cookie-widget-without-widget-areas.php
@cameronjonesweb
cameronjonesweb / class-att-example.php
Created Nov 14, 2018
Generate a class attribute from an array of classes and sanitises the classes
View class-att-example.php
<?php
// Example.
$myclasses = [ 'my-class', 'some-other-class', '<script>console.log(hi);</script>' ];
printf(
'<div %1$s>%2$s</div>',
cameronjonesweb_generate_class_attribute( $myclasses ),
'My content'
);
@cameronjonesweb
cameronjonesweb / functions.php
Last active Nov 1, 2018
Takes custom classes out of the list item and adds them to the anchor element in WordPress menus. Perfect for font icons
View functions.php
<?php
add_filter( 'nav_menu_link_attributes','cameronjonesweb_move_custom_menu_item_class_to_anchor_element', 10, 4 );
add_filter( 'nav_menu_css_class', 'cameronjonesweb_remove_custom_menu_item_class_from_li_element', 10, 4 );
/**
* Get the custom item menu classes and add them to the anchor element
*
* @link https://cameronjonesweb.com.au
* @param array $atts The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
@cameronjonesweb
cameronjonesweb / remove-current-page-parent.php
Created Oct 24, 2018
Removes the `current_page_parent` class from the blog page link when not viewing a blog related page
View remove-current-page-parent.php
<?php
/**
* Removes the `current_page_parent` class from the blog page link when not viewing a blog related page
*
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
* @param WP_Post $item The current menu item.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
function cameronjonesweb_remove_current_page_parent( $classes, $item, $args, $depth ) {
You can’t perform that action at this time.