Skip to content

Instantly share code, notes, and snippets.

View mikeselander's full-sized avatar
:shipit:
Shipping

Mike Selander mikeselander

:shipit:
Shipping
View GitHub Profile
@mikeselander
mikeselander / new_gist_file_0
Created June 5, 2014 18:10
See all posted WordPress variables
echo $GLOBALS['wp_query']->request;
@mikeselander
mikeselander / json-into-xml.php
Created June 5, 2014 18:11
Convert object from json into xml
$obj = json_decode($save);
$xml = $xmls->serialize($obj);
file_put_contents($file, $xml);
@mikeselander
mikeselander / child-page-listing.php
Created June 5, 2014 18:16
Check to see if a page has children, and if it does, list pages out
if( !$post->post_parent ){ // If is a parent page
$parent_id = $post->ID;
} else { // If is a child
if( $post->ancestors ) {
$parent_id = end( $post->ancestors );
}
}
if ($children) {
echo "<ul class='page-children'>";
@mikeselander
mikeselander / css-cheatsheet.css
Created June 6, 2014 04:02
Basic CSS Selector Cheatsheet
/* Basic Selectors */
#name /* <div id='name'> */
.name{} /* <div class='name'> */
.parent.name{} /* <div class='parent name'> */
.parent .child{} /* Child Element <div class='parent'> <div class='child'> */
.parent > .child{} /* Direct Child Element ONLY (grandchildren will be ignored) */
.one + .two{} /* Directly Adjoining Elements <div class='one'></div> <div class='two'></div> */
.one ~ .two{} /* Any Following Elements */
/* dynamic selectors */
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
function make_comparer() {
// Normalize criteria up front so that the comparer finds everything tidy
$criteria = func_get_args();
foreach ($criteria as $index => $criterion) {
$criteria[$index] = is_array($criterion)
? array_pad($criterion, 3, null)
: array($criterion, SORT_ASC, null);
}
return function($first, $second) use (&$criteria) {
@mikeselander
mikeselander / Pre_Render_Object.php
Created June 19, 2014 16:29
A function to automatically fill in an edit gravity form with the appropriate data from a custom table object
add_filter('gform_pre_render_3', 'populate_fields_contact'); // Document Form
function populate_fields_contact( $form ){
// Make sure we're editing the object correctly
if ( $_GET['update_contact'] ){
// Set our default values
$data_type = "contact";
$data_type_length = 8; // 'contact_' = 8 char
@mikeselander
mikeselander / remove-admin-bar.php
Created July 2, 2014 23:25
Remove admin bar & keep end users out of the WordPress backend
/**
* Remove admin bar & admin access for non-managers & non-admins
* @access public
* @since 0.1.0
*/
add_action('admin_init', 'no_mo_dashboard');
add_action('after_setup_theme', 'remove_admin_bar');
function no_mo_dashboard() {
if ( ! current_user_can( 'edit_others_posts' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( site_url() ); exit;
@mikeselander
mikeselander / restrict-failed-login.php
Created July 2, 2014 23:27
On front-end login form, keep user from being re-directed to an admin login page when a field fails
/**
* Keep a failed login attempt on the same page instead of re-directing to backend
* @access public
* @since 0.1.0
*/
add_action( 'wp_login_failed', 'my_front_end_login_fail' ); // hook failed login
function my_front_end_login_fail( $username ) {
$referrer = $_SERVER['HTTP_REFERER']; // where did the post submission come from?
if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) {
@mikeselander
mikeselander / resize-partners.js
Created July 2, 2014 23:32
Maintain an exact size & margin between an unknown number of images within a parent div - useful for situations where a user can add multiple (unknown) number of logos to a box (generally footer)
function adjust_header_banner(){
var footer = $('.footer');
count = 0;
totalWidth = 0;
// Calculate distance between partner images
$('.partners img').each(function() {
totalWidth += $(this).width();
count += 1;