Skip to content

Instantly share code, notes, and snippets.

View richerimage's full-sized avatar

Richard Barratt richerimage

View GitHub Profile
// Utility function to change the prices with a multiplier (number)
function get_price_multiplier() {
$prod_id = get_the_ID();
$brand = 'acme';
if ( (is_user_logged_in()) && ($brand == 'acme') ) {
return 0.8; // 20% off
} else {
@richerimage
richerimage / pretty_dumps.php
Created December 30, 2018 22:03
Pretty print_r dumps
$dump = what_I_want_to_dump();
print("<pre>".print_r($dump,true)."</pre>");
@richerimage
richerimage / facet-test.php
Created November 27, 2018 17:06
Facet Test
<?php
add_action( 'wp_head', 'cvl_add_facetwp_fwp_http', 100 );
function cvl_add_facetwp_fwp_http() {
if (is_singular('job_listing')) {
global $post; ?>
@richerimage
richerimage / cvl-facetwp.php
Last active November 26, 2018 21:27
cvl-facet-functions.php
<?php
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
$parent = get_the_ID();
if ( 'example' == $class->ajax_params['template'] ) {
$query_args['post_parent'] = $parent;
$query_args['post_type'] = 'job_application';
$query_args['post_status'] = 'published';
@richerimage
richerimage / wp_query.php
Last active November 19, 2018 16:51
WP Query Magic
<?php
$args = array(
// Arguments for your query.
);
// Custom query.
$query = new WP_Query( $args );
add_filter('login_redirect', 'admin_login_redirect', 10, 3);
function admin_login_redirect( $redirect_to, $request, $user ) {
global $user;
if( isset( $user->roles ) && is_array( $user->roles ) ) {
if( in_array( 'administrator', $user->roles ) ) {
@richerimage
richerimage / Gravity Form - Display list of Users as a dropdown.php
Created May 14, 2018 12:08
Gravity Form - Display list of Users as a dropdown (User ID is the value)
add_filter( 'gform_pre_render_FORM_ID', 'dna_user_list_dropdown' );
add_filter( 'gform_pre_validation_FORM_ID', 'dna_user_list_dropdown' );
add_filter( 'gform_pre_submission_filter_FORM_ID', 'dna_user_list_dropdown' );
add_filter( 'gform_admin_pre_render_FORM_ID', 'dna_user_list_dropdown' );
function dna_user_list_dropdown( $form ) {
foreach ( $form['fields'] as &$field ) {
@richerimage
richerimage / wp_disable_admin_bar.php
Created January 22, 2018 12:37
Disable Wordpress Admin Bar
/*
* Source
* https://code.tutsplus.com/articles/how-to-disable-the-admin-bar-in-wordpress-33--wp-23361
*/
if (!function_exists('disableAdminBar')) {
function disableAdminBar(){
@richerimage
richerimage / css-for-all-except-last-child.css
Created September 4, 2017 09:07
CSS select all except last child
.selector:not(:last-child) {
/* styles for everything except last item */
}
@richerimage
richerimage / supress_metabox_display.php
Created July 11, 2016 06:05
CHANGE THE DEFAULTS WITH THE DEFAULT_HIDDEN_META_BOXES HOOK
<?php
/**
* vpm_default_hidden_meta_boxes
* Source: https://www.vanpattenmedia.com/2014/code-snippet-hide-post-meta-boxes-wordpress
*/
function vpm_default_hidden_meta_boxes( $hidden, $screen ) {
// Grab the current post type
$post_type = $screen->post_type;
// If we're on a 'post'...
if ( $post_type == 'post' ) {