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!
View GitHub Profile
View wrap-classic-block.php
<?php
function cameronjonesweb_wrap_classic_posts( $block_content, $block ) {
if ( is_null( $block['blockName'] ) && ! empty( trim( $block_content ) ) ) {
$output = '<div class="classic-block">';
$output .= $block_content;
$output .= '</div>';
$block_content = $output;
}
return $block_content;
}
View automatically-enqueue-block-stylesheet.php
<?php
add_filter( 'acf/register_block_type_args', 'cameronjonesweb_automatically_enqueue_block_stylesheet' );
function cameronjonesweb_automatically_enqueue_block_stylesheet( $args ) {
if ( empty( $args['enqueue_style'] ) ) {
$file = get_template_directory_uri() . '/blocks/' . ltrim( $args['name'], 'acf/' ) . '/block.css';
if ( file_exists( str_replace( get_template_directory_uri(), get_template_directory(), $file ) ) ) {
$args['enqueue_style'] = $file;
}
}
@cameronjonesweb
cameronjonesweb / media.js
Created Apr 25, 2020
Upload media to a custom input in the WordPress admin
View media.js
jQuery(document).ready(function($){
var custom_uploader;
var $btn;
$('.image_upload_button').click(function(e) {
@cameronjonesweb
cameronjonesweb / generate-edd-api-keys.php
Last active Feb 19, 2020
Automatically generate EDD API keys for each user
View generate-edd-api-keys.php
<?php
$user_id = 1;
$edd_api = new EDD_API();
$public_key = $edd_api->get_user_public_key( $user_id );
if ( empty( $public_key ) ) {
$edd_api->generate_api_key( $user_id );
}
@cameronjonesweb
cameronjonesweb / gform-field-content-filter.php
Created Feb 16, 2020
Render the_content in a gravity forms field
View gform-field-content-filter.php
<?php
$form_id = 1;
$field_id = 1;
add_filter( "gform_field_content_{$form_id}_{$field_id}", 'gfield_render_the_content', 10, 5 );
function gfield_render_the_content( $content, $field, $value, $lead_id, $form_id ) {
$content = apply_filters( 'the_content', get_the_content() );
return $content;
}
@cameronjonesweb
cameronjonesweb / round-gravity-forms-currency.php
Created Nov 25, 2019
Round currency fields with Gravity Forms
View round-gravity-forms-currency.php
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;
}
View cpt-rewrites.php
<?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'
View resume.json
{
"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 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 );
}
You can’t perform that action at this time.