Plugin URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=readme
Description: Ninja Forms is a webform builder with unparalleled ease of use and features.
Author URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=Plugins+WP+Dashboard
Copyright 2016 WP Ninjas.
require_once dirname( __FILE__ ) . '/lib/NF_VersionSwitcher.php';
require_once dirname( __FILE__ ) . '/lib/NF_Tracking.php';
require_once dirname( __FILE__ ) . '/lib/NF_Conversion.php';
require_once dirname( __FILE__ ) . '/lib/NF_ExceptionHandlerJS.php';
require_once dirname( __FILE__ ) . '/lib/Conversion/Calculations.php';
require_once dirname( __FILE__ ) . '/includes/Integrations/sendwp.php';
// Services require PHP v5.6+
if( version_compare( PHP_VERSION, '5.6', '>=' ) ) {
include_once dirname( __FILE__ ) . '/services/bootstrap.php';
function ninja_forms_three_table_exists(){
$table_name = $wpdb->prefix . 'nf3_forms';
return ( $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name );
if( get_option( 'ninja_forms_load_deprecated', FALSE ) && ! ( isset( $_POST[ 'nf2to3' ] ) && ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) ){
include 'deprecated/ninja-forms.php';
register_activation_hook( __FILE__, 'ninja_forms_activation_deprecated' );
function ninja_forms_activation_deprecated( $network_wide ){
include_once 'deprecated/includes/activation.php';
ninja_forms_activation( $network_wide );
include_once 'lib/NF_Upgrade.php';
include_once 'lib/NF_AddonChecker.php';
include_once plugin_dir_path( __FILE__ ) . 'includes/deprecated.php';
const VERSION = '3.4.33';
const DB_VERSION = '1.4';
const WP_MIN_VERSION = '5.0';
private static $instance;
* Plugin Database Version
* This may be overwritten at a later point in this file.
* @var string $db_version
public static $db_version = self::DB_VERSION;
public $controllers = array();
public $fields = array();
public $actions = array();
public $merge_tags = array();
public $metaboxes = array();
protected $_dispatcher = '';
protected $settings = array();
protected $requests = array();
protected $processes = array();
* Main Ninja_Forms Instance
* Insures that only one instance of Ninja_Forms exists in memory at any one
* time. Also prevents needing to define globals all over the place.
* @staticvar array $instance
* @return Ninja_Forms Highlander Instance
public static function instance()
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Ninja_Forms ) ) {
self::$instance = new Ninja_Forms;
self::$dir = plugin_dir_path( __FILE__ );
// Define old constants for backwards compatibility.
if( ! defined( 'NF_PLUGIN_DIR' ) ){
define( 'NF_PLUGIN_DIR', self::$dir );
define( 'NINJA_FORMS_DIR', self::$dir . 'deprecated' );
self::$url = plugin_dir_url( __FILE__ );
if( ! defined( 'NF_PLUGIN_URL' ) ){
define( 'NF_PLUGIN_URL', self::$url );
$saved_version = get_option( 'ninja_forms_version' );
// If we have a recorded version...
// AND that version is less than our current version...
if ( $saved_version && version_compare( $saved_version, self::VERSION, '<' ) ) {
// *IMPORTANT: Filter to delete old bad data.
// Leave this here until at least 3.4.0.
if ( version_compare( $saved_version, '3.3.7', '<' ) && version_compare( $saved_version, '3.3.4', '>' ) ) {
delete_option( 'nf_sub_expiration' );
// We just upgraded the plugin.
update_option( 'ninja_forms_version', self::VERSION );
// If we've not recorded our db version...
if ( ! get_option( 'ninja_forms_db_version' ) ) {
// If this isn't a fresh install...
// AND If we're upgrading from a version before 3.3.0...
if ( $saved_version && version_compare( $saved_version, '3.3.0', '<' ) ) {
// Set it to the baseline (1.0) so that our upgrade process will run properly.
add_option( 'ninja_forms_db_version', '1.0', '', 'no' );
} // OR If this isn't a fresh install...
elseif ( $saved_version ) {
// Set it to the expected (1.1) so that our upgrade process will handle that.
add_option( 'ninja_forms_db_version', '1.1', '', 'no' );
} // Otherwise... (This is a fresh install.)
// Set it to the current DB version.
add_option( 'ninja_forms_db_version', self::DB_VERSION, '', 'no' );
// Establish that our upgrades don't need to take place.
$required_updates = Ninja_Forms()->config( 'RequiredUpdates' );
date_default_timezone_set( 'UTC' );
$now = date( "Y-m-d H:i:s" );
foreach( $required_updates as $slug => $update ) {
$updated[ $slug ] = $now;
update_option( 'ninja_forms_required_updates', $updated );
// Set our static db version.
self::$db_version = get_option( 'ninja_forms_db_version', self::$db_version );
* Register our autoloader
spl_autoload_register( array( self::$instance, 'autoloader' ) );
self::$instance->menus[ 'forms' ] = new NF_Admin_Menus_Forms();
self::$instance->menus[ 'dashboard' ] = new NF_Admin_Menus_Dashboard();
self::$instance->menus[ 'add-new' ] = new NF_Admin_Menus_AddNew();
self::$instance->menus[ 'submissions'] = new NF_Admin_Menus_Submissions();
self::$instance->menus[ 'import-export'] = new NF_Admin_Menus_ImportExport();
self::$instance->menus[ 'settings' ] = new NF_Admin_Menus_Settings();
self::$instance->menus[ 'licenses'] = new NF_Admin_Menus_Licenses();
self::$instance->menus[ 'system_status'] = new NF_Admin_Menus_SystemStatus();
self::$instance->menus[ 'add-ons' ] = new NF_Admin_Menus_Addons();
self::$instance->menus[ 'divider'] = new NF_Admin_Menus_Divider();
self::$instance->menus[ 'mock-data'] = new NF_Admin_Menus_MockData();
self::$instance->controllers[ 'form' ] = new NF_AJAX_Controllers_Form();
self::$instance->controllers[ 'fields' ] = new NF_AJAX_Controllers_Fields();
self::$instance->controllers[ 'batch_process' ] = new NF_AJAX_REST_BatchProcess();
self::$instance->controllers[ 'required_updates' ] = new NF_AJAX_REST_RequiredUpdate();
self::$instance->controllers[ 'preview' ] = new NF_AJAX_Controllers_Preview();
self::$instance->controllers[ 'submission' ] = new NF_AJAX_Controllers_Submission();
self::$instance->controllers[ 'savedfields' ] = new NF_AJAX_Controllers_SavedFields();
self::$instance->controllers[ 'deletealldata' ] = new NF_AJAX_Controllers_DeleteAllData();
self::$instance->controllers[ 'jserror' ] = new NF_AJAX_Controllers_JSError();
self::$instance->controllers[ 'dispatchpoints' ] = new NF_AJAX_Controllers_DispatchPoints();
self::$instance->controllers[ 'REST' ][ 'forms' ] = new NF_AJAX_REST_Forms();
self::$instance->controllers[ 'REST' ][ 'new-form-templates' ] = new NF_AJAX_REST_NewFormTemplates();
require_once Ninja_Forms::$dir . 'includes/Libraries/BackgroundProcessing/classes/wp-async-request.php';
self::$instance->requests[ 'delete-field' ] = new NF_AJAX_Requests_DeleteField();
require_once Ninja_Forms::$dir . 'includes/Libraries/BackgroundProcessing/wp-background-processing.php';
self::$instance->requests[ 'update-fields' ] = new NF_AJAX_Processes_UpdateFields();
if( class_exists( 'WP_CLI_Command' ) ) {
WP_CLI::add_command('ninja-forms', 'NF_WPCLI_NinjaFormsCommand');
self::$instance->preview = new NF_Display_Preview();
add_filter('template_include', array(self::$instance, 'maybe_load_public_form'));
self::$instance->shortcodes = new NF_Display_Shortcodes();
new NF_Admin_CPT_Submission();
new NF_Admin_CPT_DownloadAllSubmissions();
require_once Ninja_Forms::$dir . 'lib/StepProcessing/menu.php';
require_once Ninja_Forms::$dir . 'blocks/ninja-forms-blocks.php';
new NF_Admin_Metaboxes_Calculations();
* User data requests ( GDPR actions )
new NF_Admin_UserDataRequests();
self::$instance->_logger = new NF_Database_Logger();
self::$instance->_dispatcher = new NF_Dispatcher();
self::$instance->merge_tags[ 'wp' ] = new NF_MergeTags_WP();
self::$instance->merge_tags[ 'fields' ] = new NF_MergeTags_Fields();
self::$instance->merge_tags[ 'calcs' ] = new NF_MergeTags_Calcs();
self::$instance->merge_tags[ 'form' ] = new NF_MergeTags_Form();
self::$instance->merge_tags[ 'other' ] = new NF_MergeTags_Other();
self::$instance->merge_tags[ 'deprecated' ] = new NF_MergeTags_Deprecated();
self::$instance->add_form_modal = new NF_Admin_AddFormModal();
self::$instance->_eos[ 'parser' ] = require_once 'includes/Libraries/EOS/Parser.php';
self::$instance->settings = apply_filters( 'ninja_forms_settings', get_option( 'ninja_forms_settings' ) );
self::$instance->notices = new NF_Admin_Notices();
self::$instance->widgets[] = new NF_Widget();
self::$instance->tracking = new NF_Tracking();
self::$instance->submission_expiration_cron = new NF_Database_SubmissionExpirationCron();
* TODO: Review PR#2492 for improvements.
// self::$instance->exception_handler_js = new NF_ExceptionHandlerJS();
* TODO: Move to a permanent home.
register_activation_hook( __FILE__, array( self::$instance, 'activation' ) );
self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm();
$email_telemetry = new NF_EmailTelemetry( get_option( 'ninja_forms_optin_reported' ) );
$email_telemetry->setup();
* Require EDD auto-update file
if( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
// Load our custom updater if it doesn't already exist
require_once( self::$dir . 'includes/Integrations/EDD/EDD_SL_Plugin_Updater.php');
require_once self::$dir . 'includes/Integrations/EDD/class-extension-updater.php';
// If Ninja Forms was just upgraded...
// Ensure all of our tables have been defined.
$migrations = new NF_Database_Migrations();
add_action( 'init', array( self::$instance, 'flush_rewrite_rules' ) );
// Enable "Dev Mode" for existing installations.
$settings = Ninja_Forms()->get_settings();
if( ! isset($settings['builder_dev_mode'])){
Ninja_Forms()->update_setting('builder_dev_mode', 1);
add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
add_action( 'plugins_loaded', array( self::$instance, 'plugins_loaded' ) );
add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) );
add_action( 'init', array( self::$instance, 'init' ), 5 );
add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 );
add_action( 'nf_weekly_promotion_update', array( self::$instance, 'nf_run_promotion_manager' ) );
add_action( 'activated_plugin', array( self::$instance, 'nf_bust_promotion_cache_on_plugin_activation' ), 10, 2 );
// Checks php version and..
if (version_compare(PHP_VERSION, '7.2.0', '<')) {
// Pulls in the whip notice if the user is.
add_action( 'admin_init', array( self::$instance, 'nf_php_version_whip_notice' ) );
add_action( 'admin_init', array( self::$instance, 'nf_do_telemetry' ) );
add_action( 'admin_init', array( self::$instance, 'nf_plugin_add_suggested_privacy_content' ), 20 );
do_action( 'nf_init', self::$instance );
$this->register_rewrite_rules();
public function flush_rewrite_rules()
$this->register_rewrite_rules();
public function register_rewrite_rules()
add_rewrite_tag('%nf_public_link%', '([a-zA-Z0-9]+)');