Skip to content

Instantly share code, notes, and snippets.

View hlashbrooke's full-sized avatar
🎲

Hugh Lashbrooke hlashbrooke

🎲
View GitHub Profile
@hlashbrooke
hlashbrooke / functions.php
Created July 21, 2014 11:30
WooCommerce Order Barcodes: Disable nonce check
<?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 / 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.
<?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 / 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.
<?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 / functions.php
Last active October 13, 2017 12:58
Sensei Certificates: Use custom font in certificate PDFs
<?php
/**
* Custom fonts MUST be uploaded to the following directory:
* /wp-content/plugins/sensei-certificates/lib/tfpdf/font/unifont/
*
* All custom fonts MUST be TrueType fonts (.ttf)
*
* Only one custom font can be used and it will override ALL fonts in ALL templates
**/
@hlashbrooke
hlashbrooke / functions.php
Last active April 6, 2022 16:49
WooCommerce Product Vendors: Add extra custom fields to vendor profiles
<?php
// Add fields to new vendor form
add_action( 'shop_vendor_add_form_fields', 'custom_add_vendor_fields', 2, 1 );
function custom_add_vendor_fields( $taxonomy ) {
?>
<div class="form-field">
<label for="vendor_website"><?php _e( 'Vendor website' ); ?></label>
<input type="text" name="vendor_data[website]" id="vendor_website" class="vendor_fields" /><br/>
<span class="description"><?php _e( 'The vendor\'s website.' ); ?></span>
@hlashbrooke
hlashbrooke / function.php
Created April 9, 2014 07:58
Sensei: Reset all user activity (for all users or specified user)
<?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 / upload.php
Created March 20, 2014 06:12
WordPress: Upload user-submitted files from the frontend
<?php
function upload_user_file( $file = array() ) {
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
$file_return = wp_handle_upload( $file, array('test_form' => false ) );
if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
return false;
} else {
@hlashbrooke
hlashbrooke / function.php
Created February 28, 2014 08:41
WordPress: Add post types to the 'At a glance' widget
<?php
add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
$post_types = array( 'post_type_1', 'post_type_2' );
foreach( $post_types as $type ) {
if( ! post_type_exists( $type ) ) continue;
@hlashbrooke
hlashbrooke / class.php
Created February 28, 2014 08:37
A complete, versatile options page class for any WordPress plugin
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
class WordPress_Plugin_Template_Settings {
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings_base;
@hlashbrooke
hlashbrooke / function.php
Last active December 13, 2023 12:19
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
<?php
function woocommerce_version_check( $version = '2.1' ) {
if ( function_exists( 'is_woocommerce_active' ) && is_woocommerce_active() ) {
global $woocommerce;
if( version_compare( $woocommerce->version, $version, ">=" ) ) {
return true;
}
}
return false;
}