Skip to content

Instantly share code, notes, and snippets.

View jondcampbell's full-sized avatar

Jon Campbell jondcampbell

View GitHub Profile
@jondcampbell
jondcampbell / functions.php
Created December 22, 2016 19:20
messy mobile menu combo
function dpcc_add_slide_out_left_navigation(){
ob_start();
?>
<div id="left-nav">
<?php if ( is_user_logged_in() ) { ?>
<div class="dpcc-more-slide-out-left-menu">
<?php wp_nav_menu( array( 'theme_location' => 'secondary' ) ); ?>
@jondcampbell
jondcampbell / class.php
Last active December 13, 2016 22:35
dont use this, scratch example
// The Field
$this->cmb_resource_form->add_field( array(
'name' => 'Seasons',
'desc' => '',
'id' => $this->cmb_prefix . 'seasons',
'taxonomy' => 'season', //Enter Taxonomy Slug
'type' => 'taxonomy_multicheck',
// Optional:
'options' => array(
'no_terms_text' => 'Sorry, no seasons could be found.' // Change default text. Default: "No terms"
@jondcampbell
jondcampbell / functions.php
Created July 15, 2016 18:56
updating data on wp all import save
add_action( 'pmxi_saved_post', 'sgc_post_saved', 10, 1 );
function sgc_post_saved( $post_id ) {
// We only want to run this on import of course members
if ( 'course-members' === get_post_type( $post_id ) ) :
// Perform proper date formatting on our date of birth field, and passport dates
update_date_value_of_post( $post_id, 'personal_date_of_birth' );
update_date_value_of_post( $post_id, 'travel_passport_date_of_issue' );
@jondcampbell
jondcampbell / template.php
Created February 16, 2016 18:48
check if an acf link field value is for our current site or an external link
<?php
$our_parsed_url = parse_url( site_url() );
$link_parsed_url = parse_url( get_sub_field( 'link' ) );
if ( $our_parsed_url['host'] === $link_parsed_url['host'] ) :
$external_link = false;
else :
$external_link = true;
endif;
?>
@jondcampbell
jondcampbell / cmb2setup.php
Created January 4, 2016 23:01
CMB2 File List: Don't show media from other posts. The key is the query_args that tell the media uploader to only show the resources uploaded to post 99999999999 (which I hope never exists).
$this->cmb_form->add_field( array(
'name' => 'Resource File List',
'desc' => '',
'id' => $this->cmb_prefix . 'resource_files',
'type' => 'file_list',
// 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 )
'attributes' => array(
'required' => true, // Will be required only if visible.
'data-conditional-id' => $this->cmb_prefix . 'resource_type',
'data-conditional-value' => 'files',
@jondcampbell
jondcampbell / controller.php
Created October 9, 2015 23:08
query a prices table, finding me the companies with the most products. uses laravel and db query builder. grouping and ordering
$companies = DB::table('prices')
->select(DB::raw('company_id, COUNT(*) as total_products'))
->groupBy('company_id')
->orderBy('total_products', 'desc')
->get();
@jondcampbell
jondcampbell / functions.php
Last active January 31, 2016 23:55
Theme my login replacement variables filter. Used to add your own variables to the Custom Emails module of theme my login. Uses tml_replace_vars.
function custom_email_replace($old_replacements, $user_id){
// Generate the new url we need for this user
$enrollment_form_url = 'special-url-'.$user_id;
// An array of our replacement variables and their values
$new_replacements = array(
'%enrollmentform%'=> $enrollment_form_url,
);
// Merge our two arrays together
@jondcampbell
jondcampbell / template.php
Created May 29, 2015 18:57
get the label of ACF select field instead of value
echo get_field_object( 'select_field' )['choices'][ get_field( 'select_field' ) ];
@jondcampbell
jondcampbell / functions.php
Created May 26, 2015 23:03
Find all woocommerce orders that have a particular product_id in it. Returns an array of order ids.
global $wpdb;
$sql = "SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id IN ( SELECT order_item_id FROM {$wpdb->prefix}woocommerce_order_itemmeta WHERE meta_key = '_product_id' AND meta_value = $product_id ) AND order_item_type = 'line_item'";
$order_ids = $wpdb->get_col( $sql );
@jondcampbell
jondcampbell / functions.php
Created April 29, 2015 22:19
disable the billing fields at woocommerce checkout. sadly it doesnt add to your custom attributes, it just replaces them with disabled.
function custom_disable_woocommerce_billing_checkout_fields( $fields ) {
foreach ($fields['billing'] as $key => $billing_field){
$fields['billing'][$key]['custom_attributes'] = array('disabled' => 'disabled') ;
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'custom_disable_woocommerce_billing_checkout_fields' );