Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle B. Johnson kjohnson

View GitHub Profile
View gist:ddd59433f2bdaa8be62e9a9c77f2cccd
<?php
// Formatted string.
echo sprintf( 'This is a known %s being translated.', __( 'Translated String' ) );
// Interpolation
extract([
'string' => __( 'Translated String' )
]);
echo "This is a user provided ${string}";
@kjohnson
kjohnson / callback.js
Last active Jan 15, 2020
Caldera Forms Dynamic Processor Setting Example Use
View callback.js
console.log('loaded');
function myDynamicOptionsCallback(resolve, reject){
// alert('Fetching select options');
console.log('Callback start');
setTimeout(function(){
console.log('Resolving');
resolve([
{
value: 'aye',
@kjohnson
kjohnson / plugin.php
Created Oct 11, 2019
Ninja Forms submit:response
View plugin.php
<?php
/**
* Plugin Name: Ninja Forms Sandbox
*/
add_action( 'wp_enqueue_scripts', function() {
wp_enqueue_script('ninja_forms_display_sandbox', plugin_dir_url(__FILE__) . 'script.js', ['nf-front-end'], time() );
});
View functions.php
<?php
add_filter( 'ninja_shop_possible_template_paths', function( $paths ) {
$paths[] = dirname( __FILE__ ) . '/templates/';
return $paths;
} );
View ninja-forms-email-attachments.php
<?php
add_filter( 'ninja_forms_action_email_attachments', function( $attachments, $data, $settings ) {
// Append file path.
$attachments[] = $path_to_file;
return $attachments;
}, 10, 3 );
View dynamic-list-options-add.php
<?php
/**
* Update list options during form render.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options', function( $options, $settings ) {
$options[] = [
View custom-server-side-field-validation.php
<?php
add_filter( 'ninja_forms_submit_data', function( $form_data ){
if( ! my_nf_validation( $form_data ) ) { // Add check here.
$errors = [
'fields' => [
'12' => __( 'An unexpected error occurred.', 'my-plugin' )
],
View dynamic-recaptcha-language-per-form.php
<?php
add_action( 'nf_get_form_id', function( $form_id ) {
if( '12' == $form_id ) {
$recaptcha_lang = 'en';
Ninja_Forms()->update_setting( 'recaptcha_lang', $recaptcha_lang, true );
}
});
View dynamic-default-value-checkbox-full.php
<?php
/**
* Wrap hooks for a specific form.
*
* @param int $form_id
*/
add_action( 'nf_get_form_id', function( $form_id ){
// Check for a specific Form ID.
View dynamic-field-settings-key.php
<?php
/**
* Change a field's settings when localized to the page.
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field', function( $field ){
You can’t perform that action at this time.