Skip to content

Instantly share code, notes, and snippets.

Avatar

Hugh Lashbrooke hlashbrooke

View GitHub Profile
@hlashbrooke
hlashbrooke / function.php
Last active August 29, 2015 13:56
Sensei - Check if a lesson has a quiz
View function.php
<?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 / filter.php
Created February 19, 2014 14:05
Sensei - Set a custom image size for a question image
View filter.php
<?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
Created April 9, 2014 07:58
Sensei: Reset all user activity (for all users or specified user)
View function.php
<?php
function sensei_reset_activity( $user_id = 0 ) {
// Get all Sensei activities
$token = 'sensei_';
$activities = array( 'course_start', 'course_end', 'lesson_start', 'lesson_end', 'quiz_grade', 'quiz_answers', 'quiz_asked' );
if( 0 < intval( $user_id ) ) {
$args['user_id'] = intval( $user_id );
}
@hlashbrooke
hlashbrooke / function.php
Created July 14, 2014 15:44
Sensei - Disable "Pass required to complete lesson" on all lessons. Add this to your theme's functions.php file and then load any frontend page on the site. After that you must remove the code from your site.
View function.php
<?php
add_action( 'init', 'sensei_disable_pass_required_all_lessons' );
function sensei_disable_pass_required_all_lessons() {
if( is_admin() ) {
return;
}
global $woothemes_sensei;
@hlashbrooke
hlashbrooke / function.php
Last active August 29, 2015 14:04
Function to prevent numbers (or any other string) from being automatically turned into a link inside Gmail, Outlook, etc.
View function.php
<?php
function prevent_text_link( $str ) {
// Get total length of string
$strlen = strlen( $str );
// Get number of middle character in string
$middle = round( intval( $strlen ) / 2 );
// Loop through each character in the string and add an empty HTML tag in the middle
@hlashbrooke
hlashbrooke / functions.php
Created July 21, 2014 11:30
WooCommerce Order Barcodes: Disable nonce check
View functions.php
<?php
add_filter( 'woocommerce_order_barcodes_do_nonce_check', 'disable_woocommerce_order_barcodes_nonce_check' );
function disable_woocommerce_order_barcodes_nonce_check( $do_check ) {
// Do any required pressing here
$do_check = false;
return $do_check;
}
?>
@hlashbrooke
hlashbrooke / functions.php
Created August 1, 2014 07:33
Sensei: Give editors access to all courses & lessons on the frontend
View functions.php
<?php
add_filter( 'sensei_all_access', 'sensei_editor_access' );
function sensei_editor_access( $access ) {
if( current_user_can( 'editor' ) ) {
$access = true;
}
return $access;
}
?>
@hlashbrooke
hlashbrooke / functions.php
Created August 1, 2014 07:20
Sensei: Force lesson ordering to use the menu order attribute instead of the custom ordering available from v1.6
View functions.php
<?php
add_filter( 'pre_get_posts', 'sensei_lessons_use_menu_order' );
function sensei_lessons_use_menu_order( $query ) {
if( is_admin() || 'lesson' != $query->query_vars['post_type'] ) {
return;
}
$query->set( 'orderby', 'menu_order date' );
}
@hlashbrooke
hlashbrooke / admin.css
Created October 16, 2014 11:35
Better bbPress admin icons
View admin.css
body #menu-posts-forum div.wp-menu-image:before {
content: "\f325" !important;
}
body #menu-posts-topic div.wp-menu-image:before {
content: "\f348" !important;
}
body #menu-posts-reply div.wp-menu-image:before {
content: "\f125" !important;
}
@hlashbrooke
hlashbrooke / function1.php
Created October 16, 2014 12:21
Create a shortcode in WordPress
View function1.php
<?php
function shortcode_function( $params ) {
return "Shortcode content";
}
add_shortcode( 'shortcode_name', 'shortcode_function' );
?>