Skip to content

Instantly share code, notes, and snippets.

View menslow's full-sized avatar

Michael Enslow menslow

View GitHub Profile
@menslow
menslow / gist:1855391
Created February 17, 2012 20:55
JavaScript: Boilerplate JavaScript App
App = function(){
/* private */
var default_topic = 'Placeholder Text';
/* HTML5 elememt support tester */
var element_supports_attribute = function(element,attribute){
var test = document.createElement(element);
if (attribute in test) {
return true;
@menslow
menslow / wp template part dropdown state
Created February 28, 2012 23:27
WordPress: Template Part: State Dropdown
<?php
global $input_state_province, $input_required, $selected_state;
?>
<label class="unitx1"><?php _e('State'); ?> <?php if($input_required) : echo '*'; endif; ?>
<select id="<?php echo esc_attr($input_state_province); ?>" name="<?php echo esc_attr($input_state_province); ?>" class="<?php if($input_state_province) : echo 'required'; endif; ?>">
<option value=""<?php if($selected_state==='') : echo ' selected="selected"'; endif; ?>><?php _e('Please Select'); ?></option>
<option value="AL"<?php if($selected_state==='AL') : echo ' selected="selected"'; endif; ?>><?php _e('AL'); ?></option>
<option value="AK"<?php if($selected_state==='AK') : echo ' selected="selected"'; endif; ?>><?php _e('AK'); ?></option>
<option value="AZ"<?php if($selected_state==='AZ') : echo ' selected="selected"'; endif; ?>><?php _e('AZ'); ?></option>
<option value="AR"<?php if($selected_state==='AR') : echo ' selected="selected"'; endif; ?>><?php _e('AR'); ?></option>
@menslow
menslow / Cake Cap Deploy
Created April 8, 2012 22:54
CakePHP: Capistrano deployment script for CakePHP App
default_run_options[:pty] = true # Must be set for the password prompt from git to work
set :domain, "your-domain.com"
set :user, "your-user"
set :application, "your-app"
set :repository, "your-repo"
set :branch, "master"
set :scm, :git
# Tell Capistrano to use agent forwarding with this command. uses your local keys instead of keys installed on the server.
@menslow
menslow / WordPress Sign In
Created April 12, 2012 21:12
WordPress: Simple sign in function for custom front-end sign in forms.
/**
* mm_sign_in function.
* Sign the user in
* @access public
* @return User errors or true if successful signon
*/
function mm_sign_in() {
if(!is_user_logged_in()) {
if(!empty($_POST)) {
// verify nonce
@menslow
menslow / WordPress Registration
Created April 13, 2012 00:33
WordPress: Simple registration function for custom front-end registration forms.
/**
* mm_register function.
* Register a new user.
* @access public
* @return User errors or user is logged in.
*/
function mm_register() {
if(!is_user_logged_in()) {
if(!empty($_POST)) {
@menslow
menslow / WordPress Show Admin Bar
Created April 16, 2012 18:20
WordPress: Add filter to control which users see the admin bar.
/**
* mm_show_admin_bar function.
* Filter to control which users see the admin bar.
* @access public
* @return false or true if user is admin.
*/
function mm_show_admin_bar() {
if (current_user_can('administrator')) {
return true;
} else {
@menslow
menslow / PHP truncate functions
Created April 16, 2012 20:14
PHP: Couple of yummy truncate functions.
/**
* truncate_words function to truncate a string of words to a specified number of words
* @param string $str The text string to split
* @param integer $words The number of words to extract. Defaults to 15
*/
function truncate_words( $str, $words = 15 )
{
$arr = preg_split( '/[\s]+/', $str, $words+1 );
$arr = array_slice( $arr, 0, $words );
return join( ' ', $arr ) . '&hellip;';
@menslow
menslow / gist:5511828
Created May 3, 2013 17:42
CMS driven 404 page for Genesis Framework
<?php
/**
* Handles display of 404 page.
*
* This file requires the creation of a page with the slug 'page-not-found'
*/
function jb_page_404(){
genesis_custom_loop( array('pagename' => 'page-not-found', 'posts_per_page' => 1 ) );
}
@menslow
menslow / gist:5873095
Created June 27, 2013 00:41
TexExpander Snippet for dropping the default WordPress tables (without dropping the whole database). Complete with field for adding your table prefix.
DROP TABLE %filltext:name=prefix:default=wp:width=6%_commentmeta;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_comments;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_links;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_options;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_postmeta;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_posts;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_term_relationships;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_term_taxonomy;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_terms;
DROP TABLE %filltext:name=prefix:default=wp:width=6%_usermeta;
@menslow
menslow / _text-size-adjust.scss
Last active February 26, 2017 15:15
Sass mixin for text-size-adjust
// text-size-adjust
//------------------------------------------------
//
// Values: none (default), auto, 100%
//
// Reference:
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-size-adjust
//