Skip to content

Instantly share code, notes, and snippets.

View New0's full-sized avatar

Nicolas Figueira New0

View GitHub Profile
@New0
New0 / RecentlyUsedAccounts.php
Last active September 9, 2020 15:57
Query recent messages
<?php
namespace App\Console\Commands;
use App\Message;
use Carbon\Carbon;
use Illuminate\Console\Command;
class RecentlyUsedAccounts extends Command
{
/**
@New0
New0 / caldera_forms_shortcodes.txt
Created July 2, 2020 08:48
Caldera Forms shortcodes
A regular Form
[caldera_form id="CF54ce83dd431a1"]
A Form that will open as a Modal, formatted as a link taking the name of the Form as text.
[caldera_form_modal id="CF54ce83dd431a1"]
A Form that will open as a Modal, formatted as a button with text defined in the shortcode
[caldera_form_modal id="CF54ce83dd431a1" type="button"]Open Form[/caldera_form_modal]
@New0
New0 / cf-post-id-user.php
Created June 30, 2020 10:30
Caldera Forms using Custom fields add-on, save the new Post ID as User meta data.
<?php
/** Hook in when custom fields are saved by CF Custom fields to write entry ID as user meta */
add_action( 'cf_custom_fields_post_save_meta_key_to_post_type', function($value, $slug, $post_id, $field, $form){
if( $slug === "meta_post_id" ){
if( $value === $post_id){
return;
} else {
update_user_meta( get_current_user_id(), "meta_post_id", $post_id );
}
}
@New0
New0 / easy_pods_content.php
Last active June 15, 2020 08:09
Using Easy Pods function in the_content filter hook to display the query instead of using the shortcode.
<?php
//EDIT easy_pods_name with the correct name of the easy pods
add_filter('the_content', function($content) {
// Check if we're inside the post 661
if ( get_the_ID() === 661 ) {
return $content . cep_render_easy_pod( 'easy_pods_name' );
}
return $content;
@New0
New0 / cf-entry-id-column.php
Last active May 29, 2020 08:17
Add the entry ID on CSV Entries export
<?php
// Based on https://calderaforms.com/doc/caldera_forms_admin_csv/
add_filter( 'caldera_forms_admin_csv', function( $csv_data, $form ){
//IMPORTANT change form ID to match your form
if( 'CF5eb5616ea264f' === $form[ 'ID' ] ){
//Add a header for new column
$csv_data[ 'headers' ] = ['entry_id' => 'Entry ID'] + $csv_data[ 'headers' ];
//Add a value for each row for this new column
@New0
New0 / cf-min-html5-date.php
Created May 26, 2020 15:00
Set the Caldera Forms text field with date Type to only allow future dates to be picked.
<?php
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field ){
//EDIT FIELD ID
if( $field['ID'] === "fld_7194486" ){
$attrs[ 'min' ] = date("Y-m-d");
}
return $attrs;
@New0
New0 / cf-reset-form-stripe-cancelation.php
Last active May 21, 2020 09:57
Reset Form after Stripe transaction cancelled in Caldera Forms
<?php
/**
* Plugin Name: Caldera Forms manage Stripe cancelation
* Description: Dispay a link that resets the form when returning from Stripe cancellation.
* Plugin URL: https://gist.github.com/New0/65b1b0dc194c23703e935a0fc22268a1
* Author: New0
*/
add_filter( 'caldera_forms_pre_render_form', function( $html, $entry_id, $form ){
//Check if we come back from Stripe with cancelled status
@New0
New0 / cf-stripe-transients-durantion.php
Last active May 8, 2020 10:20
Set custom duration for Caldera Forms Stripe sessions to be correctly recorded ( since add-on version 1.4.11 )
<?php
/**
* Plugin Name: Stripe session transients duration
* Description: Customize duration for Form entries to be stored.
* Author: New0
*
*/
//Set the time in seconds ( here 15 * 60 converts to 15 minutes )
add_filter("cf_stripe_transients_status_duration", function() {
return 15 * 60;
<?php
/**
* caldera_forms_api_allow_pdf_download
*
* Control how it is allowed to download the PDF files
*
* @param boolean $allowed
* @param array $request
*/
add_filter("caldera_forms_api_allow_pdf_download", function($allowed, $request ) {
@New0
New0 / cf-pdf-template.html
Last active April 17, 2020 09:59
HTML template example that can be used in the editor for Caldera Forms emails and PDF Submissions
<div style="text-align: center; font-size: 2em;">
<div style="border: 5px solid #b3e6ff; padding: 2% 3% 2% 3%; max-width: 650px; margin: 1% auto 1% auto; background-color: #b3e6ff; color: white;">My PDF Submission</div>
<div></div>
</div>
<div style="text-align: left; font-size: 1.2em;">
<div style="border: 2px solid #b3e6ff; padding: 2% 3% 2% 3%; max-width: 650px; margin: 1% 10% 1% 10%; background-color: white; color: black;">
<p style="text-align: center;">
Hello %first_name% %last_name%