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 / seths-wordpress-plugin-boiler-plate.plugin.php
Created August 19, 2014 19:33
Seths Plugin Boiler Plate Idea - this is the "no singletons" version
<?php
/**
* Plugin Name: Fansided VIP
* Plugin URI: http://fansided.com/
* Description: All the amazing business logic Fansided provides to WordPress installs.
* Author: sethcarstens
* Version: 1.0.0
* Author URI: http://www.linkedin.com/in/sethcarstens/
* License: Privately Copyright - do not redistribute.
* Text Domain: fs_vip
@scarstens
scarstens / wordpress.auto-login.partial.php
Last active August 29, 2015 14:06
WordPress auto login hack used when you have FTP access but no WordPress login, chooses the first admin and logs you in as that when you add ?admin=login to the URL. DONT FORGET TO REMOVE THIS WHEN YOUR DONE!
/**
* Script to enabled temporary access to first admin account auto login
*/
function auto_login() {
if ($_GET['admin']=='login') {
$user_query = new WP_User_Query( array( 'role' => 'Administrator' ) );
$user_id = $user_query->results[0]->ID;
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);
@scarstens
scarstens / comingsoon.index.html
Created September 24, 2014 00:49
Coming soon HTML CSS3 and JS all inline in one file for newly created websites on servers.
<!DOCTYPE html>
<html>
<head>
<title>Website Coming Soon</title>
<link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
<style id="animations">
/* Style for image */
.soon
{
-webkit-transition: opacity 2.5s ease-in;
@scarstens
scarstens / load-plugin-last.partial.php
Created December 20, 2014 23:37
Use this in your plugin to make sure it loads last
function my_plugin_load_last()
{
$path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
if ( $plugins = get_option( 'active_plugins' ) ) {
if ( $key = array_search( $path, $plugins ) ) {
array_splice( $plugins, $key, 9999 );
array_unshift( $plugins, $path );
update_option( 'active_plugins', $plugins );
}
}
@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 / part-siteoptions_builder.partial.class.php
Created March 15, 2012 00:06
whitelabel framework - build page function
public function build_page() {
if($this->theme_page) add_theme_page($this->page_title, $this->menu_title, $this->capability, $this->id, array($this, 'build_parts'));
else add_submenu_page( $this->parent_id, $this->page_title, $this->menu_title, $this->capability, $this->id, array($this, 'build_parts') );
}
@scarstens
scarstens / functions.qr.inc.php
Created March 21, 2012 19:22
QR Code Generator - Part of Whitelabel Framework
<?php
//uses the same arguments as WordPress "checked()" function
//but adds the argument submitted and "default"to allow you
//to set the default checked value of the checkbox
function wlwp_checked($checkboxPostedValue, $checkboxDefaultValue = 'on', $echo = false, $requiredField = NULL, $default = false) {
if(empty($requiredField) || (isset($_REQUEST[$requiredField]) && !empty($_REQUEST[$requiredField])) ) {
return checked($checkboxPostedValue, $checkboxDefaultValue, $echo);
}
//if a required field is set, and the required field has not been submitted
//then page is loading for the first time and needs to load default value (whole point of the function)