Skip to content

Instantly share code, notes, and snippets.

View jdhobbsuk's full-sized avatar

Jason Hobbs jdhobbsuk

View GitHub Profile
@jdhobbsuk
jdhobbsuk / WordPress Shortcode: Video
Last active August 29, 2015 13:57
YouTube / Vimeo shortcode for WordPress
// Video Shortcode
// -------------------------------------------------------------
function my_shortcode_video( $atts, $content = null ) {
// extract and set defaults
extract( shortcode_atts( array(
'url' => '',
'autoplay' => 'false',
'image' => 'false'
), $atts ) );
@jdhobbsuk
jdhobbsuk / WordPress Future Events
Last active August 29, 2015 13:57
WP_Query tweak for future events (eg. Events)
// the rest of your $args array
$now = date('Ymd');
$date_key = 'date';
$args['meta_query'] = array(
array(
'key' => $date_key,
'value' => $now,
'compare' => '>=',
),
@jdhobbsuk
jdhobbsuk / is-child-term.php
Created May 6, 2014 09:43
is_child_term()
// is_child_term()
// -------------------------------------------------------------
function is_child_term($taxonomy, $parent_id){
$child_terms = get_term_children( $parent_id, $taxonomy );
$response = false;
foreach ( $child_terms as $term ):
if(is_tax($taxonomy, $term)):
$response = true;
endif;
@jdhobbsuk
jdhobbsuk / WordPress Create Past & Future filters
Last active August 29, 2015 14:07
Filter and order a custom post type by a meta_key, like events by past and future date
// Set Events to date order (in admin), either future or past
// -------------------------------------------------------------
function set_events_admin_order($wp_query) {
if (is_admin()) :
$post_type_req = 'events'; // change this
$filter_by = 'event_date'; // change this
$now = date('Ymd');
@jdhobbsuk
jdhobbsuk / WordPress Shortcode: Blockquote
Last active August 29, 2015 14:17
blockquote-shortcode.php
// Blockquote
// -------------------------------------------------------------
function my_shortcode_blockquote( $atts, $content ) {
// extract and set defaults
extract( shortcode_atts( array(
'line1' => '',
'line2' => ''
), $atts ) );
$output_string = '<blockquote>';
@jdhobbsuk
jdhobbsuk / helper-functions.php
Created April 17, 2015 14:21
WordPress Get current user's role
function get_current_user_role(){
if( is_user_logged_in() ):
global $current_user;
$user_role = $current_user->roles[0];
return $user_role;
else:
return FALSE;
endif;
}
@jdhobbsuk
jdhobbsuk / acf-settings.php
Last active April 29, 2016 22:40
ACF: Filter Post Object by posts owned by current author
function filter_acf_selection_by_ownership( $args, $field, $post ) {
$user = get_current_user_id();
if(get_current_user_role() != 'administrator' || get_current_user_role() != 'editor'):
$args['author'] = $user;
endif;
return $args;
@jdhobbsuk
jdhobbsuk / General
Created April 28, 2015 15:56
Ghost Referral Spam
free-share-buttons|simple-share-buttons|Get-Free-Traffic-Now|buy-cheap-online|googlsucks|theguardlan|hulfingtonpost|darodar
@jdhobbsuk
jdhobbsuk / admin-cpt-filter.php
Last active August 29, 2015 14:22
Filter CPT by
// Add Hospital filter to CPTs (in admin)
// -------------------------------------------------------------
function restrict_people_by_hospital() {
global $typenow;
$taxonomy = 'hospital';
if ($typenow == 'consultant') {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("All {$info_taxonomy->label}s"),
@jdhobbsuk
jdhobbsuk / remove-pagination.php
Last active October 16, 2015 16:15
Remove pagination from post types (in admin)
// Force CPTs to have no pagination
// -------------------------------------------------------------
if ( is_admin() ) :
function force_no_admin_pagination() {
// get all post types (excluding posts)
$post_types = get_post_types();
unset($post_types['post']);
// get all users