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 /
Created April 28, 2014 17:47
Automatically link twitter usernames in content and comment areas of WordPress.
scarstens / class.array2xml.php
Last active August 29, 2015 14:00
Array to XML Using XDOMDocument
View class.array2xml.php
class XDOMElement extends DOMElement {
function __construct($name, $value = null, $namespaceURI = null) {
parent::__construct($name, null, $namespaceURI);
class XDOMDocument extends DOMDocument {
scarstens / destroy_php_session.php
Created May 5, 2014 17:14
Destroy PHP session
View destroy_php_session.php
scarstens / wordpress.disable_registration_.php
Created May 29, 2014 20:32
Disable default registration page in WordPress by redirecting away. Has filter for custom redirection. Used to secure registrations that do not follow standard WordPress registration workflows.
View wordpress.disable_registration_.php
function disable_default_registration(){
global $pagenow;
if( 'wp-login.php' == $pagenow && $_REQUEST['action'] == 'register') {
$registration_redirect = apply_filters('disable_default_registration_redirect', site_url());
scarstens / php_smart_session_start.php
Created May 29, 2014 23:50
PHP Session Start only if Session does not exist.
View php_smart_session_start.php
isset($_SESSION) || session_start();
scarstens / wordpress.cssjs-per-page-loader.php
Created June 19, 2014 18:55
Per page CSS and JS loader for wordpress that loads CSS and JS using the URL slug. Loads if it exists, doesn't load if it doesn't exist. Its like get_template_part actions for CSS and JS files! Keywords: this, page, stylesheet, js, javascript, wordpress
View wordpress.cssjs-per-page-loader.php
//load styles and scripts for this page
add_action( 'wp_enqueue_scripts', 'this_page_stylesheet' );
add_action( 'wp_enqueue_scripts', 'this_page_js' );
function this_page_stylesheet() {
$ss_filename = str_replace('php', 'css', basename(__FILE__));
wp_enqueue_style( 'page-style', get_stylesheet_directory_uri().'/appearance/'.$ss_filename);
function this_page_js() {
scarstens / function.valsort.php
Last active August 29, 2015 14:02
Value Sorting multi-dimensional arrays
View function.valsort.php
* Sorts an array by the value defined in $key
* @author Seth Carstens []
* example array:
* $array[1]['regularvalue'->'sample1','selectedsortvalue'->'a comes before b']
* $array[2]['regularvalue'->'sample2','selectedsortvalue'->'c comes after b']
* ex array after usort($array, valsort('selectedsortvalue'));:
* $array[2]['regularvalue'->'sample2','selectedsortvalue'->'c comes after b']
* $array[1]['regularvalue'->'sample1','selectedsortvalue'->'a comes before b']
scarstens / function.callFunctionFromString.js
Created June 21, 2014 00:28
Call javascript function using a javascript string as a parameter
View function.callFunctionFromString.js
//enable callFunction function
function callFunction(func){
this[func].apply(this,, 2));
/* use case, calling many function dynamically
jQuery.each(filterGroups, function(index, value){
if(maybe_debug) console.log(index,':',value);callFishFinderFunction('applyFilter',index);}
scarstens / wordpress.function-load_classes.php
Created July 13, 2014 07:45
loads classes from a folder
View wordpress.function-load_classes.php
* Returns array of features, also
* Scans the plugins subfolder "/classes"
* @since 0.1
* @return void
protected function load_classes() {
// load all files with the pattern *.php from the directory inc
scarstens / print_style_hooks.wordpress.php
Created August 15, 2014 03:48
WordPress php code to print a list of hook-action-styles from the enqueue method.
View print_style_hooks.wordpress.php
add_action('wp_print_styles','check_styles', 1);
function check_styles(){
$hook_name = 'wp_enqueue_scripts';
global $wp_filter;
var_dump( $wp_filter[$hook_name] );exit;