Skip to content

Instantly share code, notes, and snippets.

@nciske
nciske / run_shortcode.php
Last active September 6, 2015 04:48
run_shortcode() is a faster way to call individual shortcodes -- at least 4x faster on a vanilla install, speed increases to 10x or greater with the number of shortcodes registered
<?php
// Faster replacement for do_shortcode *for individual shortcodes only*
// If you have nested shortcodes or shortcodes intermixed in content, do_shortcode() is the still the way to go.
// Inspired by: https://kovshenin.com/2013/dont-do_shortcode/
// WordPress Core Trac Ticket: https://core.trac.wordpress.org/ticket/25435
// Usage
@nciske
nciske / double-confirmation-fields.php
Last active February 8, 2016 15:03
Tweaked to allow a custom message
<?php
/**
* Double Confirmation Fields
* http://gravitywiz.com/2012/05/01/custom-field-confirmation/
*/
register_confirmation_fields( 10, array( 1, 2 ), 'Your custom messages do not match.' );
add_filter( 'gform_validation', 'gfcf_validation' );
function gfcf_validation( $validation_result ) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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
);
@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 / 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 / salesforce_w2l_cc_admin_from_email.php
Last active February 24, 2017 01:29
salesforce_w2l_cc_admin_from_email example
add_filter('salesforce_w2l_cc_admin_replyto_email','yourprefix_salesforce_w2l_cc_admin_from_email');
function yourprefix_salesforce_w2l_cc_admin_replyto_email( $email ){
// change to the field name you want to use if not using the built in field
$field_name = 'email';
// Get the email from the POST data, and sanitize it
$user_email = sanitize_email( $_POST[ $field_name ] );
@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 / 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' ;