Skip to content

Instantly share code, notes, and snippets.

@nciske
nciske / acf-get-field-fail-gracefully.php
Last active August 29, 2015 14:17
Fail gracefully when ACF is deactivated but avoid lots of function_exists calls...
<?php
function prefix_get_field( $key, $id = null ){
if( !$id )
$id = get_the_id();
if( function_exists('get_field') ){
return get_field( $key, $id );
}else{
return get_post_meta( $id, $key, true );
@nciske
nciske / detect_ie.js
Created January 23, 2015 20:51
Detect IE version (all)
function getInternetExplorerVersion()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
@nciske
nciske / gform-na-currency.php
Created July 30, 2014 14:51
Gravity Forms - Currency with no symbol. For those edge cases where the amount could be in any number of denominations.
<?php
add_filter("gform_currencies", "add_na_currency");
function add_na_currency($currencies) {
$currencies['NA'] = array(
"name" => __("N/A", "gravityforms"),
"symbol_left" => '',
"symbol_right" => "",
"symbol_padding" => " ",
@nciske
nciske / location_date_shortcode.php
Created July 10, 2014 15:45
location_date_shortcode example (ACF)
<?php
add_shortcode('location_date','location_date_sc')
function location_date_sc( $atts, $content ){
extract( shortcode_atts( array(
'post_id' => get_the_id(),
), $atts, 'location_date' ) );
@nciske
nciske / author_box_in_feed.php
Last active August 29, 2015 14:02
Show Genesis single author box in RSS feed
<?php
add_filter( 'the_content_feed', 'genesis_author_box_in_feed' );
function genesis_author_box_in_feed( $content ){
$content .= genesis_author_box( 'single', false );
return $content;
}
<?php
function email_feed_post_limit( $limit, $query ) {
if ( ! is_admin() && $query->is_feed() && isset( $_GET['email'] ) && $_GET['email'] ) {
return 'LIMIT 0, 10';
}
return $limit;
}
add_filter( 'post_limits', 'email_feed_post_limit', 10, 2 );
<?php
/*
How to use:
1. Create a custom field at SalesForce, long enough to hold your longest page title (i.e. at least 255 characters)
2. Replace PAGE_TITLE_CUSTOM_FIELD_NAME below with the name of the custom field you setup in SalesForce,
it will be something like PageTitle__c
3. Add a hidden field to your form(s) with the same field name (e.g. "PageTitle__c")
4. Profit
*/
<?php
function fix_pb_cover_image( $metadata, $object_id, $meta_key, $single ) {
if( isset( $meta_key ) && 'pb_cover_image' == $meta_key && is_ssl() )
return str_replace( 'http://', 'https://', $metadata );
return $metadata;
}
@nciske
nciske / plugin.php
Last active August 29, 2015 14:01
Fix for Genesis Simple Sidebars "Illegal string offset" error. Replace plugin.php with code below.
<?php
/*
Plugin Name: Genesis Simple Sidebars
Plugin URI: http://www.studiopress.com/plugins/simple-sidebars
Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
Author: Nathan Rice
Author URI: http://www.nathanrice.net/
Text Domain: ss
Domain Path: /languages/
@nciske
nciske / sf_w2l_user_ip.php
Last active August 29, 2015 14:01
Save user ip in a specific field -- replace user_ip__c with your custom field name - make sure it can store up to 45 characters (for IPv6 addresses)
<?php
// Save user ip in a specific field
// -- replace user_ip__c with your custom field name
// -- make that a hidden text field in your lead form (make sure it's enabled)
// -- make sure it can store up to 45 characters (for IPv6 addresses)
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_ip_field', 10, 3 );
function salesforce_w2l_ip_field( $val, $field, $form ){