Skip to content

Instantly share code, notes, and snippets.

View New0's full-sized avatar

Nicolas Figueira New0

View GitHub Profile
@New0
New0 / cf-remove-backslash.php
Last active February 14, 2020 16:01
Remove backslash from parsed data of bracket magic tags in Caldera Forms
<?php
/*
* This is very basic, you may want to target a precise $form, $magics or type of $value using conditions.
*/
add_filter( 'caldera_forms_do_field_bracket_value', function($value, $magics, $entry_id, $form ){
return implode("",explode("\\",$value));
}, 10, 4);
@New0
New0 / cf-set-browser-details.php
Created February 6, 2020 11:18
Set the browser details "HTTP_USER_AGENT" in a Caldera Forms hidden field
<?php
/*
* Set the HTTP_USER_AGENT as the value of a hidden field during submission
* In this case the hidden field ID is fld_7526079, that needs to be edited
*/
add_filter( 'caldera_forms_process_field_hidden', function( $value, $field ) {
//Change your field ID here
if( $field['ID'] === "fld_7526079" ){
$value = $_SERVER['HTTP_USER_AGENT'];
@New0
New0 / cf-stripe-pi-description.php
Last active January 30, 2020 13:52
Display a description for the payment on the Stripe interface. Requires Caldera Forms Stripe add-on
<?php
/*
* Plugin Name: CF Stripe Payment description
* Author: Nicolas Figueira
* Descriptipon: Display the description in the payments on the Stripe dashboard
*
*/
add_filter( 'cf_stripe_charge_args', function( $args, $config, $form ){
//The description can also be set to be different from the processor's settings
@New0
New0 / cf-caldera_forms_field_attributes-ssn-pattern.php
Created January 7, 2020 20:20
Social security number pattern for Caldera Forms single line text fields
<?php
/*
* Validates fields only using a Social security number pattern like 999-99-999
* EDIT FIELDS IDS TO BE VALIDATED "fld_5675945", "fld_1648505"
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
$fields = ["fld_5675945", "fld_1648505"];
if( in_array( $field['ID'], $fields ) ){
$attrs[ 'pattern' ] = '^\d{3}-\d{2}-\d{4}';
}
@New0
New0 / cf-user-entry-viewer.php
Created January 7, 2020 16:24
Allow a precise user to read form the caldera forms entry viewer
<?php
/*
* This will allow a user with ID 2 to view the entry viewer even without the manage_optiuons capability
* REPLACE 2 by the correct user ID
*/
add_filter('caldera_forms_manage_cap', function( $cap, $context, $form ){
if( is_user_logged_in() ){
$user_id = get_current_user_id();
@New0
New0 / ds-custom-button.php
Created June 30, 2018 09:32
Custom plugin to filter Direct Stripe button markup
<?php
/*
* Plugin Name: Direct Stripe Custom Button
*/
//Set Styles settings not to use custom or Stripe styles
//Filters added in Direct Stripe 2.1.5 ( List of Actions and filters https://newo.me/direct-stripe-actions-and-filters-hooks/ )
add_filter('direct_stripe_div_before', function( $div, $button_id, $class ){
if( $button_id !== 'MyButtonID'){ //Set a Button ID in the Button Settings to target only this Button
<?php
//this applies change when creating plans
add_filter( 'cf_stripe_recurring_args', 'my_cf_stripe_recurring_filter', 10, 2 );
//this applies change when creating one time payments
add_filter( 'cf_stripe_charge_args', 'my_cf_stripe_single_filter', 10, 2 );
//this is the callback to change arguments sent to API
//Be careful not to set a field that isn't supported or the API will reject the charge.
//Description for single payments
<?php
/**
* Change Caldera Forms Stripe Payment Amount
*/
add_filter( 'cf_stripe_charge_args', function( $args, $config, $form ){
//change charge amounts to $10. Amount is in cents.
$args["line_items"][0][ "amount" ] = 1000;
return $args;
}, 10, 4 );
@New0
New0 / cf-limit-option-submissions.php
Created December 9, 2019 09:38
Use cf_entry_limiter_entry_limit filter hook for select fields with multiple choices allowed
<?php
/**
* Allow different field values of same field to have different limits when using Caldera Forms Entry Limitter
*
* Requires version 1.2.0 or later
*/
add_filter( 'cf_entry_limiter_entry_limit', function( $limit, $entry, $field, $form ){
//IMPORTANT: Change fld_9970286 to your field's ID
if( 'fld_9970286' === $field[ 'ID' ] ){
//IMPORTANT: Use the field values (not labels) in these conditionals
@New0
New0 / cf-tabindex-radio-options.php
Last active November 19, 2019 15:44
//Example of adding a tabindex to radio fields options in Caldera Forms
<?php
/**
* Plugin Name: CF tabindex on radio options
* Autor: New0
* Description: Add tabindex on options of radio fields in CF
*/
//Example of adding a tabindex to radio fields options in Caldera Forms
// If there are multiple radio fields on same page, target each field using the field ID between caldera-grid and radio classes.
//Like ".caldera-grid #fld_8471527_1-wrap .radio label input" replacing #fld_8471527 by the field ID ( and keeping _1-wrap attached).