: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Admin\Tools\Importers;
* Ninja Forms Importer class.
class NinjaForms extends Base {
* Define required properties.
$this->name = 'Ninja Forms';
$this->slug = 'ninja-forms';
$this->path = 'ninja-forms/ninja-forms.php';
* @return \NF_Database_Models_Form[]
public function get_forms() {
if ( ! $this->is_active() ) {
$forms = \Ninja_Forms()->form()->get_forms();
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
if ( ! $form instanceof \NF_Database_Models_Form ) {
$forms_final[ $form->get_id() ] = $form->get_setting( 'title' );
* @param int $id Form ID.
public function get_form( $id ) {
$form['settings'] = \Ninja_Forms()->form( $id )->get()->get_settings();
$fields = \Ninja_Forms()->form( $id )->get_fields();
$actions = \Ninja_Forms()->form( $id )->get_actions();
foreach ( $fields as $field ) {
if ( ! $field instanceof \NF_Database_Models_Field ) {
$form['fields'][] = array_merge(
'id' => $field->get_id(),
foreach ( $actions as $action ) {
if ( ! $action instanceof \NF_Database_Models_Action ) {
$form['actions'][] = $action->get_settings();
* Import a single form using AJAX.
public function import_form() {
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can( 'create_forms' ) ) {
// Define some basic information.
$analyze = isset( $_POST['analyze'] );
$nf_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : 0;
$nf_form = $this->get_form( $nf_id );
$nf_form_name = $nf_form['settings']['title'];
$nf_recaptcha_type = 'v2';
$fields_pro_plain = [ 'phone', 'date' ];
$fields_pro_omit = [ 'html', 'divider' ];
$fields_unsupported = [ 'spam', 'starrating', 'listmultiselect', 'hidden', 'total', 'shipping', 'quantity', 'product' ];
'form_title' => $nf_form_name,
'submit_text' => esc_html__( 'Submit', 'wpforms-lite' ),
'submit_text_processing' => esc_html__( 'Sending', 'wpforms-lite' ),
'notification_enable' => '1',
'notification_name' => esc_html__( 'Notification 1', 'wpforms-lite' ),
'email' => '{admin_email}',
'subject' => sprintf( /* translators: %s - form name. */
esc_html__( 'New Entry: %s', 'wpforms-lite' ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'message' => '{all_fields}',
'message' => esc_html__( 'Thanks for contacting us! We will be in touch with you shortly.', 'wpforms-lite' ),
'import_form_id' => $nf_id,
// If form does not contain fields, bail.
if ( empty( $nf_form['fields'] ) ) {
'name' => sanitize_text_field( $nf_form_name ),
'msg' => esc_html__( 'No form fields found.', 'wpforms-lite' ),
foreach ( $nf_form['fields'] as $nf_field ) {
// Try to determine field label to use.
$label = $this->get_field_label( $nf_field );
// Next, check if field is unsupported. If unsupported make note and
// then continue to the next field.
if ( in_array( $nf_field['type'], $fields_unsupported, true ) ) {
// Now check if this install is Lite. If it is Lite and it's a
// field type not included, make a note then continue to the next
if ( ! wpforms()->is_pro() && in_array( $nf_field['type'], $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
if ( ! wpforms()->is_pro() && in_array( $nf_field['type'], $fields_pro_omit, true ) ) {
$upgrade_omit[] = $label;
// Determine next field ID to assign.
if ( empty( $form['fields'] ) ) {
$field_id = (int) max( array_keys( $form['fields'] ) ) + 1;
switch ( $nf_field['type'] ) {
// Single line text, address, city, first name, last name,
// zipcode, email, number, textarea fields.
if ( $nf_field['type'] === 'email' ) {
} elseif ( $nf_field['type'] === 'number' ) {
} elseif ( $nf_field['type'] === 'textarea' ) {
$form['fields'][ $field_id ] = [
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'placeholder' => ! empty( $nf_field['placeholder'] ) ? $nf_field['placeholder'] : '',
'default_value' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'nf_key' => $nf_field['key'],
// Single checkbox field.
$form['fields'][ $field_id ] = [
'label' => esc_html__( 'Single Checkbox Field', 'wpforms-lite' ),
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'nf_key' => $nf_field['key'],
// Multi-check field, radio, select, state, and country fields.
if ( $nf_field['type'] === 'listcheckbox' ) {
} elseif ( $nf_field['type'] === 'listradio' ) {
if ( $nf_field['type'] === 'listcountry' ) {
$countries = wpforms_countries();
foreach ( $countries as $key => $country ) {
'default' => isset( $nf_field['default'] ) && $nf_field['default'] === $key ? '1' : '',
foreach ( $nf_field['options'] as $option ) {
'label' => $option['label'],
'value' => $option['value'],
$form['fields'][ $field_id ] = [
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'nf_key' => $nf_field['key'],
$form['fields'][ $field_id ] = [
'code' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'nf_key' => $nf_field['key'],
$form['fields'][ $field_id ] = [
'nf_key' => $nf_field['key'],
$type = wpforms()->is_pro() ? 'phone' : 'text';
$form['fields'][ $field_id ] = [
'format' => ! empty( $nf_field['mask'] ) && '(999) 999-9999' === $nf_field['mask'] ? 'us' : 'international',
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'placeholder' => ! empty( $nf_field['placeholder'] ) ? $nf_field['placeholder'] : '',
'default_value' => ! empty( $nf_field['default'] ) ? $nf_field['default'] : '',
'nf_key' => $nf_field['key'],
$type = wpforms()->is_pro() ? 'date-time' : 'text';
$form['fields'][ $field_id ] = [
'description' => ! empty( $nf_field['desc_text'] ) ? $nf_field['desc_text'] : '',
'required' => ! empty( $nf_field['required'] ) ? '1' : '',
'date_placeholder' => '',
'date_format' => 'm/d/Y',
'date_type' => 'datepicker',
'time_format' => 'g:i A',
'nf_key' => $nf_field['key'],
if ( $nf_field['size'] === 'invisible' ) {
$nf_recaptcha_type = 'invisible';
// If we are only analyzing the form, we can stop here and return the
// details about this form.
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
foreach ( $nf_form['actions'] as $action ) {
if ( $action['type'] === 'successmessage' ) {
$form['settings']['confirmations'][1]['message'] = $this->get_smarttags( $action['message'], $form['fields'] );
// If the user has already defined v2 reCAPTCHA keys in the WPForms
$site_key = wpforms_setting( 'recaptcha-site-key', '' );
$secret_key = wpforms_setting( 'recaptcha-secret-key', '' );
// Try to abstract keys from NF.
if ( empty( $site_key ) || empty( $secret_key ) ) {
$nf_settings = get_option( 'ninja_forms_settings' );
if ( ! empty( $nf_settings['recaptcha_site_key'] ) && ! empty( $nf_settings['recaptcha_secret_key'] ) ) {
$wpforms_settings = get_option( 'wpforms_settings', [] );
$wpforms_settings['recaptcha-site-key'] = $nf_settings['recaptcha_site_key'];
$wpforms_settings['recaptcha-secret-key'] = $nf_settings['recaptcha_secret_key'];
$wpforms_settings['recaptcha-type'] = $nf_recaptcha_type;
update_option( 'wpforms_settings', $wpforms_settings );
if ( ! empty( $site_key ) && ! empty( $secret_key ) ) {
$form['settings']['recaptcha'] = '1';
// Setup email notifications.
'notification_name' => esc_html__( 'Notification', 'wpforms-lite' ) . " $action_count",
'email' => '{admin_email}',
'subject' => sprintf( /* translators: %s - form name. */
esc_html__( 'New Entry: %s', 'wpforms-lite' ),
'sender_name' => get_bloginfo( 'name' ),
'sender_address' => '{admin_email}',
'message' => '{all_fields}',
foreach ( $nf_form['actions'] as $action ) {
if ( $action['type'] !== 'email' ) {
$action_defaults['notification_name'] = esc_html__( 'Notification', 'wpforms-lite' ) . " $action_count";
$form['settings']['notifications'][ $action_count ] = $action_defaults;
if ( ! empty( $action['label'] ) ) {
$form['settings']['notifications'][ $action_count ]['notification_name'] = $action['label'];
if ( ! empty( $action['to'] ) ) {
$form['settings']['notifications'][ $action_count ]['email'] = $this->get_smarttags( $action['to'], $form['fields'] );
if ( ! empty( $action['reply_to'] ) ) {
$form['settings']['notifications'][ $action_count ]['replyto'] = $this->get_smarttags( $action['reply_to'], $form['fields'] );
if ( ! empty( $action['email_subject'] ) ) {
$form['settings']['notifications'][ $action_count ]['subject'] = $this->get_smarttags( $action['email_subject'], $form['fields'] );
if ( ! empty( $action['email_message'] ) ) {
$form['settings']['notifications'][ $action_count ]['message'] = $this->get_smarttags( $action['email_message'], $form['fields'] );
if ( ! empty( $action['from_name'] ) ) {
$form['settings']['notifications'][ $action_count ]['sender_name'] = $this->get_smarttags( $action['from_name'], $form['fields'] );
if ( ! empty( $action['from_address'] ) ) {
$form['settings']['notifications'][ $action_count ]['sender_address'] = $this->get_smarttags( $action['from_address'], $form['fields'] );
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
* @param array $field Field data.
public function get_field_label( $field ) {
if ( ! empty( $field['label'] ) ) {
$label = sanitize_text_field( $field['label'] );
$label = sprintf( /* translators: %s - field type. */
esc_html__( '%s Field', 'wpforms-lite' ),
ucfirst( $field['type'] )