: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$wpforms_settings['recaptcha-secret-key'] = $pf_form['pirateformsopt_recaptcha_secretkey'];
$wpforms_settings['recaptcha-type'] = 'v2';
update_option( 'wpforms_settings', $wpforms_settings );
( ! empty( $site_key ) && ! empty( $secret_key ) ) ||
( ! empty( $wpforms_settings['recaptcha-site-key'] ) && ! empty( $wpforms_settings['recaptcha-secret-key'] ) )
$form['settings']['recaptcha'] = '1';
$this->import_smtp( $pf_form_id, $form );
$this->add_form( $form, $unsupported, $upgrade_plain, $upgrade_omit );
* Replace 3rd-party form provider tags/shortcodes with our own Smart Tags.
* See: PirateForms_Util::get_magic_tags() for all PF tags.
* @param string $string String to process the smart tag in.
* @param array $fields List of fields for the form.
public function get_smarttags( $string, $fields ) {
foreach ( self::$tags as $tag ) {
if ( $tag === '[email]' ) {
foreach ( $fields as $field ) {
if ( $field['type'] === 'email' ) {
$wpf_tag = '{field_id="' . $field['id'] . '"}';
$string = str_replace( $tag, $wpf_tag, $string );
* Import SMTP settings from Default form only.
* @param int $pf_form_id PirateForms form ID.
* @param array $form WPForms form array.
protected function import_smtp( $pf_form_id, $form ) {
// At this point we import only default form SMTP settings.
if ( $pf_form_id !== 0 ) {
$pf_form = $this->get_form( 0 );
if ( empty( $pf_form['pirateformsopt_use_smtp'] ) || $pf_form['pirateformsopt_use_smtp'] !== 'yes' ) {
// If user has WP Mail SMTP already activated - do nothing as it's most likely already configured.
if ( is_plugin_active( self::SLUG_SMTP_PLUGIN ) ) {
// Check that we successfully installed and activated the plugin.
if ( ! $this->install_activate_smtp() ) {
* Finally, start the settings importing.
// WP Mail SMTP 1.x and PHP 5.3+ are allowed. Older WPMS versions are ignored.
if ( ! function_exists( 'wp_mail_smtp' ) ) {
// TODO: change to \WPMailSMTP\Options in future.
$options = get_option( 'wp_mail_smtp', [] );
$options['mail']['from_email'] = $this->get_smarttags( $pf_form['pirateformsopt_email'], $form['fields'] );
$options['mail']['mailer'] = 'smtp';
$options['smtp']['host'] = $pf_form['pirateformsopt_smtp_host'];
$options['smtp']['port'] = $pf_form['pirateformsopt_smtp_port'];
$options['smtp']['encryption'] = empty( $pf_form['pirateformsopt_use_secure'] ) ? 'none' : $pf_form['pirateformsopt_use_secure'];
$options['smtp']['auth'] = ! empty( $pf_form['pirateformsopt_use_smtp_authentication'] ) && $pf_form['pirateformsopt_use_smtp_authentication'] === 'yes';
$options['smtp']['user'] = $pf_form['pirateformsopt_smtp_username'];
$options['smtp']['pass'] = $pf_form['pirateformsopt_smtp_password'];
update_option( 'wp_mail_smtp', $options );
* Do all the voodoo to install and activate the WP Mail SMTP plugin behind the scene.
* No user interaction is needed.
protected function install_activate_smtp() {
* If installed but not activated - bail.
* We don't want to break current site email deliverability.
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
// FALSE will bail the import.
if ( array_key_exists( self::SLUG_SMTP_PLUGIN, get_plugins() ) ) {
'provider' => $this->slug,
'page' => 'wpforms-tools',
$creds = request_filesystem_credentials( esc_url_raw( $url ), '', false, false, null );
// Check for file system permissions.
if ( $creds === false ) {
if ( ! WP_Filesystem( $creds ) ) {
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
// Create the plugin upgrader with our custom skin.
$installer = new PluginSilentUpgrader( new PluginSilentUpgraderSkin() );
if ( ! method_exists( $installer, 'install' ) ) {
$installer->install( self::URL_SMTP_ZIP );
// Flush the cache and return the newly installed plugin basename.
if ( $installer->plugin_info() ) {
$plugin_basename = $installer->plugin_info();
// Activate, do not redirect, run the plugin activation routine.
$activated = activate_plugin( $plugin_basename );
if ( ! is_wp_error( $activated ) ) {