Skip to content

Instantly share code, notes, and snippets.

View topdown's full-sized avatar
🎯
Focusing

Jeff Behnke topdown

🎯
Focusing
View GitHub Profile
@topdown
topdown / Regex_find_words_in_string.php
Last active December 15, 2015 01:19
Regex find words in string This regex is capable of finding specific words in string and ignoring words in HTML attributes so when replacing with HTML it does not break the code.
<?php
// Updated, the other expression misses stuff like nulla.jpg which broke images
// (?<!-)\b(ipsum|nulla|Nulla)\b(?!\/|\"|\.[a-zA-Z0-9])
//----------------------------
// Example string
//----------------------------
?>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc feugiat laoreet augue, non congue lectus mattis nec. Etiam augue risus, consequat et sodales at, scelerisque id orci. Sed posuere egestas tristique. Aenean fermentum volutpat nisi, nulla vitae convallis risus mollis vel. <a title="nulla" href="http://nulla/nulla">Nulla</a> Nulla convallis venenatis tortor, nec congue augue hendrerit quis. Fusce augue metus, venenatis posuere ornare quis, scelerisque sed quam. <img alt="ipsum" src="ipsum.png" title="ipsum">Nunc nec adipiscing justo. Morbi eget ultrices diam. Proin nisl nisl, aliquet quis aliquet non, sollicitudin ultricies lectus. Etiam malesuada mauris quis sem varius hendrerit. Etiam eu tempor magna. Donec quam metus, elementum eget sollicitudin adipiscing, porttitor di
<?php
/**
* Abstract class which has helper functions to get data from the database
*/
abstract class Base_Custom_Data
{
/**
* The current table name
*
* @var boolean
@topdown
topdown / gist:8d895976b40b888942ba
Created January 19, 2016 02:59
Brew Update issues untracked working tree
cd $(brew --repository)
sudo chown -R $USER .
git reset --hard origin/master
brew update
@topdown
topdown / custom-post_status.php
Last active January 31, 2016 18:06
Custom post status workaround
<?php
/**
* Register Custom Status
*
*/
function custom_archived_post_status() {
$args = array(
@topdown
topdown / Gruntfile.js
Last active April 10, 2016 20:21
Network wide WordPress theme development
// http://mattbanks.me/grunt-wordpress-development-deployments/
// https://github.com/mattbanks/WordPress-Starter-Theme/blob/master/Gruntfile.js
'use strict';
module.exports = function (grunt) {
// load all grunt tasks matching the `grunt-*` pattern
require('load-grunt-tasks')(grunt);
var $proxy = 'vvv_domain.dev';
@topdown
topdown / fix-commands.sh
Last active June 6, 2016 14:47
VVV Issues
# Not saying this is a fix all, but this is what I had to do to get VVV running properly on my system.
# It failed to install properly do to script errors
# Branch master
# head 7f5411455573bba88d8ce232db957c62b11977f5
# VVV Update issues
vagrant ssh
su
#pass
@topdown
topdown / cron.php
Last active July 1, 2016 16:33
Custom cron script for WP
<?php
// This code can go anywhere as long as its loaded by a plugin or theme
// setup the schedual
if ( ! wp_next_scheduled( 'my_task_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
@topdown
topdown / wp-bin-example.php
Last active July 10, 2016 18:38
Load WordPress hooks, filters and APIs in a bin file for processing forms and other data
<?php
// Don't load theme data IE css and other features
define( 'WP_USE_THEMES', false );
/*
* Loads the WordPress Environment and Template
* Change PATH_TO_WP to the path of the following file
*/
require( 'PATH_TO_WP/wp-blog-header.php' );
@topdown
topdown / provision-custom.sh
Created August 5, 2016 18:56
This file is a custom provision script for VVV that skips all updates and update checks
#!/bin/bash
#
# provision.sh
#
# Customized by Jeff Behnke @topdown on GitHub
#
# This file is a custom provision script for VVV that skips all updates and update checks
# It only does the absolute tasks that I know are needed for vagrant up, vagrant reload, vagrant provision and vv create
# It currently runs vagrant provision tasks in roughly 8 secs.
# You should be using VV for creating sites, then replace its custom-provision.sh with this one once you have a working VVV system.
@topdown
topdown / display-rewrites.php
Created October 25, 2016 23:38
For debugging WP rewrite rules
<?php
function jb_show_rewrite_rules() {
$rules = get_option('rewrite_rules');
$n = 0;
$html = '<table><tr><th style="width: 5%;">#</th><th style="width: 35%;">Key</th><th style="width: 60%;">Rule</th></tr>';
foreach ( $rules as $key => $value ) {
$html .= '<tr><td>' . ++$n . '</td><td>' . $key . '</td><td>' . $value . '</td></tr>';
} // end foreach