Skip to content

Instantly share code, notes, and snippets.

View timothyjensen's full-sized avatar

Tim Jensen timothyjensen

View GitHub Profile
@timothyjensen
timothyjensen / functions.php
Last active September 4, 2019 18:49
Enforce anti-spam honeypot on all Gravity Forms forms
<?php
/**
* Enforce anti-spam honeypot on all Gravity forms.
*
* @param array $form
*
* @return array $form
*/
add_filter( 'gform_form_post_get_meta', function ( $form ) {
<?php
add_action( 'before_genesis_site-inner_wrap', 'do_full_width_page_header' );
/**
* Adds a div with a background image before the site-inner wrap.
*/
function do_full_width_page_header() {
printf( '<div class="full-width-page-header" style="background: url(\'%s\');"></div>',
wp_get_attachment_image_url( 2623, 'full' )
);
@timothyjensen
timothyjensen / functions.php
Last active June 4, 2019 19:20
Add hooks before Genesis structural wraps.
<?php
// Prefixing is recommended if you are not using a namespace.
// namespace TimJensen\GenesisStarter\Setup;
/**
* Adds hooks immediately before and after Genesis structural wraps.
*
* @version 1.1.0
*
* @return void
@timothyjensen
timothyjensen / output.php
Created March 1, 2017 02:22
Example output of get_all_custom_field_meta()
<?php
array(
'prefix_subtitle' => 'This is the subtitle',
'prefix_content_row' => array(
array(
'css_classes' => 'extra-class row-1',
'background_color' => '1',
'columns' => array(
array(
'column' => 'Row 1 column 1',
@timothyjensen
timothyjensen / config.php
Created March 1, 2017 02:01
Example config for get_all_custom_field_meta()
<?php
$config = array(
array(
'name' => 'prefix_subtitle',
),
array(
'name' => 'prefix_content_row',
'sub_fields' => array(
array(
'name' => 'css_classes',
@timothyjensen
timothyjensen / functions.php
Last active February 5, 2018 14:58
Get an auto generated post excerpt, or a manual excerpt if one has been set.
<?php
// Make sure to prefix the function if you do not use a namespace.
// namespace TimJensen\HelperFunctions;
/**
* Returns an auto generated post excerpt, or a manual excerpt if one has been set.
*
* @version 1.2.1
*
* @param int $post_id Required. Post ID.
@timothyjensen
timothyjensen / functions.php
Last active October 13, 2019 05:14
Retrieves all post meta data according to the structure in the $config array. Provides a convenient and more performant alternative to ACF's `get_field()`. This function is especially useful when working with ACF repeater and flexible content fields. See details at https://www.timjensen.us/acf-get-field-alternative.
<?php
/**
* Retrieves all post meta data according to the structure in the $config
* array.
*
* Provides a convenient and more performant alternative to ACF's
* `get_field()`.
*
* This function is especially useful when working with ACF repeater fields and
* flexible content layouts.
@timothyjensen
timothyjensen / functions.php
Last active May 5, 2017 13:02
Example usage for ForwardJump Infusionsoft SDK
<?php
add_action( 'wp_login', 'fj_infusionsoft_api_sample_usage', 10, 2 );
/**
* Adds a user as an Infusionsoft contact after they log in to WordPress.
*
* @param string $user_login WP user login
* @param object $user WP user object
*/
function fj_infusionsoft_api_sample_usage( $user_login, $user ) {
// Instantiates the Infusionsoft object and ensures that we have a valid access token.
<?php
add_filter( 'template_include', 'your_custom_cpt_template', 99 );
/**
* Load an alternative template file for a given post type
*
* @param string $template path to the default template
* @return string $template path to the default template
* @return string $custom_template path to the custom template
*/
function your_custom_cpt_template( $template ) {