Skip to content

Instantly share code, notes, and snippets.

View TimBHowe's full-sized avatar

Tim Howe TimBHowe

View GitHub Profile
@TimBHowe
TimBHowe / functions.php
Last active May 24, 2022 16:21
Add "Company" field to WordPress user account and add sortable company column to the user backend.
//add&remove field from user profiles - sorce:http://davidwalsh.name/add-profile-fields
function modify_contact_methods($profile_fields) {
// Add new fields
$profile_fields['company'] = 'Company';
// Remove old fields
//unset($profile_fields['aim']);
return $profile_fields;
@TimBHowe
TimBHowe / function.php
Last active April 28, 2022 21:24
WordPress Redirect any pages that are in draft/trash for non login users to the home page
<?php
//redirect any draft/trashed posts
add_action('wp', 'trash_redirect');
function trash_redirect(){
if ( !current_user_can( 'edit_pages' ) ) {
if (is_404()){
global $wp_query, $wpdb;
$page_id = $wpdb->get_var( $wp_query->request );
$post_status = get_post_status( $page_id );
if($post_status == 'trash' || $post_status == 'draft'){
@TimBHowe
TimBHowe / custom-system-emails.php
Last active December 23, 2015 22:19
Update the default WordPress system emails with site/blog branding.
<?php
/** custom-system-emails.php
*
* Plugin Name: Custom WordPress System Emails
* Plugin URI: http://hallme.com
* Description: This plugin custom plugin created for Process Pro to alter the default WordPress System emails. There is no admin section to this plugin so all edits will need to be made in the code.
* Version: 0.1
* Author: Hall Internet Marketing - Tim Howe
* Author URI: http://hallme.com
* Text Domain: wp-system-emails
@TimBHowe
TimBHowe / gist:6765309
Created September 30, 2013 15:16
PHP function to truncate a string up to a number of characters while preserving whole words and HTML tags. Source from http://alanwhipple.com/2011/05/25/php-truncate-string-preserving-html-tags-words/
<?php
/**
* truncateHtml can truncate a string up to a number of characters while preserving whole words and HTML tags
*
* @param string $text String to truncate.
* @param integer $length Length of returned string, including ellipsis.
* @param string $ending Ending to be appended to the trimmed string.
* @param boolean $exact If false, $text will not be cut mid-word
* @param boolean $considerHtml If true, HTML tags would be handled correctly
*
@TimBHowe
TimBHowe / functions.php
Created October 21, 2013 19:33
Sort WordPress media library by pdf file type.
//sort media library by pdf file type - http://wordpress.org/support/topic/filter-media-library-by-file-type
function modify_post_mime_types($post_mime_types) {
$post_mime_types['application/pdf'] = array(__('PDF'), __('Manage PDF'), _n_noop('PDF <span class="count">(%s)</span>', 'PDF <span class="count">(%s)</span>'));
return $post_mime_types;
}
add_filter('post_mime_types', 'modify_post_mime_types');
@TimBHowe
TimBHowe / function.php
Created November 20, 2013 17:27
Redirect non admin users to the home page after logging in. - Original Source (http://tommcfarlin.com/redirect-non-admin/)
// Redirect non-admins to the homepage after logging into the site.
function nonadmin_login_redirect( $redirect_to, $request, $user ) {
return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url();
}
add_filter( 'login_redirect', 'nonadmin_login_redirect', 10, 3 );
@TimBHowe
TimBHowe / functions.php
Created March 7, 2014 22:15
Change the WordPress gallery html output
<?php
//Modify the output of the gallery short code
add_filter('post_gallery', 'scaffolding_post_gallery', 10, 2);
function scaffolding_post_gallery($attr) {
$post = get_post();
static $instance = 0;
$instance++;
if ( ! empty( $attr['ids'] ) ) {
@TimBHowe
TimBHowe / gf-addon-api.php
Last active August 29, 2015 13:58
Add a dropdown list of the current forms in gravity forms add-on API
<?php
public function plugin_settings_fields() {
//collect the forms for the array options
$forms = RGFormsModel::get_forms();
$choices = array();
foreach($forms as $form){
$choices[] = array("label" => esc_html($form->title),"value" => absint($form->id));
}
@TimBHowe
TimBHowe / editore_styles.scss
Last active August 29, 2015 14:00
WordPress Core Media Player Classes to make the video player responsive
/*Core Media Player*/
.mejs-container {
.mejs-controls{
.mejs-button{}
.mejs-playpause-button{}
.mejs-play{}
.mejs-pause{}
@TimBHowe
TimBHowe / remove_orders
Last active January 31, 2017 12:47
Remove all orders from WordPress WooCommerce. This is ideally for clearing out orders on a staging/beta version of a WooCommerce site where the order information is not needed or should not be stored.
DELETE FROM wp_postmeta
WHERE post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'shop_order');
DELETE FROM wp_posts WHERE post_type = 'shop_order';