Skip to content

Instantly share code, notes, and snippets.

View New0's full-sized avatar

Nico Figueira Mahe New0

View GitHub Profile
@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 / 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-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 / 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 / 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 / last.sql
Last active September 10, 2020 09:24
Last 30 days Interval with comparison symbols
SELECT DISTINCT
account
FROM
messages t
WHERE
t.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY) and t.created_at < NOW()
@New0
New0 / last.sql
Created September 10, 2020 09:53
last 30 days distinct accounts using BETWEEN
SELECT DISTINCT
account
FROM
messages t
WHERE
t.created_at BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) and NOW()
@New0
New0 / nf-subs-management-level.php
Last active November 2, 2021 12:07
Allow editors to manage Ninja Forms > 3.6 Submissions
<?php
/**
* Filter hook used in the API route permission callback to retrieve submissions
*
* return bool as for authorized or not.
*/
add_filter( 'ninja_forms_api_allow_get_submissions', 'nf_define_permission_level', 10, 2 );
add_filter( 'ninja_forms_api_allow_delete_submissions', 'nf_define_permission_level', 10, 2 );
add_filter( 'ninja_forms_api_allow_update_submission', 'nf_define_permission_level', 10, 2 );
add_filter( 'ninja_forms_api_allow_handle_extra_submission', 'nf_define_permission_level', 10, 2 );
@New0
New0 / jwt-whitelist-nf.php
Created April 26, 2022 10:55
Whitelist Ninja Forms routes for JWT auth plugin
<?php
/*
Plugin Name: Whitelist Ninja Forms routes
Plugin URI: https://gist.github.com/New0/7aa904c822604588f3c9066c54de8af9
Description: Whitelist Ninja Forms routes for JWT auth plugin - https://wordpress.org/plugins/jwt-auth/ -
Version: 1.0.0
Author: New0
*/
if ( ! defined( 'ABSPATH' ) ) {
@New0
New0 / nf_consent_hooks.php
Last active June 2, 2022 11:54
DRAFT used for beta testing a precise Ninja Forms Version, leave a comment if interested in testing those hooks.