: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
add_rewrite_tag('%nf_public_link%', '([a-zA-Z0-9]+)');
add_rewrite_rule('^ninja-forms/([a-zA-Z0-9]+)/?', 'index.php?nf_public_link=$matches[1]', 'top');
public function admin_init()
do_action( 'nf_admin_init', self::$instance );
if ( isset ( $_GET[ 'nf-upgrade' ] ) && 'complete' == $_GET[ 'nf-upgrade' ] ) {
Ninja_Forms()->dispatcher()->send( 'upgrade' );
add_filter( 'ninja_forms_dashboard_menu_items', array( $this, 'maybe_hide_dashboard_items' ) );
// Remove already completed updates from our filtered list of required updates.
add_filter( 'ninja_forms_required_updates', array( $this, 'remove_completed_updates' ), 99 );
add_filter( 'ninja_forms_required_updates', array( $this, 'remove_bad_updates' ), 99 );
// Sets up a weekly cron to run the promotion manager.
if ( ! wp_next_scheduled( 'nf_weekly_promotion_update' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'nf-weekly', 'nf_weekly_promotion_update' );
// Get our list of required updates.
$required_updates = Ninja_Forms()->config( 'RequiredUpdates' );
$sql = "SELECT COUNT( `id` ) AS total FROM `{$wpdb->prefix}nf3_forms`;";
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
$threshold = 0; // Threshold percentage for our required updates.
if ( get_transient( 'ninja_forms_prevent_updates' ) ) {
update_option( 'ninja_forms_needs_updates', 0 );
// If we got back a list of updates...
// AND If we have any forms on the site...
// AND If the gate is open...
// To avoid errors on older upgrades, ignore the gatekeeper if the db version is the baseline (1.0)...
elseif ( ! empty( $required_updates )
&& 0 < $result[ 0 ][ 'total' ]
&& ( WPN_Helper::gated_release( $threshold )
|| '1.0' == self::$db_version ) ) {
// Record that we have updates to run.
update_option( 'ninja_forms_needs_updates', 1 );
} // Otherwise... (Sanity check)
// Record that there are no required updates.
update_option( 'ninja_forms_needs_updates', 0 );
function maybe_load_public_form($template) {
if($public_link_key = sanitize_text_field(get_query_var('nf_public_link'))){
// @TODO Move this functionality behind a boundry.
$query = $wpdb->prepare( "SELECT `parent_id` FROM {$wpdb->prefix}nf3_form_meta WHERE `key` = 'public_link_key' AND `value` = %s", $public_link_key );
$results = $wpdb->get_col($query);
$form_id = reset($results);
$page_template = get_page_template();
if( ! empty( $page_template ) )
$template = $page_template;
new NF_Display_PagePublicLink($form_id);
* Privacy policy suggested content for Ninja Forms
function nf_plugin_add_suggested_privacy_content() {
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) return;
$content = $this->plugin_get_default_privacy_content();
wp_add_privacy_policy_content(
wp_kses_post( wpautop( $content, false) ) );
* Return the default suggested privacy policy content.
* @return string The default policy content.
function plugin_get_default_privacy_content() {
'<h2>' . esc_html__( 'Ninja Forms allows you to collect personal information', 'ninja-forms' ) . '</h2>' .
'<p>' . esc_html__( 'If you are using Ninja Forms to collect personal information, you should consult a legal professional for your use case.', 'ninja-forms' ) . '</p>';
* NF PHP Version Whip Notice
* If the user is on a version below PHP 7.2 then we get an instance of the
* NF PHP Version Whip class which will add a non-dismissible admin notice.
* @return NF_Php_Version_Whip
public function nf_php_version_whip_notice()
require_once self::$dir . '/includes/Libraries/Whip/NF_Php_Version_Whip.php';
return new NF_Php_Version_Whip();
* Function to launch our various telemetry calls on admin_init.
public function nf_do_telemetry() {
if ( ! has_filter( 'ninja_forms_settings_licenses_addons' ) && ( ! Ninja_Forms()->tracking->is_opted_in() || Ninja_Forms()->tracking->is_opted_out() ) ) {
// If we've not already sent table collation...
if ( ! get_option( 'nf_tel_collate' ) ) {
// Get the collation of the wp_options table.
$sql = "SHOW FULL COLUMNS FROM `" . $wpdb->prefix . "options` WHERE Field = 'option_value'";
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
$collate[ 'cache' ] = $result[ 0 ][ 'Collation' ];
// Get the collation of the nf3_forms table.
$sql = "SHOW FULL COLUMNS FROM `" . $wpdb->prefix . "nf3_forms` WHERE Field = 'title'";
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
$collate[ 'forms' ] = $result[ 0 ][ 'Collation' ];
// Send our data to api.ninjaforms.com.
Ninja_Forms()->dispatcher()->send( 'table_collate', $collate );
// Record an option so that we don't run this again.
add_option( 'nf_tel_collate', '1', '', 'no' );
public function maybe_hide_dashboard_items( $items )
$disable_marketing = false;
if ( apply_filters( 'ninja_forms_disable_marketing', $disable_marketing ) ) {
if ( 1 == get_option( 'ninja_forms_needs_updates' ) ) {
public function scrub_available_actions( $actions )
foreach( $actions as $key => $action ){
if ( ! is_plugin_active( $action[ 'plugin_path' ] ) ) continue;
unset( $actions[ $key ] );
* Call back function for the promo manager cron.
* Grabs a fresh copy of the promotions and stores them in an option.
public function nf_run_promotion_manager()
$promotion_manager = new NF_PromotionManager();
$promomotions = json_encode( $promotion_manager->get_promotions() );
update_option( 'nf_active_promotions', $promomotions, false );
* Listens for plugin activation and runs check to see if any
* promotions need to be added or removed.
public function nf_bust_promotion_cache_on_plugin_activation( $plugin, $network_activation )
$addons_with_promotions = $this->get_promotion_addons_lookup_table();
$plugin = explode( '/', $plugin );
$this->nf_maybe_bust_promotion_cache( $addons_with_promotions, $plugin[ 0 ] );
* Build a look up table for the add-ons that have promotions.
* TODO: maybe come up with a better name for this class.
* @return array of promotions.
public function get_promotion_addons_lookup_table()
// @TODO: Maybe use ninja_forms_addons_feed option to populate this later?
$nf_promotion_addons = array(
'ninja-forms-conditional-logic', // Account for development environments.
'ninja-forms-conditionals',
'ninja-forms-multi-part',
'ninja-forms-layout-styles', // Account for development environments.
'ninja-mail', // Account for Ninja Mail as legacy for SendWP.
return $nf_promotion_addons;
* Loops over our add-ons that have promotions and
* runs the promotion manager class.
public function nf_maybe_bust_promotion_cache( $promo_addons, $plugin_being_activated )
if ( in_array( $plugin_being_activated, $promo_addons ) ) {
$this->nf_run_promotion_manager();
public function admin_notices()
// Notices filter and run the notices function.
$admin_notices = Ninja_Forms()->config( 'AdminNotices' );
self::$instance->notices->admin_notice( apply_filters( 'nf_admin_notices', $admin_notices ) );
public function plugins_loaded()
unload_textdomain('ninja-forms');
load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' );
* Field Class Registration
self::$instance->fields = apply_filters( 'ninja_forms_register_fields', self::load_classes( 'Fields' ) );
if( ! apply_filters( 'ninja_forms_enable_credit_card_fields', false ) ){
unset( self::$instance->fields[ 'creditcard' ] );
unset( self::$instance->fields[ 'creditcardcvc' ] );
unset( self::$instance->fields[ 'creditcardexpiration' ] );
unset( self::$instance->fields[ 'creditcardfullname' ] );
unset( self::$instance->fields[ 'creditcardnumber' ] );
unset( self::$instance->fields[ 'creditcardzip' ] );
* Form Action Registration
$actions = self::load_classes( 'Actions' ) ;
uksort( $actions, [ $this, 'sort_actions' ] );
self::$instance->actions = apply_filters( 'ninja_forms_register_actions', $actions );
self::$instance->merge_tags = apply_filters( 'ninja_forms_register_merge_tags', self::$instance->merge_tags );
* It's Ninja Time: Hook for Extensions
do_action( 'ninja_forms_loaded' );
* Autoload Ninja Forms classes
public function autoloader( $class_name )
if( class_exists( $class_name ) ) return;
if (false !== strpos($class_name, 'NF_')) {
$class_name = str_replace('NF_', '', $class_name);
$classes_dir = realpath(plugin_dir_path(__FILE__)) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;
$class_file = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
if (file_exists($classes_dir . $class_file)) {
require_once $classes_dir . $class_file;
if (false !== strpos($class_name, 'WPN_')) {
$class_name = str_replace('WPN_', '', $class_name);
$classes_dir = realpath(plugin_dir_path(__FILE__)) . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR;
$class_file = str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
if (file_exists($classes_dir . $class_file)) {
require_once $classes_dir . $class_file;
* Form Model Factory Wrapper
* @return NF_Abstracts_ModelFactory
public function form( $id = '' )
if ( isset ( $forms[ $id ] ) ) {
$forms[ $id ] = new NF_Abstracts_ModelFactory( $wpdb, $id );
* Ninja_Forms()->logger()->log( 'debug', "Hello, {name}!", array( 'name' => 'world' ) );
* Ninja_Forms()->logger()->debug( "Hello, {name}!", array( 'name' => 'world' ) );
public function dispatcher()
return $this->_dispatcher;
return new NF_EOS_Parser();
public function session()
$this->session = new NF_Session();
public function request( $action )
if( ! isset( $this->requests[ $action ] ) ) return new NF_AJAX_Requests_NullRequest();
return $this->requests[ $action ];
public function background_process( $action )
if( ! isset( $this->requests[ $action ] ) ) return new NF_AJAX_Processes_NullProcess();
return $this->requests[ $action ];
* @param bool|false $default
public function get_setting( $key = '', $default = false )
if( empty( $key ) || ! isset( $this->settings[ $key ] ) || empty( $this->settings[ $key ] ) ) return $default;
return $this->settings[ $key ];
public function get_settings()
return ( is_array( $this->settings ) ) ? $this->settings : array();
* @param bool|false $defer_update Defer the database update of all settings
public function update_setting( $key, $value, $defer_update = false )
$this->settings[ $key ] = $value;
$this->update_settings();
* Save settings to database
public function update_settings( $settings = array() )
if( ! is_array( $this->settings ) ) $this->settings = array();
if( $settings && is_array( $settings ) ) {
$this->settings = array_merge($this->settings, $settings);
update_option( 'ninja_forms_settings', $this->settings );
public function display( $form_id, $preview = FALSE )
$noscript_message = esc_html__( 'Notice: JavaScript is required for this content.', 'ninja-forms' );
$noscript_message = apply_filters( 'ninja_forms_noscript_message', $noscript_message );
Ninja_Forms()->template( 'display-noscript-message.html.php', array( 'message' => $noscript_message ) );
//Detect Page builder editor
$visual_composer_screen = !empty(get_post_meta(get_queried_object_id(), '_vcv-editorStartedAt', true)) && isset( $_GET['vcv-ajax'] );
//Set a list of conditions that would lead to loading the iFrame
$set_load_iframe_condition = $visual_composer_screen;
//FIlter the current result of the conditions
$load_iframe = apply_filters("ninja_forms_display_iframe", $set_load_iframe_condition, $form_id);
NF_Display_Render::localize_iframe($form_id);
NF_Display_Render::localize($form_id);
NF_Display_Render::localize_preview($form_id);
private function sort_actions( $a, $b )
// Create a numeric lookup by flipping the non-associative array.
$custom_order = array_flip( $this->config( 'ActionTypeOrder' ) );
$a_order = ( isset( $custom_order[ $a ] ) ) ? $custom_order[ $a ] : 9001;
$b_order = ( isset( $custom_order[ $b ] ) ) ? $custom_order[ $b ] : 9001;
return intval( $a_order >= $b_order );
* Load Classes from Directory
private static function load_classes( $prefix = '' )
$subdirectory = str_replace( '_', DIRECTORY_SEPARATOR, str_replace( 'NF_', '', $prefix ) );
$directory = 'includes/' . $subdirectory;
foreach (scandir( self::$dir . $directory ) as $path) {
$path = explode( DIRECTORY_SEPARATOR, str_replace( self::$dir, '', $path ) );
$filename = str_replace( '.php', '', end( $path ) );
$class_name = 'NF_' . $prefix . '_' . $filename;
if( ! class_exists( $class_name ) ) continue;