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 / the_short_content.php
Last active December 19, 2015 17:39
Shortened get_the_content() with a passable character length variable. Defaults to 200 characters
function otm_short_content( $length = 200 ) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
echo wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
echo wpautop( $content );
}
@mikeselander
mikeselander / get_short_content.php
Last active December 21, 2015 17:08
A companion function to the_short_content to return without any wpautop or echoing
function otm_get_short_content($length = 200) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
return wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
return wpautop( $content );
}
@mikeselander
mikeselander / gform_field_value_{your_field}
Created February 28, 2014 03:27
This is an example of the gform_field_value function
/**
* Pre-populates a company ID into a Gravity Forms field from a GET variable
*
* @since 0.1.0
*
*/
add_filter('gform_field_value_company_id', 'company_id_population');
function company_id_population(){
// if we have the proper company GET variable - set the return variable
@mikeselander
mikeselander / gform_pre_render example
Created February 28, 2014 03:32
This is an example of the gform_pre_render function - pulls from a custom table of contact
/**
* Creates a dropdown field based on a returned SQL query of a custom db table
*
* @since 0.1.0
*
*/
add_filter('gform_pre_render_7', 'populate_contacts'); // _7 relates this to a particular field
function populate_contacts( $form ){
// Loop through fields
@mikeselander
mikeselander / gform_validation
Created February 28, 2014 03:46
An example of gform_validation where we validate a field value based on a minimum value from a custom metabox
/**
* Custom validation so that a bid less than the minimum custom metabox is not allowed
*
* @since 0.1.0
*
*/
add_filter( "gform_field_validation_10_1", "min_bid_validation", 10, 4 );
function min_bid_validation( $result, $value, $form, $field ){
// Get the correct output from the form
@mikeselander
mikeselander / gform_after_submission
Created February 28, 2014 03:52
Get data out of a Gravity Form with gform_after_submission
/**
* Get an auction id & info from Gravity Forms ID8
*
* @since 0.1.0
*
*/
add_action('gform_after_submission_8', 'ps_add_bid_card_from_form', 10, 2); // _8 means we're only grabbing data when the form ID8 is submitted
function ps_add_bid_card_from_form($entry, $form) {
// Get these two fields from fields ID2 & ID3
@mikeselander
mikeselander / gform_confirmation
Created February 28, 2014 03:54
Show a custom confirmation based on which page the form is submitted on with gform_confirmation
/**
* Dual confirmation message
*
* @since 0.1.0
*
*/
add_filter("gform_confirmation_10", "bid_confirmation", 10, 4);
function bid_confirmation( $confirmation, $form, $lead, $ajax ){
// If this is the correct page, re-direct back to our page w/ lead info
@mikeselander
mikeselander / A spam comment gone bad
Created May 9, 2014 20:27
A spam comment gone wrong
{
{I have|I’ve} been {surfing|browsing} online more than {three|3|2|4} hours today, yet I never found any interesting article like yours.
{It’s|It is} pretty worth enough for me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website
owners|web owners} and bloggers made good content as you did,
the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn’t|could not} {resist|refrain from} commenting.
{Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss
feed} as I {can not|can’t} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink} or {newsletter|e-newsletter} service.
@mikeselander
mikeselander / 0_reuse_code.js
Created June 5, 2014 02:53
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mikeselander
mikeselander / javascript_resources.md
Created June 5, 2014 02:53 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage