Skip to content

Instantly share code, notes, and snippets.

View New0's full-sized avatar

Nicolas Figueira New0

View GitHub Profile
@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 / cf-show-pro-ui.php
Last active January 26, 2023 00:49
Show Pro settings in Caldera Forms if disconnected ( this can be activated as a WordPress plugin using the Download Zip button )
<?php
/**
* Plugin Name: CF Show Pro UI
* Description: Show Caldera Forms pro settings
* Author: Caldera Forms
**/
//Force Pro settings to show
add_filter('caldera_forms_show_pro_ui', '__return_true');
<?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).
@New0
New0 / cf-custom-code.php
Created November 8, 2019 11:38
Replace text in CF Connected Forms buttons
<?php
/*
* Plugin Name: CF custom code
* Author: New0
* Description: Force connected Submit button text if translation didn't apply
*/
add_action('wp_footer', function() {
?>
<script type="text/javascript">
@New0
New0 / cf-allow-all-viewers.php
Last active November 1, 2019 08:49
Allow all users (non logged-in) to view the Caldera Forms entry for a prcise form.
<?php
/*
* Plugin Name: CF allow all viewers
* Author: New0
* Description: Allow all requests to read entries of form with ID CF5c78740daac4a
*/
/**
* For API endpoint that powers front-end entry viewer.
*/
@New0
New0 / DS-filter-emails.php
Last active October 27, 2019 09:28
To be installed as a plugin - Filter Emails sent by Direct Stripe
<?php
/*
* Plugin Name: Direct Stripe Filter Emails
* Description: Filter Emails sent by Direct Stripe
* Author: New0
* Author URI: https://newo.me/
* Version: 0.0.1
*/
add_filter( 'direct_stripe_success_user_email_content', function( $message, $amount, $currency, $email_address, $description, $user, $button_id ){