Skip to content

Instantly share code, notes, and snippets.

View klhall1987's full-sized avatar

Kenny Hall klhall1987

View GitHub Profile
@klhall1987
klhall1987 / MergeTags.php
Created August 22, 2018 18:04
Merge tag class with callback
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Class NF_MergeTagExample_MergeTags
*/
final class NF_MergeTagExample_MergeTags extends NF_Abstracts_MergeTags
{
protected $id = 'mergetag-example';
public function __construct()
@klhall1987
klhall1987 / MergeTags.php
Created August 22, 2018 18:03
Merge Tag Config Example
<?php if ( ! defined( 'ABSPATH' ) ) exit;
return apply_filters( 'ninja_forms_register_user_settings', array(
'example_tag' => array(
'id' => 'example_tag',
'tag' => '{mergetag_example:example_tag}',
'label' => __( 'Example Tag', 'ninja-forms-mergetag-example' ),
'callback' => 'example_tag',
),
@klhall1987
klhall1987 / MergeTags.php
Created August 22, 2018 18:03
Merge Tag Config Example
<?php if ( ! defined( 'ABSPATH' ) ) exit;
return apply_filters( 'ninja_forms_register_user_settings', array(
'example_tag' => array(
'id' => 'example_tag',
'tag' => '{mergetag_example:example_tag}',
'label' => __( 'Example Tag', 'ninja-forms-mergetag-example' ),
'callback' => 'example_tag',
),
@klhall1987
klhall1987 / addon_base_class.php
Last active August 22, 2018 18:02
Register Merge Tags example
<?php
public function __construct()
{
/*
* Required for all Extensions.
*/
add_action( 'admin_init', array( $this, 'setup_license') );
// Call our register merge tags method.
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Class NF_MergeTagExample_MergeTags
*/
final class NF_MergeTagExample_MergeTags extends NF_Abstracts_MergeTags
{
protected $id = 'mergetag_example';
public function __construct()
@klhall1987
klhall1987 / ninja-forms-permissions-submissions.php
Last active July 4, 2020 09:38
ninja-forms-submission-permissions.php
<?php
// Must use all three filters for this to work properly.
add_filter( 'ninja_forms_admin_parent_menu_capabilities', 'nf_subs_capabilities' ); // Parent Menu
add_filter( 'ninja_forms_admin_all_forms_capabilities', 'nf_subs_capabilities' ); // Forms Submenu
add_filter( 'ninja_forms_admin_submissions_capabilities', 'nf_subs_capabilities' ); // Submissions Submenu
function nf_subs_capabilities( $cap ) {
return 'edit_posts'; // EDIT: User Capability
}
@klhall1987
klhall1987 / formSubmit.js
Last active April 15, 2020 18:17
Example of how to use the .on formSubmit listener.
<script>
jQuery( document ).ready( function() {
//Setup our on formSumbit Listener.
jQuery( document ).on( 'nfFormSubmitResponse', function() {
//Do Stuff
ga('send', 'event', 'Email List', 'Subscribed', 'New Subscriber');
});
});
</script>
<?php
/*
Plugin Name: Default Value Example
*/
add_filter( 'ninja_forms_render_default_value', 'test', 10, 3 );
function test( $default_value, $field_class, $field_settings )
{
if( 'textbox' == $field_settings[ 'type' ] ) {
@klhall1987
klhall1987 / index.php
Last active October 24, 2019 10:40
Make Translatable strings with Ninja Forms Date Picker.
<?php
/*
Plugin Name: Date Picker test
*/
add_filter( 'ninja_forms_enqueue_scripts', 'nf_datepicker_options' );
function nf_datepicker_options()
{
wp_enqueue_script( 'nf_datepicker_options', plugin_dir_url( __FILE__ ) . 'script.js', array( 'jquery' ), false, true );
add_filter( 'ninja_forms_render_default_value', 'my_change_nf_default_value', 10, 3 );
function my_change_nf_default_value( $default_value, $field_type, $field_settings ) {
if( 'your_field_key' == $field_settings[ 'key' ] ){
$default_value = 'foo';
}
return $default_value;