Skip to content

Instantly share code, notes, and snippets.

<?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 );
@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;
}
@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 / 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 / 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 / filter-returl.php
Created April 1, 2015 19:38
Filter retURL
add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_field_urlredirect', 10, 3 );
function salesforce_w2l_field_urlredirect( $val, $field, $form ){
$postid = get_the_id();
// Target a specific field on all forms
if( $field == 'retURL' ){
if( $field == 'retURL' && $postid == '671' ) {
$URL = 'http://www.mycompany.com/thank-you?option=1' ;
@nciske
nciske / post-content-xml.php
Created April 8, 2015 17:14
Save post content to disk
function pht_write_file( $id, $post) {
$upload_dir = wp_upload_dir();
$file = $upload_dir['basedir']."/publication-hub-tools/test.xml";
$content = $post->post_content;
// convert $content to XML...
file_put_contents( $file, $content );
}
add_action( 'publish_post', 'pht_write_file', 10, 2 );
@nciske
nciske / salesforce_w2l_cc_admin_from_name.php
Created May 4, 2015 13:54
salesforce_w2l_cc_admin_from_name example
add_filter( 'salesforce_w2l_cc_admin_from_name', 'yourprefix_salesforce_w2l_cc_admin_from_name' );
function yourprefix_salesforce_w2l_cc_admin_from_name( $name ){
// change to the field names you want to use if not using the built in fields
$field_names = array( 'first_name', 'last_name');
$user_name_pieces = array();
foreach( $field_names as $field_name ){
@nciske
nciske / post-meta-count.php
Last active August 29, 2015 14:20
Count post meta by post_id
<?php
function wpdc_count_post_meta( $post_id ){
global $wpdb;
$sql = $wpdb->prepare( 'SELECT COUNT( meta_id ) FROM '.$wpdb->postmeta.' WHERE `post_id` = %d', $post_id );
$post_meta_count = $wpdb->get_var( $sql );
@nciske
nciske / clean-vimeo-oembed.php
Created May 26, 2015 21:43
Clean Vimeo oEmbeds
<?php
add_filter('oembed_fetch_url','ch_add_vimeo_args',10,3);
function ch_add_vimeo_args($provider, $url, $args) {
if ( strpos($provider, '//vimeo.com/') !== false ) {
$args = array(
'title' => 0,
'byline' => 0,
'portrait' => 0,
'badge' => 0
);