Skip to content

Instantly share code, notes, and snippets.

View cameronjonesweb's full-sized avatar
👨‍👦

Cameron Jones cameronjonesweb

👨‍👦
View GitHub Profile
@cameronjonesweb
cameronjonesweb / round-gravity-forms-currency.php
Created November 25, 2019 22:47
Round currency fields with Gravity Forms
add_filter( 'gform_currencies', 'cameronjonesweb_round_gravity_forms_currencies' );
function cameronjonesweb_round_gravity_forms_currencies( $currencies ) {
foreach ( $currencies as $key => $val ) {
$currencies[ $key ]['decimals'] = 0;
}
return $currencies;
}
<?php
add_action( 'init', 'rewrites' );
add_filter( 'post_type_link', 'filter_post_link', 1, 2 );
function rewrites() {
add_rewrite_tag( '%artist%', '([^/]+)' );
add_rewrite_rule(
'songs/([^/]+)/([^/]+)?$',
'index.php?artist=$matches[1]&songs=$matches[2]',
'top'
@cameronjonesweb
cameronjonesweb / resume.json
Last active November 6, 2019 03:21
JSON Resume
{
"basics": {
"name": "Cameron Jones",
"label": "WordPress Developer",
"picture": "https://secure.gravatar.com/avatar/95d0c3a6511821a3f93807930a329cbb",
"email": "cameron@cameronjonesweb.com.au",
"phone": "0428 785 391",
"website": "https://cameronjonesweb.com.au",
"summary": "",
"location": {
@cameronjonesweb
cameronjonesweb / functions.php
Last active October 7, 2020 23:41
Helper function to generate post type labels
<?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 July 20, 2019 16:18
Converts the category checkboxes to radio buttons
<?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 23:14
Preserve taxonomy heirarchy on edit post page
<?php
add_filter('wp_terms_checklist_args', function ($args){
$args['checked_ontop'] = false;
return $args;
});
@cameronjonesweb
cameronjonesweb / default.css
Created May 10, 2019 03:41
Comment parsing proof of concept
/*
Skin Name: Default
Author: Cameron Jones
Author URI: https://cameronjonesweb.com.au
*/
@cameronjonesweb
cameronjonesweb / examples.php
Created January 29, 2019 06:05
Generate a style tag based on an associative array of styles
<?php
$styles = [
'color' => '#f00',
'background' => '#fff',
];
cameronjonesweb_generate_style_attribute( $styles );
@cameronjonesweb
cameronjonesweb / functions.php
Created January 28, 2019 11:23
Removes buttons from WooCommerce notices
<?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 January 21, 2019 05:35
Accurately check if a string contains a phrase
<?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.