Skip to content

Instantly share code, notes, and snippets.

@Idealien
Idealien / php
Created September 23, 2014 03:16
GF Entry Manipulation
<?php
add_filter("gform_after_submission", "post_form_anonymize", 10 , 2);
//Gravity Form Submission
function post_form_anonymize($entry, $form){
$cssClasses = preg_split('/[\ \n\,]+/', $form['cssClass']);
if (in_array("anonymize", $cssClasses)) {
RGFormsModel::update_lead_property($entry['id'], "created_by","1");
RGFormsModel::update_lead_property($entry['id'], "ip","XXX.YYY.XXX.YYY");
@Idealien
Idealien / gflow-complete-step-function.php
Last active March 29, 2018 06:33
Gravity Flow - Different ways to have workflow step(s) trigger post status update
//Update after each step completion - probably executes too often for most use cases
add_action( 'gravityflow_step_complete', 'gravityflow_step_complete_post_publish', 10, 4 );
function gravityflow_step_complete_post_publish( $step_id, $entry_id, $form_id, $status ) {
$entry = GFAPI::get_entry( $entry_id );
$currentPost = get_post( rgar( $entry, 'post_id' ) );
if("draft" == $currentPost->post_status) {
@Idealien
Idealien / functions.php
Last active December 11, 2017 08:10
Gravity Forms - Tally Common Questions in Merge Tag
<?php
add_filter( 'gform_replace_merge_tags', array(&$this, "replace_tally_results"), 10, 7 );
function replace_tally_results( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
$custom_merge_tag = '{tally_results}';
if ( strpos( $text, $custom_merge_tag ) === false ) {
return $text;
}
$score = array();
foreach($form['fields'] as $field) {
@Idealien
Idealien / wpallimport - functions.php
Created May 19, 2016 17:45
WP All Import - Users - Maintain multiple roles in wp_capabilities user meta
<?php
function ipost_import_roles($employee_ID) {
$user_query = new WP_User_Query( array( 'meta_key' => 'employee_id', 'meta_value' => $employee_ID ) );
$defaultRole = array("employee" => true);
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
if( $user->roles ) {
$roles = $defaultRole;
foreach( $user->roles as $role ) {
@Idealien
Idealien / step3A-functions.php
Last active December 11, 2017 08:09
ACF + Rest API = Powerful!
<?php
//REST API - Enable more fields to be searched via Rest API
add_filter( 'rest_query_vars', function ( $valid_vars ) {
$update_vars = $valid_vars;
//Vehicle Meta Data
$update_vars = array_merge( $update_vars, array( 'make', 'meta_query' ) );
$update_vars = array_merge( $update_vars, array( 'model', 'meta_query' ) );
return $update_vars;
(function($) {
acf.add_action('ready', function( $el ){
//Identify the field you want to check against.
//Use a class to handle scenarios involving repeater / flexible content where multiple instances exist
var $field = $('.example input');
$field.on('change', function (evt) {
@Idealien
Idealien / bash.sh
Created October 31, 2016 21:56
WP Gravity Forms CLI - Entry Generation for Workflows
#!/bin/bash
INPUT=input_filename.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read reviewer employee
do
f10=$(wp user get $reviewer --field=ID)
f11=$(wp user get $employee --field=ID)
f14=$(wp user meta get $employee user_meta_field_name)
@Idealien
Idealien / functions.php
Created November 2, 2016 23:54
WP Gravity Flow Bulk Creation for Import Plugin Processing
<?php
//replace ## with your form ID - and also update field IDs with your appropriate numbers.
add_action( "gform_pre_submission_##", "employee_lookup_and_assignment", 10, 1 );
function employee_lookup_and_assignment( $form ) {
$reviewer = get_user_by( 'email', rgpost( 'input_12' ));
if( $reviewer ):
$_POST['input_10'] = "user_id|" . $reviewer->ID;
endif;
<?php
add_action( 'rest_api_init', 'rest_register_game_meta' );
function rest_register_game_meta() {
//For generic fields that should never allow front-end updates
$restArgsDisplay = array(
'get_callback' => 'rest_get_game_meta',
'update_callback' => null,
'schema' => null,
@Idealien
Idealien / screenshot_checkbox.jpg
Last active March 25, 2017 18:23
Images for CMB2
screenshot_checkbox.jpg