Skip to content

Instantly share code, notes, and snippets.

View chasecmiller's full-sized avatar

Crumbls chasecmiller

View GitHub Profile
/**
* Here is a patch to bring Visual Composer into Event Espresso 4.
*
* Tested on Visual Composer 4.11 and Event Espresso 4.
*
* Instructions:
* 1) Add this to the end of functions.php or any is_admin() included file.
**/
add_action('admin_print_scripts', function() {
@chasecmiller
chasecmiller / Plugin.php
Last active February 6, 2018 00:08
Wordpress - Materialized Path for Custom Post Types ( CPT ) and Built In Post Types
<?php
/*
Plugin Name: Materialized Paths
Plugin URI: http://crumbls.com
Description: Implement materialized paths for WordPress to enable simple searching for child and parent paths.
Author: Chase C. Miller
Version: 2.0.1a
Author URI: http://crumbls.com
Text Domain: Crumbls\Plugins\Materialized
*/
@chasecmiller
chasecmiller / plugin.php
Last active November 1, 2017 22:22
Extending Category Meta Box in WordPress admin
<?php
namespace Crumbls\Plugins\MetaBoxAlternate;
defined('ABSPATH') or exit(1);
/*
Plugin Name: Allow a filterd list for bloated category lists in the admin meta box
Plugin URI: http://crumbls.com
Description: Example of creating a third tab on the category selection box. We used it to give our Editorial department the categories that we use for news stories, not similar category names.
@chasecmiller
chasecmiller / Example.php
Last active August 11, 2017 03:08
Move WordPress pre-existing attachments to S3 using WP Offload S3 Lite.
<?php
/**
* You can include this snippet anywhere.
* Just remove the reference once you're done.
* It checks to make sure files exist and are readable.
*
* If WP Offload S3 Lite is not installed, this won't do anything other than waste resources.
*
* Love the full plugin? Buy it!
@chasecmiller
chasecmiller / plugin_debug.php
Last active September 9, 2019 23:03
Proof of concept of a WordPress mu-plugin to automatically disable plugins that start throwing errors.
<?php
/*
Plugin Name: Plugin Debugging Tool
Description: Attempt to automatically de-activate plugins that are causing errors. Doesn't always work. This must be installed in the mu-plugins directory.
Author: Chase C. Miller
Version: 1.0
Author URI: http://crumbls.com
*/
namespace Crumbls\Debug\Plugins;
@chasecmiller
chasecmiller / thePermalinkPDF.php
Created November 1, 2017 22:03
WordPress: Change PDF links in WordPress to link directly to the PDF instead of the attachment page
<?php
defined('ABSPATH') || exit(1);
add_filter('the_permalink', 'thePermalinkPDF');
add_filter('attachment_link', 'thePermalinkPDF');
// Automatically convert permalinks to PDFs in search results to the PDF itself, not the Attachment page
function thePermalinkPDF($permalink){
global $post;
if (get_post_mime_type($post->ID) != 'application/pdf') {
@chasecmiller
chasecmiller / wpeCacheFix.php
Created January 11, 2018 18:20
WPEngine - Cache key override - You need this if you want to run a secondary ( or multisite ) in a subdirectory on WP Engine
<?php
/**
* Author: Chase C. Miller
* Working Date: 2017-01-11
* Custom cache key for WPEngine to bypass object caching problems that can happen when you install a secondary or multisite on WPEngine.
* It should be installed as a mu-plugin to catch early activation.
**/
global $wp_object_cache;
@chasecmiller
chasecmiller / HasExtendedData.php
Created January 22, 2020 15:38
A Laravel trait to allow any data to be added to a model .
<?php
// Customize this.
namespace Crumbls\ExtendedData\Traits;
use Str;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;
@chasecmiller
chasecmiller / HasPasswordAttribute.php
Last active February 3, 2021 17:24
A laravel trait for setting passwords with automatic hashing.
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Hash;
/**
* Trait HasPasswordAttribute
* @package App\Traits
*/
@chasecmiller
chasecmiller / gist:027896f5518d44141687cca4da4c10b7
Last active March 5, 2021 19:08
Getting the row number for the current db entry in Laravel.
This is a very inefficient way to do it once the db is huge. But it works. For the example, the user id is 5.
$userId = 5;
\DB::statement('SET @row=0');
$user = \App\Models\User::whereRaw('1=1')
->select([
\DB::raw('@row:=@row+1 as row'),
\DB::raw('count(*) as c'),
'users.*'
])