Skip to content

Instantly share code, notes, and snippets.

View hlashbrooke's full-sized avatar
🎲

Hugh Lashbrooke hlashbrooke

🎲
View GitHub Profile
@hlashbrooke
hlashbrooke / filter.php
Created February 19, 2014 14:05
Sensei - Set a custom image size for a question image
<?php
add_filter( 'sensei_question_image_size', 'custom_sensei_question_image_size', 10, 2 );
function custom_sensei_question_image_size( $size, $question_id ) {
$size = 'large';
return $size;
}
?>
@hlashbrooke
hlashbrooke / function.php
Last active August 29, 2015 13:56
Sensei - Check if a lesson has a quiz
<?php
/**
* Check if a lesson contains a quiz
*
* @param integer $lesson_id ID of lesson
* @return boolean True if lesson contains a quiz, false if not
*/
if( ! function_exists( 'sensei_lesson_has_quiz' ) ) {
function sensei_lesson_has_quiz( $lesson_id = 0 ) {
@hlashbrooke
hlashbrooke / function.php
Last active October 3, 2019 14:52
Sensei - Remove user from course
<?php
function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
global $woothemes_sensei;
$course_id = intval( $course_id );
$user_id = intval( $user_id );
if( $course_id > 0 && $user_id > 0 ) {
// Get all course lessons
@hlashbrooke
hlashbrooke / function.php
Created August 24, 2013 17:12
Make your WordPress content editor use HTML by default - this example will ensure that only non-admin users see the HTML editor by default.
<?php
add_filter( 'wp_default_editor', 'set_html_content_editor' );
function set_html_content_editor( $tab ) {
if( ! current_user_can( 'administrator' ) ) {
$tab = 'html';
}
return $tab;
}
?>
@hlashbrooke
hlashbrooke / function.php
Last active December 21, 2015 13:49
WooThemes Testimonials: Modify content to use testimonial excerpt
<?php
add_filter( 'woothemes_testimonials_content', 'custom_testimonials_content', 10, 2 );
function custom_testimonials_content( $content, $post ) {
$content = $post->post_excerpt;
return $content;
}
?>
@hlashbrooke
hlashbrooke / function.php
Last active July 4, 2022 21:35
WordPress: Display posts in a random order, but retain persistent pagination
<?php
session_start();
add_filter( 'posts_orderby', 'randomise_with_pagination' );
function randomise_with_pagination( $orderby ) {
if( is_front_page() ) {
// Reset seed on load of initial archive page
@hlashbrooke
hlashbrooke / function.php
Created August 21, 2013 11:01
WooCommerce: Get all order statuses as an array
<?php
function woocommerce_get_order_statuses() {
$order_statuses = get_terms( 'shop_order_status', array( 'hide_empty' => false ) );
$statuses = array();
foreach ( $order_statuses as $status ) {
$statuses[ $status->slug ] = $status->name;
}
return $statuses;
}
?>
@hlashbrooke
hlashbrooke / analytics-wordpress.php
Created August 9, 2013 16:26
Segment.io WordPress plugin: Adding filter to identification traits
<?php
$identify = array(
'user_id' => $user->user_email,
'traits' => apply_filters( 'segment_identify_traits', array(
'username' => $user->user_login,
'email' => $user->user_email,
'name' => $user->display_name,
'firstName' => $user->user_firstname,
'lastName' => $user->user_lastname,
'url' => $user->user_url
@hlashbrooke
hlashbrooke / style.css
Created August 7, 2013 06:15
WooCommerce Email Validation: Fix field layout when field appears on the right
#billing_email-2_field { float: right; }
@hlashbrooke
hlashbrooke / class1.php
Last active May 26, 2020 01:03
WordPress: Use checkbox term selection for non-hierarchical taxonomies - http://www.hughlashbrooke.com/wordpress-use-checkbox-term-selection-for-non-hierarchical-taxonomies/
<?php
class Tag_Checklist {
private $taxonomy;
private $post_type;
function __construct( $taxonomy, $post_type ) {
$this->taxonomy = $taxonomy;
$this->post_type = $post_type;