: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php if ( ! defined( 'ABSPATH' ) ) exit;
final class NF_Admin_Menus_Forms extends NF_Abstracts_Menu
public $page_title = 'Ninja Forms';
public $menu_slug = 'ninja-forms';
public $icon_url = 'dashicons-feedback';
public $position = '35.1337';
public $ver = Ninja_Forms::VERSION;
//Data needed into nfDasboard wp_localize_script
private $preloadedFormData;
private $fieldTypeSections;
private $formSettingTypeData;
// Stores whether or not this form has a password field.
private $legacy_password = false;
public function __construct()
if( ! defined( 'DOING_AJAX' ) ) {
add_action('current_screen', array($this, 'admin_init'));
add_action( 'current_screen', array( 'NF_Admin_AllFormsTable', 'process_bulk_action' ) );
add_action( 'admin_body_class', array( $this, 'body_class' ), 999999999 );
add_action( 'admin_init', array( $this, 'nf_upgrade_redirect' ) );
* If we have required updates, redirect to the main Ninja Forms page
public function nf_upgrade_redirect() {
if( "1" == get_option( 'ninja_forms_needs_updates' ) &&
'admin.php' == $pagenow &&
'ninja-forms' == $_GET[ 'page' ] &&
isset( $_GET[ 'form_id' ] ) ) {
wp_safe_redirect( admin_url( 'admin.php?page=ninja-forms' ), 301 );
public function body_class( $classes )
// Add class for the builder.
if( isset( $_GET['page'] ) && isset( $_GET[ 'form_id' ] ) && $_GET['page'] == $this->menu_slug ) {
$classes = "$classes ninja-forms-app";
public function get_page_title()
return esc_html__( 'Ninja Forms', 'ninja-forms' );
public function admin_init()
* If we aren't on the Ninja Forms menu page, don't admin_init.
if ( empty( $_GET[ 'page' ] ) || 'ninja-forms' !== $_GET[ 'page' ] ) {
* If the nf3_ database tables do not exist, then re-run activation.
if ( ! ninja_forms_three_table_exists() ) {
Ninja_Forms()->activation();
if( isset( $_GET[ 'form_id' ] ) && ! is_numeric( $_GET[ 'form_id' ] ) && 'new' != $_GET[ 'form_id' ] ) {
if( current_user_can( apply_filters( 'ninja_forms_admin_import_template_capabilities', 'manage_options' ) ) ) {
$this->import_from_template();
/* DISABLE OLD FORMS TABLE IN FAVOR OF NEW DASHBOARD */
// $this->table = new NF_Admin_AllFormsTable();
public function display()
if( isset( $_GET[ 'form_id' ] ) ){
if( 'new' == $_GET[ 'form_id' ] ) {
$form_id = 'tmp-' . time();
$form_id = (is_numeric($_GET['form_id'])) ? absint($_GET['form_id']) : '';
Ninja_Forms::template( 'admin-menu-new-form.html.php' );
Ninja_Forms::template( 'fields-label--builder.html' ); // Fork for the builder.
Ninja_Forms::template( 'fields-address.html' );
Ninja_Forms::template( 'fields-address2.html' );
Ninja_Forms::template( 'fields-button.html' );
Ninja_Forms::template( 'fields-checkbox.html' );
Ninja_Forms::template( 'fields-city.html' );
Ninja_Forms::template( 'fields-color.html' );
Ninja_Forms::template( 'fields-date.html' );
Ninja_Forms::template( 'fields-email.html' );
Ninja_Forms::template( 'fields-file.html' );
Ninja_Forms::template( 'fields-firstname.html' );
Ninja_Forms::template( 'fields-hidden.html' );
Ninja_Forms::template( 'fields-hr.html' );
Ninja_Forms::template( 'fields-html.html' );
Ninja_Forms::template( 'fields-input.html' );
Ninja_Forms::template( 'fields-lastname.html' );
Ninja_Forms::template( 'fields-listcheckbox.html' );
Ninja_Forms::template( 'fields-listradio.html' );
Ninja_Forms::template( 'fields-listselect--builder.html' ); // Fork that removes the `for` attribute, which hijacks click events.
Ninja_Forms::template( 'fields-number.html' );
Ninja_Forms::template( 'fields-password.html' );
Ninja_Forms::template( 'fields-recaptcha.html' );
Ninja_Forms::template( 'fields-starrating.html' );
Ninja_Forms::template( 'fields-submit.html' );
Ninja_Forms::template( 'fields-tel.html' );
Ninja_Forms::template( 'fields-terms.html' );
Ninja_Forms::template( 'fields-textarea.html' );
Ninja_Forms::template( 'fields-textbox.html' );
Ninja_Forms::template( 'fields-zip.html' );
Ninja_Forms::template( 'fields-repeater.html' );
Ninja_Forms::template( 'fields-total.html' );
Ninja_Forms::template( 'fields-tax.html' );
Ninja_Forms::template( 'fields-product.html' );
Ninja_Forms::template( 'fields-shipping.html' );
delete_user_option( get_current_user_id(), 'nf_form_preview_' . $form_id );
if( ! isset( $_GET[ 'ajax' ] ) ) {
$this->_localize_form_data( $form_id );
$this->_localize_field_type_data();
$this->_localize_action_type_data();
$this->_localize_form_settings();
$this->_localize_merge_tags();
//moved after _localize functions trigger to get inline variables
$this->_enqueue_the_things( $form_id );
* - DISABLE IN FAVOR OF NEW DASHBOARD.
// $this->table->prepare_items();
// Ninja_Forms::template( 'admin-menu-all-forms.html.php', array(
// 'table' => $this->table,
// 'add_new_url' => admin_url( 'admin.php?page=ninja-forms&form_id=new' ),
// 'add_new_text' => __( 'Add New Form', 'ninja-forms' )
$use_services = true; // Feature Flag.
$use_services = apply_filters( 'ninja_forms_use_services', $use_services ); // The WordPress Way.
if ( apply_filters( 'ninja_forms_disable_marketing', false ) ) $use_services = false;
$use_services = $use_services && ( version_compare( PHP_VERSION, '5.6', '>=' ) ); // PHP Version Check.
$dash_items = Ninja_Forms()->config('DashboardMenuItems');
$required_updates = get_option( 'ninja_forms_needs_updates', 0 );
wp_enqueue_script( 'backbone-radio', Ninja_Forms::$url . 'assets/js/lib/backbone.radio.min.js', array( 'jquery', 'jquery-migrate', 'backbone' ) );
wp_enqueue_script( 'backbone-marionette-3', Ninja_Forms::$url . 'assets/js/lib/backbone.marionette3.min.js', array( 'jquery', 'backbone' ) );
wp_enqueue_script( 'nf-jBox', Ninja_Forms::$url . 'assets/js/min/jBox.min.js', array( 'jquery' ) );
wp_enqueue_script( 'nf-ninjamodal', Ninja_Forms::$url . 'assets/js/lib/ninjaModal.js', array( 'jquery' ), $this->ver );
wp_enqueue_script( 'nf-batch-processor', Ninja_Forms::$url . 'assets/js/lib/batch-processor.js', array( 'nf-ninjamodal' ), $this->ver );
wp_enqueue_script( 'nf-moment', Ninja_Forms::$url . 'assets/js/min/datepicker.min.js', array( 'jquery', 'nf-dashboard' ) );
wp_enqueue_script( 'nf-dashboard', Ninja_Forms::$url . 'assets/js/min/dashboard.min.js', array( 'backbone-radio', 'backbone-marionette-3' ), $this->ver );
wp_enqueue_script( 'nf-sendwp', Ninja_Forms::$url . 'assets/js/lib/sendwp.js', array(), $this->ver );
wp_enqueue_script( 'nf-feature-scripts', Ninja_Forms::$url . 'assets/js/lib/feature-scripts.js', array(), $this->ver );
$current_user = wp_get_current_user();
wp_localize_script( 'nf-dashboard', 'nfi18n', Ninja_Forms::config( 'i18nDashboard' ) );
$promotions = get_option( 'nf_active_promotions' );
$promotions = json_decode( $promotions, true );
$surveyPromo = new NF_Admin_SurveyPromo();
if($surveyPromo->shouldShow() && $surveyPromo->isDashboard()) $promotions = array();
if( ! empty( $promotions ) ) {
wp_localize_script( 'nf-dashboard', 'nfPromotions', array_values( $promotions[ 'dashboard' ] ) );
wp_localize_script( 'nf-dashboard', 'nfAdmin', array(
'ajaxNonce' => wp_create_nonce( 'ninja_forms_dashboard_nonce' ),
'batchNonce' => wp_create_nonce( 'ninja_forms_batch_nonce' ),
'updateNonce' => wp_create_nonce( 'ninja_forms_required_update_nonce' ),
'formTelemetry' => ( get_option( 'nf_form_tel_sent' ) ) ? 0 : 1,
'showOptin' => ( get_option( 'ninja_forms_do_not_allow_tracking' ) ||
get_option( 'ninja_forms_allow_tracking' ) ) ? 0 : 1,
'requiredUpdates' => $required_updates,
'currentUserEmail' => $current_user->user_email,
'builderURL' => admin_url( 'admin.php?page=ninja-forms&form_id=' ),
'sendwpInstallNonce' => wp_create_nonce( 'ninja_forms_sendwp_remote_install' ),
'disconnectNonce' => wp_create_nonce( 'nf-oauth-disconnect' ),
"nfDashItems" => array_values( $dash_items ),
"useServices" => $use_services ? 'true' : 'false',
"serviceSuccess" => isset( $_GET[ 'success' ] ) ? htmlspecialchars( $_GET[ 'success' ] ) : '',
"preloadedFormData" => $this->preloadedFormData,
"fieldTypeData" => $this->fieldTypeData,
"fieldSettings" => $this->fieldSettings,
"fieldTypeSections" => $this->fieldTypeSections,
"actionTypeData" => $this->actionTypeData,
"actionSettings" => $this->actionSettings,
"formSettingTypeData" => $this->formSettingTypeData,
"formSettings" => $this->formSettings,
"mergeTags" => $this->mergeTags
wp_localize_script( 'nf-dashboard', 'nfDashInlineVars', $nfDashInlineVars );
wp_enqueue_style( 'nf-builder', Ninja_Forms::$url . 'assets/css/builder.css', array(), $this->ver );
wp_enqueue_style( 'nf-dashboard', Ninja_Forms::$url . 'assets/css/dashboard.min.css', array(), $this->ver );
wp_enqueue_style( 'nf-jbox', Ninja_Forms::$url . 'assets/css/jBox.css' );
wp_enqueue_style( 'nf-font-awesome', Ninja_Forms::$url . 'assets/css/font-awesome.min.css' );
if( $required_updates ) {
wp_enqueue_style( 'nf-updates-styles', Ninja_Forms::$url . '/assets/css/required-updates.css' );
Ninja_Forms::template( 'admin-menu-dashboard.html.php' );
public function submenu_separators()
add_submenu_page( 'ninja-forms', '', '', 'read', '', '' );
* TODO: Remove this function and its hook because we are handling template imports via the batch processor.
private function import_from_template()
$template = sanitize_title( $_GET['form_id'] );
$templates = Ninja_Forms::config( 'NewFormTemplates' );
if( isset( $templates[ $template ] ) && ! empty( $templates[ $template ][ 'form' ] ) ) {
$form = $templates[ $template ][ 'form' ];
$form = Ninja_Forms::template( $template . '.nff', array(), TRUE );
if( ! $form ) die( 'Template not found' );
$form = json_decode( html_entity_decode( $form ), true );
$form_id = Ninja_Forms()->form()->import_form( $form );
$error_message = ( function_exists( 'json_last_error_msg' ) && json_last_error_msg() ) ? json_last_error_msg() : esc_html__( 'Form Template Import Error.', 'ninja-forms' );
wp_die( $error_message );
header( "Location: " . admin_url( "admin.php?page=ninja-forms&form_id=$form_id" ) );
private function _enqueue_the_things( $form_id )
wp_enqueue_style( 'nf-builder', Ninja_Forms::$url . 'assets/css/builder.css', array(), $this->ver );
wp_enqueue_style( 'nf-font-awesome', Ninja_Forms::$url . 'assets/css/font-awesome.min.css' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'jBox', Ninja_Forms::$url . 'assets/css/jBox.css' );
wp_enqueue_style( 'summernote', Ninja_Forms::$url . 'assets/css/summernote.css' );
wp_enqueue_style( 'codemirror', Ninja_Forms::$url . 'assets/css/codemirror.css' );
wp_enqueue_style( 'codemirror-monokai', Ninja_Forms::$url . 'assets/css/monokai-theme.css' );
wp_enqueue_script( 'wp-util' );
wp_enqueue_script( 'nf-autoNumeric', Ninja_Forms::$url . 'assets/js/min/autonumeric.min.js', array( 'backbone' ) );
wp_enqueue_script( 'jquery-maskedinput', Ninja_Forms::$url . 'assets/js/lib/jquery.maskedinput.min.js', array( 'jquery', 'backbone' ) );
wp_enqueue_script( 'backbone-marionette', Ninja_Forms::$url . 'assets/js/lib/backbone.marionette.min.js', array( 'jquery', 'backbone' ) );
wp_enqueue_script( 'backbone-radio', Ninja_Forms::$url . 'assets/js/lib/backbone.radio.min.js', array( 'jquery', 'backbone' ) );
wp_enqueue_script( 'nf-builder-deps', Ninja_Forms::$url . 'assets/js/min/builder-deps.min.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery-hotkeys-new', Ninja_Forms::$url . 'assets/js/lib/jquery.hotkeys.min.js' );
wp_enqueue_script( 'jBox', Ninja_Forms::$url . 'assets/js/min/jBox.min.js', array( 'nf-builder-deps' ) );
wp_enqueue_script( 'nf-ninjamodal', Ninja_Forms::$url . 'assets/js/lib/ninjaModal.js', array( 'jBox' ), $this->ver );
wp_enqueue_script( 'nf-jquery-caret', Ninja_Forms::$url . 'assets/js/lib/jquery.caret.min.js' );
wp_enqueue_script( 'jquery-mobile-events', Ninja_Forms::$url . 'assets/js/lib/jquery.mobile-events.min.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery-ui-touch-punch', Ninja_Forms::$url . 'assets/js/lib/jquery.ui.touch-punch.min.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery-classy-wiggle', Ninja_Forms::$url . 'assets/js/lib/jquery.classywiggle.min.js', array( 'jquery' ) );
wp_enqueue_script( 'nf-moment', Ninja_Forms::$url . 'assets/js/min/datepicker.min.js', array( 'jquery', 'nf-builder' ) );
wp_enqueue_script( 'codemirror', Ninja_Forms::$url . 'assets/js/lib/codemirror.min.js', array( 'jquery', 'nf-builder-deps' ) );
wp_enqueue_script( 'codemirror-xml', Ninja_Forms::$url . 'assets/js/lib/codemirror-xml.min.js', array( 'jquery', 'codemirror' ) );
wp_enqueue_script( 'codemirror-formatting', Ninja_Forms::$url . 'assets/js/lib/codemirror-formatting.min.js', array( 'jquery', 'codemirror' ) );
wp_enqueue_script( 'summernote', Ninja_Forms::$url . 'assets/js/lib/summernote.min.js', array( 'jquery', 'nf-builder-deps' ) );
wp_enqueue_script( 'nf-builder', Ninja_Forms::$url . 'assets/js/min/builder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-effects-bounce', 'wp-color-picker' ), $this->ver );
wp_localize_script( 'nf-builder', 'nfi18n', Ninja_Forms::config( 'i18nBuilder' ) );
$home_url = parse_url( home_url() );
if($wp_rewrite->permalink_structure) {
$public_link_structure = site_url() . '/ninja-forms/[FORM_ID]';
$public_link_structure = site_url('?nf_public_link=[FORM_ID]');
if(isset($_GET['nf_dev_mode']) && $_GET['nf_dev_mode']){
$dev_mode = absint($_GET['nf_dev_mode']);
// @NOTE Check the settings array to avoid a default value in place of zero.
$settings = Ninja_Forms()->get_settings();
if( ! isset($settings['builder_dev_mode'])){
$dev_mode = $settings['builder_dev_mode'];
wp_localize_script( 'nf-builder', 'nfAdmin', array(
'ajaxNonce' => wp_create_nonce( 'ninja_forms_builder_nonce' ),
'batchNonce' => wp_create_nonce( 'ninja_forms_batch_nonce' ),
'requireBaseUrl' => Ninja_Forms::$url . 'assets/js/',
'previewurl' => home_url() . '/?nf_preview_form=',
'wp_locale' => $wp_locale->number_format,
'editFormText' => esc_html__( 'Edit Form', 'ninja-forms' ),
'mobile' => ( wp_is_mobile() ) ? 1: 0,
'currencySymbols' => array_merge( array( '' => Ninja_Forms()->get_setting( 'currency_symbol' ) ), Ninja_Forms::config( 'CurrencySymbol' ) ),
'dateFormat' => !empty( Ninja_Forms()->get_setting('date_format') ) ? Ninja_Forms()->get_setting('date_format') : get_option('date_format'),
'formID' => isset( $_GET[ 'form_id' ] ) ? absint( $_GET[ 'form_id' ] ) : 0,
'home_url_host' => $home_url[ 'host' ],
'publicLinkStructure' => $public_link_structure,
'devMode' => (bool) $dev_mode,
'filter_esc_status' => json_encode( WPN_Helper::maybe_disallow_unfiltered_html_for_escaping() ),
"preloadedFormData" => $this->preloadedFormData,
"fieldTypeData" => $this->fieldTypeData,
"fieldSettings" => $this->fieldSettings,
"fieldTypeSections" => $this->fieldTypeSections,
"actionTypeData" => $this->actionTypeData,
"actionSettings" => $this->actionSettings,
"formSettingTypeData" => $this->formSettingTypeData,
"formSettings" => $this->formSettings,
"mergeTags" => $this->mergeTags
wp_localize_script( 'nf-builder', 'nfDashInlineVars', $nfDashInlineVars );
do_action( 'nf_admin_enqueue_scripts' );
private function _localize_form_data( $form_id )
$form = Ninja_Forms()->form( $form_id )->get();
if( ! $form->get_tmp_id() ) {
if(WPN_Helper::use_cache()) {
$form_cache = WPN_Helper::get_nf_cache( $form_id );
$fields = $form_cache[ 'fields' ];
$fields = ($form_id) ? Ninja_Forms()->form($form_id)->get_fields() : array();
$actions = ($form_id) ? Ninja_Forms()->form($form_id)->get_actions() : array();
$fields_settings = array();
if( ! empty( $fields ) ) {
// TODO: Replace unique field key checks with a refactored model/factory.
// $unique_field_keys = array();
// $form_cache = get_option( 'nf_form_' . $form_id, false );
// $cache_updated = false;
foreach ($fields as $field) {
$field_id = ( is_object( $field ) ) ? $field->get_id() : $field[ 'id' ];
* TODO: Replace unique field key checks with a refactored model/factory.
/* END Duplicate field check. */
$type = ( is_object( $field ) ) ? $field->get_setting( 'type' ) : $field[ 'settings' ][ 'type' ];
* As of version 3.3.16, we want password fields to only show up if the user is using an add-on that requires them.
* But, because we don't want to break any forms that may already have a password field, we enable them if the current form already has them.
* The $legacy_password class var holds whether or not this form has a pre-existing password or confirm password field.
if ( 'password' == $type || 'passwordconfirm' == $type ) {
$this->legacy_password = true;
if( ! isset( Ninja_Forms()->fields[ $type ] ) ){
$field = NF_Fields_Unknown::create( $field );
$settings = ( is_object( $field ) ) ? $field->get_settings() : $field[ 'settings' ];
$settings[ 'id' ] = $field_id;
$settings = $this->null_data_check( $settings );
$settings = $this->sanitizeFieldSettings($settings);
$fields_settings[] = $settings;
$actions_settings = array();
if( ! empty( $actions ) ) {
foreach ($actions as $action) {
$type = $action->get_setting( 'type' );
if( ! isset( Ninja_Forms()->actions[ $type ] ) ) continue;
$settings = $action->get_settings();
$settings['id'] = $action->get_id();
$settings = $this->null_data_check( $settings );
$actions_settings[] = $settings;
if( $form->get_tmp_id() ){
$actions_settings = Ninja_Forms()->config( 'FormActionDefaults' );
$form_data['id'] = $form_id;
// Use form cache for form settings.
// TODO: Defer to refactor of factory/model.
if( $form_cache && isset( $form_cache[ 'settings' ] ) ) {
$form_data['settings'] = $form_cache[ 'settings' ];
$form_data['settings'] = $form->get_settings();
$form_data['fields'] = $fields_settings;
$form_data['actions'] = $actions_settings;