Skip to content

Instantly share code, notes, and snippets.

@kstover
kstover / 0_reuse_code.js
Created June 15, 2014 21:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kstover
kstover / export-filtered-subs.php
Last active August 29, 2015 14:18
Exporting filtered submissions using the Ninja Forms Submissions API
<?php
// Build an array that we can use for filtering our submitted data.
$args = array(
// fields is a key in our associative array that means we're looking for field values.
'fields' => array(
// 1 represents our field id and 'Kevin' represents the value we're looking to match.
1 => 'Kevin',
// If you want to filter by multiple fields, you'd add them here.
// 2 => 'checked'
),
@kstover
kstover / NF-Admin-Modal.html
Last active August 29, 2015 14:21
Ninja Forms - Using the NF Admin Modal to create custom admin modal dialogs
<div class="custom-message" style="display:none;"> <!-- adding display:none; will keep the element from flashing on load. -->
<?php _e( 'This setting will COMPLETELY remove anything Ninja Forms related upon plugin deletion. This includes SUBMISSIONS and FORMS. It cannot be undone.', 'ninja-forms' ); ?>
</div>
<div class="custom-message-buttons" style="display:none;"> <!-- the buttons div defines the bottom of the modal.-->
<div id="nf-admin-modal-cancel"> <!-- nf-admin-modal-cancel is the class that aligns the button to the left. -->
<a class="submitdelete deletion modal-close" href="#">Cancel</a>
</div>
<div id="nf-admin-modal-update"> <!-- nf-admin-modal-update is the class that aligns the button to the right. -->
<a class="button-primary" href="#">Continue</a>
</div>
/**
* Force the cookie expiration variant time to 23 minutes
*
* @access public
* @since 2.9.18
* @param int $exp Default expiration (1 hour)
* @return int
*/
public function set_expiration_variant_time( $exp ) {
return 60 * 23;
@kstover
kstover / example-action.php
Created August 13, 2015 19:13
Creating a Custom Action for Ninja Forms
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Class for our custom action type.
*
* @package Ninja Forms
* @subpackage Classes/Actions
* @copyright Copyright (c) 2014, WPNINJAS
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 2.8
*/
<?php
function my_custom_nf_action( $types ) {
$types['my_action'] = PATH_TO_MY_ACTION_CLASS_FILE;
return $types;
}
add_filter( 'nf_notification_types', 'my_custom_nf_action' );
<?php
function bust_godaddy_caching( $url, $form_id ) {
$new_url = add_query_arg( array( 'nocache' => 1 ), $url );
return $new_url;
}
add_filter( 'ninja_forms_ajax_url', 'bust_godaddy_caching', 10, 2 );
<?php
function ninja_forms_custom_display( $form_id ) {
// Output text received from the database before our field output.
$text = get_stuff_from_somewhere_else( $form_id );
echo '<h4>'. $text . '</h4>';
}
add_action( 'ninja_forms_display_before_form', 'ninja_forms_custom_display' );
/*
* This variable holds all of our custom strings for form display.
* It can be accessed and used by our JS code.
*/
var nfDynamicContent = {
beforeForm: '',
beforeFields: '<h4>Please check your fields carefully!</h4>',
afterFields: '',
afterForm: ''
}
<?php
function ninja_forms_custom_display( $before_fields, $form_id ) {
// Output text received from the database before our field output.
$text = get_stuff_from_somewhere_else( $form_id );
$before_fields .= '<h4>'. $text . '</h4>';
return $before_fields;
}
add_filter( 'nf_frontend_before_form', 'ninja_forms_custom_display', 10, 2 );