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 / php_smart_session_start.php
Created May 29, 2014 23:50
PHP Session Start only if Session does not exist.
isset($_SESSION) || session_start();
@scarstens
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
//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
scarstens / function.valsort.php
Last active August 29, 2015 14:02
Value Sorting multi-dimensional arrays
/**
* Sorts an array by the value defined in $key
* @author Seth Carstens [seth@sethmatics.com]
*
* 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
scarstens / function.callFunctionFromString.js
Created June 21, 2014 00:28
Call javascript function using a javascript string as a parameter
//enable callFunction function
function callFunction(func){
this[func].apply(this, Array.prototype.slice.call(arguments, 2));
}
/* use case, calling many function dynamically
jQuery.each(filterGroups, function(index, value){
if(value.onoff){
if(maybe_debug) console.log(index,':',value);callFishFinderFunction('applyFilter',index);}
});
*/
@scarstens
scarstens / wordpress.function-load_classes.php
Created July 13, 2014 07:45
loads classes from a folder
/**
* 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
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.
<?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;
}
@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 );
}
}