Skip to content

Instantly share code, notes, and snippets.

View scarstens's full-sized avatar
🌟
Automating workflows.

Seth Carstens scarstens

🌟
Automating workflows.
View GitHub Profile
@scarstens
scarstens / function-override-with-class.test.php
Created February 21, 2015 01:53
Example of overriding a "root level" function using a custom class. The example showcases how to override WordPress's pluggable.php function wp_mail, with a custom function.
<?php
class wpMandrill{
static function load(){
function wp_mail(){
echo 'custom mail';
}
}
}
@scarstens
scarstens / remove-action-by-class.function.php
Created March 5, 2015 23:54
remove_action_by_class - Remove actions that are created in WordPress by the add_action hook, but can't be removed with the remove_action hook because an instance of a class created the hook with no way to access it. Use to remove custom actions created by class instances.
<?php
/**
* Function remove_action_by_class
* Used to remove notices and nags or other class actions added with class instances (unable to remove with remove_action)
*
* @param $hook_name
* @param $class_and_function_list
* @param int $priority
*
* ex use case:
@scarstens
scarstens / xml_entities.function.php
Created April 10, 2015 17:57
Function to use with SimpleXML that allows you to properly encode all XML values, use in an example like $setting->addChild( $name, xml_entities($v) );
<?php
//for use with SimpleXML objects
//ie $setting->addChild( $name, xml_entities($v) );
if(!function_exists('xml_entities')) {
function xml_entities( $string ) {
return strtr(
$string,
array(
"<" => "&lt;",
">" => "&gt;",
@scarstens
scarstens / fix-dynamic-zindex-hoarders.js
Created June 27, 2015 01:33
Javascript snippet should be loaded "on page load" and it should attach itself to any elements on the page that are abusing z-index (anything over 999) and brings them back down to 99 by building a style element after the element found. Does not fix elements with inline !important styles, which are impossible to override.
//todo: needs to somehow use the .on function to attach to elements created after pageload
jQuery('[style*="z-index"]').each(function() {
var zi = $(this).css("z-index");
if(zi > 999){
newstyle = jQuery('<style class="zindex2big" type="text/css"> #'+this.id+'{ z-index=99 !important;} </style>').insertAfter(this);
}
});
@scarstens
scarstens / sunrise.php
Created April 18, 2016 23:50
Custom sunrise for TLD wordpress multisite in 1 file
<?php
if ( !empty( $_SERVER['HTTP_HOST'] ) ) {
$site = get_site_by_path( strtolower( $_SERVER['HTTP_HOST'] ), '/');
define( 'COOKIE_DOMAIN', '.' . $site->domain );
}
@scarstens
scarstens / class-an-injected-network-site-option.php
Created January 11, 2017 17:24
Site option example of injecting new section and fields into existing sm_options_page or sm_options_container from the fansided-vip plugin
<?php
/**
* Plugin Name: an-injected-network-site-option
* Description: Site option example of injecting new section and fields into existing sm_options_page or sm_options_container from the fansided-vip plugin
* Plugin URI: https://github.com/fansided
* Author: sethcarstens
* Author URI: https://fansided.com
* Version: 0.0.1
* Text Domain: fs
* License: GPLv2 or later
@scarstens
scarstens / sunrise.php
Created August 23, 2017 03:13
multisite-top-level-domain-config
<?php
if (!empty($_SERVER['HTTP_HOST']))
{
$site = get_site_by_path(strtolower($_SERVER['HTTP_HOST']), '/');
define('COOKIE_DOMAIN', '.'.$site->domain);
}
@scarstens
scarstens / vvv-nginx-image-fallback-prod.conf
Created June 21, 2018 21:49
Nginx configuration based on FanSided's local development shows has to setup nginx fallback for images that exist in production, so that you don't need to download them locally.
#matches all .dev TLDs
log_format main 'MAIN: $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
log_format wpc 'WPCONTENT: $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
log_format PROXY 'PROXY: $remote_addr - $remote_user [$time_local] '
@scarstens
scarstens / lando-wp-init.sh
Last active March 26, 2019 22:16
Lando Initializer
lando init --recipe=wordpress --webroot=. --option via=nginx --option php=7.2 --option database=mariadb --option xdebug=true --source=cwd --name=osp
lando start
lando wp core download
lando wp config create --dbname=wordpress --dbuser=wordpress --dbpass=wordpress
lando wp core install --quiet --admin_email="admin@lando.site" --title="LandoSite" --admin_user=admin --admin_password=password --url=https://osp.lndo.site
lando wp theme delete twentythirteen ; lando wp theme delete twentyfourteen; lando wp theme delete twentyfifteen; lando wp theme delete twentysixteen; lando wp plugin delete hello; lando wp plugin delete akismet;;