: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Admin\Tools\Importers;
* Contact Form 7 Importer class.
class ContactForm7 extends Base {
* Define required properties.
$this->name = 'Contact Form 7';
$this->slug = 'contact-form-7';
$this->path = 'contact-form-7/wp-contact-form-7.php';
public function get_forms() {
if ( ! $this->is_active() ) {
$forms = \WPCF7_ContactForm::find( [ 'posts_per_page' => - 1 ] );
foreach ( $forms as $form ) {
if ( ! empty( $form ) && ( $form instanceof \WPCF7_ContactForm ) ) {
$forms_final[ $form->id() ] = $form->title();
* @param int $id Form ID.
* @return \WPCF7_ContactForm|bool
public function get_form( $id ) {
$form = \WPCF7_ContactForm::find(
if ( ! empty( $form[0] ) && ( $form[0] instanceof \WPCF7_ContactForm ) ) {
* 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'] );
$cf7_id = ! empty( $_POST['form_id'] ) ? (int) $_POST['form_id'] : 0;
$cf7_form = $this->get_form( $cf7_id );
'name' => esc_html__( 'Unknown Form', 'wpforms-lite' ),
'msg' => esc_html__( 'The form you are trying to import does not exist.', 'wpforms-lite' ),
$cf7_form_name = $cf7_form->title();
$cf7_fields = $cf7_form->scan_form_tags();
$cf7_properties = $cf7_form->get_properties();
$fields_pro_plain = [ 'url', 'tel', 'date' ];
$fields_pro_omit = [ 'file' ];
$fields_unsupported = [ 'quiz', 'hidden' ];
'form_title' => $cf7_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' => $cf7_id,
// If form does not contain fields, bail.
if ( empty( $cf7_fields ) ) {
'name' => sanitize_text_field( $cf7_form_name ),
'msg' => esc_html__( 'No form fields found.', 'wpforms-lite' ),
foreach ( $cf7_fields as $cf7_field ) {
if ( ! $cf7_field instanceof \WPCF7_FormTag ) {
// Try to determine field label to use.
$label = $this->get_field_label( $cf7_properties['form'], $cf7_field->type, $cf7_field->name );
// Next, check if field is unsupported. If supported make note and
// then continue to the next field.
if ( in_array( $cf7_field->basetype, $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( $cf7_field->basetype, $fields_pro_plain, true ) ) {
$upgrade_plain[] = $label;
if ( ! wpforms()->is_pro() && in_array( $cf7_field->basetype, $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 ( $cf7_field->basetype ) {
// Plain text, email, URL, number, and textarea fields.
$type = $cf7_field->basetype;
if ( $type === 'url' && ! wpforms()->is_pro() ) {
$form['fields'][ $field_id ] = [
'required' => $cf7_field->is_required() ? '1' : '',
'placeholder' => $this->get_field_placeholder_default( $cf7_field ),
'default_value' => $this->get_field_placeholder_default( $cf7_field, 'default' ),
'cf7_name' => $cf7_field->name,
$form['fields'][ $field_id ] = [
'format' => 'international',
'required' => $cf7_field->is_required() ? '1' : '',
'placeholder' => $this->get_field_placeholder_default( $cf7_field ),
'default_value' => $this->get_field_placeholder_default( $cf7_field, 'default' ),
'cf7_name' => $cf7_field->name,
$type = wpforms()->is_pro() ? 'date-time' : 'text';
$form['fields'][ $field_id ] = [
'required' => $cf7_field->is_required() ? '1' : '',
'date_placeholder' => '',
'date_format' => 'm/d/Y',
'date_type' => 'datepicker',
'time_format' => 'g:i A',
'cf7_name' => $cf7_field->name,
// Select, radio, and checkbox fields.
$options = (array) $cf7_field->labels;
foreach ( $options as $option ) {
$form['fields'][ $field_id ] = [
'type' => $cf7_field->basetype,
'required' => $cf7_field->is_required() ? '1' : '',
'cf7_name' => $cf7_field->name,
$cf7_field->basetype === 'select' &&
$cf7_field->has_option( 'include_blank' )
$form['fields'][ $field_id ]['placeholder'] = '---';
$file_types = $cf7_field->get_option( 'filetypes' );
$limit = $cf7_field->get_option( 'limit' );
if ( ! empty( $file_types[0] ) ) {
$extensions = implode( ',', explode( '|', strtolower( preg_replace( '/[^A-Za-z0-9|]/', '', strtolower( $file_types[0] ) ) ) ) );
if ( ! empty( $limit[0] ) ) {
$mb = ( strpos( $limit, 'm' ) !== false );
$kb = ( strpos( $limit, 'kb' ) !== false );
$limit = (int) preg_replace( '/[^0-9]/', '', $limit );
$max_size = round( $limit / 1024, 1 );
$max_size = round( $limit / 1048576, 1 );
$form['fields'][ $field_id ] = [
'extensions' => $extensions,
'required' => $cf7_field->is_required() ? '1' : '',
'cf7_name' => $cf7_field->name,
$form['fields'][ $field_id ] = [
'label' => esc_html__( 'Acceptance Field', 'wpforms-lite' ),
'cf7_name' => $cf7_field->name,
// If we are only analyzing the form, we can stop here and return the
// details about this form.
'name' => $cf7_form_name,
'upgrade_plain' => $upgrade_plain,
'upgrade_omit' => $upgrade_omit,
if ( ! empty( $cf7_properties['messages']['mail_sent_ok'] ) ) {
$form['settings']['confirmation_message'] = $cf7_properties['messages']['mail_sent_ok'];
// 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', '' );
$type = wpforms_setting( 'recaptcha-type', 'v2' );
// Try to abstract keys from CF7.
if ( empty( $site_key ) || empty( $secret_key ) ) {
$cf7_settings = get_option( 'wpcf7' );
! empty( $cf7_settings['recaptcha'] ) &&
is_array( $cf7_settings['recaptcha'] )
foreach ( $cf7_settings['recaptcha'] as $key => $val ) {
if ( ! empty( $key ) && ! empty( $val ) ) {
$wpforms_settings = get_option( 'wpforms_settings', [] );
$wpforms_settings['recaptcha-site-key'] = $site_key;
$wpforms_settings['recaptcha-secret-key'] = $secret_key;
update_option( 'wpforms_settings', $wpforms_settings );
// Don't enable reCAPTCHA if user had configured invisible reCAPTCHA.
$form['settings']['recaptcha'] = '1';
// Setup email notifications.
if ( ! empty( $cf7_properties['mail']['subject'] ) ) {
$form['settings']['notifications'][1]['subject'] = $this->get_smarttags( $cf7_properties['mail']['subject'], $form['fields'] );
if ( ! empty( $cf7_properties['mail']['recipient'] ) ) {
$form['settings']['notifications'][1]['email'] = $this->get_smarttags( $cf7_properties['mail']['recipient'], $form['fields'] );
if ( ! empty( $cf7_properties['mail']['body'] ) ) {
$form['settings']['notifications'][1]['message'] = $this->get_smarttags( $cf7_properties['mail']['body'], $form['fields'] );
if ( ! empty( $cf7_properties['mail']['additional_headers'] ) ) {
$form['settings']['notifications'][1]['replyto'] = $this->get_replyto( $cf7_properties['mail']['additional_headers'], $form['fields'] );
if ( ! empty( $cf7_properties['mail']['sender'] ) ) {
$sender = $this->get_sender_details( $cf7_properties['mail']['sender'], $form['fields'] );
$form['settings']['notifications'][1]['sender_name'] = $sender['name'];
$form['settings']['notifications'][1]['sender_address'] = $sender['address'];
if ( ! empty( $cf7_properties['mail_2'] ) && (int) $cf7_properties['mail_2']['active'] === 1 ) {
// Check if a secondary notification is enabled, if so set defaults
$form['settings']['notifications'][2] = [
'notification_name' => esc_html__( 'Notification 2', '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}',
if ( ! empty( $cf7_properties['mail_2']['subject'] ) ) {
$form['settings']['notifications'][2]['subject'] = $this->get_smarttags( $cf7_properties['mail_2']['subject'], $form['fields'] );
if ( ! empty( $cf7_properties['mail_2']['recipient'] ) ) {
$form['settings']['notifications'][2]['email'] = $this->get_smarttags( $cf7_properties['mail_2']['recipient'], $form['fields'] );
if ( ! empty( $cf7_properties['mail_2']['body'] ) ) {
$form['settings']['notifications'][2]['message'] = $this->get_smarttags( $cf7_properties['mail_2']['body'], $form['fields'] );
if ( ! empty( $cf7_properties['mail_2']['additional_headers'] ) ) {
$form['settings']['notifications'][2]['replyto'] = $this->get_replyto( $cf7_properties['mail_2']['additional_headers'], $form['fields'] );
if ( ! empty( $cf7_properties['mail_2']['sender'] ) ) {
$sender = $this->get_sender_details( $cf7_properties['mail_2']['sender'], $form['fields'] );
$form['settings']['notifications'][2]['sender_name'] = $sender['name'];
$form['settings']['notifications'][2]['sender_address'] = $sender['address'];
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
* Lookup and return the placeholder or default value.
* @param object $field Field object.
* @param string $type Type of the field.
public function get_field_placeholder_default( $field, $type = 'placeholder' ) {
$default_value = (string) reset( $field->values );
if ( $field->has_option( 'placeholder' ) || $field->has_option( 'watermark' ) ) {
$placeholder = $default_value;