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 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 / acf-local-json.php
Last active June 4, 2018 11:12
Use ACF local JSON file for get_all_custom_field_meta().
<?php
// Replace with the name of your field group JSON.
$field_group_json = 'group_59e226a200966.json';
$field_group_array = json_decode( file_get_contents( get_stylesheet_directory() . "/acf-json/{$field_group_json}" ), true );
// Omit this line when using the Field Group Values package/plugin.
$config = $field_group_array['fields'];
@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.
<?php
add_filter( 'enter_title_here', function( $title ) {
$screen = get_current_screen();
if ( 'your_custom_post_type' == $screen->post_type ){
$title = 'Your custom placeholder text';
}
return $title;
@timothyjensen
timothyjensen / searchform.php
Created October 13, 2017 11:18
Modify the standard WordPress search form to perform faceted search.
<?php
add_filter( 'get_search_form', 'prefix_render_faceted_search_form' );
/**
* Adds checkboxes to the search form for searching specific post types.
*
* @param string $form The search form HTML output.
*
* @return string
*/
function prefix_render_faceted_search_form( $form ) {
@timothyjensen
timothyjensen / functions.php
Last active June 20, 2017 15:40
$wpdb->prepare for SQL IN statements
<?php
$data_types = [ 'data_item_one', 'data_item_two' ];
// Props to @hellofromtonya for this.
$data_type_placeholders = implode( ', ', array_fill( 0, count( $data_types ), '%s' ) );
global $wpdb;
$query = "
SELECT pm.post_id, pm.meta_key, pm.meta_value
@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.
@timothyjensen
timothyjensen / contact.html
Created April 23, 2017 19:39 — forked from atcraigwatson/contact.html
Bootstrap Ajax Contact Form
<form id="contact-form" method="post" action="mailer.php" role="form">
<div class="messages"></div>
<div class="controls">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="form_name">Firstname *</label>
@timothyjensen
timothyjensen / functions.php
Created April 12, 2017 16:41
CMB2 on Genesis Archive Settings.
<?php
add_action( 'cmb2_admin_init', 'yourprefix_register_demo_metabox' );
/**
* Creating a metabox for a Genesis CPT Archive Settings page, where the CPT is 'webinars'.
*/
function yourprefix_register_demo_metabox() {
/**
* Sample metabox to demonstrate each field type included
@timothyjensen
timothyjensen / outside-structural-wrap.php
Last active March 24, 2017 22:20 — forked from hellofromtonya/before-structural-wrap.php
Insert HTML before or after the Genesis structural wrap for the given contextual area.
<?php
add_action( 'genesis_meta', 'process_structural_wrap_handler' );
/**
* Process the structural wrap handler.
*
* @since 1.0.0
*
* @return void
*/
function process_structural_wrap_handler() {