: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$total = wp_count_posts( $source );
$total = $total->publish;
$pt = get_post_type_object( $source );
$source_name = $pt->labels->name;
foreach ( $posts as $post ) {
$items[] = esc_html( wpforms_get_post_title( $post ) );
} elseif ( $type === 'taxonomy' ) {
$type_name = esc_html__( 'taxonomy', 'wpforms-lite' );
$terms = wpforms_get_hierarchical_object(
'wpforms_dynamic_choice_taxonomy_args',
$total = wp_count_terms( $source );
$tax = get_taxonomy( $source );
$source_name = $tax->labels->name;
foreach ( $terms as $term ) {
$items[] = esc_html( wpforms_get_term_name( $term ) );
'source_name' => $source_name,
'type_name' => $type_name,
add_action( 'wp_ajax_wpforms_builder_dynamic_source', 'wpforms_builder_dynamic_source' );
* Perform test connection to verify that the current web host can successfully
* make outbound SSL connections.
function wpforms_verify_ssl() {
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! wpforms_current_user_can() ) {
'msg' => esc_html__( 'You do not have permission to perform this operation.', 'wpforms-lite' ),
$response = wp_remote_post( 'https://wpforms.com/connection-test.php' );
if ( 200 === wp_remote_retrieve_response_code( $response ) ) {
'msg' => esc_html__( 'Success! Your server can make SSL connections.', 'wpforms-lite' ),
'msg' => esc_html__( 'There was an error and the connection failed. Please contact your web host with the technical details below.', 'wpforms-lite' ),
'debug' => '<pre>' . print_r( map_deep( $response, 'wp_strip_all_tags' ), true ) . '</pre>',
add_action( 'wp_ajax_wpforms_verify_ssl', 'wpforms_verify_ssl' );
* @since 1.6.2.3 Updated the permissions checking.
function wpforms_deactivate_addon() {
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! current_user_can( 'deactivate_plugins' ) ) {
wp_send_json_error( esc_html__( 'Plugin deactivation is disabled for you on this site.', 'wpforms-lite' ) );
$type = empty( $_POST['type'] ) ? 'addon' : sanitize_key( $_POST['type'] );
if ( isset( $_POST['plugin'] ) ) {
$plugin = sanitize_text_field( wp_unslash( $_POST['plugin'] ) );
deactivate_plugins( $plugin );
do_action( 'wpforms_plugin_deactivated', $plugin );
if ( $type === 'plugin' ) {
wp_send_json_success( esc_html__( 'Plugin deactivated.', 'wpforms-lite' ) );
wp_send_json_success( esc_html__( 'Addon deactivated.', 'wpforms-lite' ) );
wp_send_json_error( esc_html__( 'Could not deactivate the addon. Please deactivate from the Plugins page.', 'wpforms-lite' ) );
add_action( 'wp_ajax_wpforms_deactivate_addon', 'wpforms_deactivate_addon' );
* @since 1.6.2.3 Updated the permissions checking.
function wpforms_activate_addon() {
check_ajax_referer( 'wpforms-admin', 'nonce' );
// Check for permissions.
if ( ! current_user_can( 'activate_plugins' ) ) {
wp_send_json_error( esc_html__( 'Plugin activation is disabled for you on this site.', 'wpforms-lite' ) );
'plugin' => __( 'Plugin activated.', 'wpforms-lite' ),
'addon' => __( 'Addon activated.', 'wpforms-lite' ),
'plugin' => __( 'Could not activate the plugin. Please activate it on the Plugins page.', 'wpforms-lite' ),
'addon' => __( 'Could not activate the addon. Please activate it on the Plugins page.', 'wpforms-lite' ),
$type = ! empty( $_POST['type'] ) ? sanitize_key( $_POST['type'] ) : 'addon';
$success_message = $success_messages[ $type ];
$error_message = $error_messages[ $type ];
if ( isset( $_POST['plugin'] ) ) {
$plugin = sanitize_text_field( wp_unslash( $_POST['plugin'] ) );
$activate = wpforms_activate_plugin( $plugin );
* Fire after plugin activating via the WPForms installer.
* @param string $plugin Path to the plugin file relative to the plugins' directory.
do_action( 'wpforms_plugin_activated', $plugin );
if ( $activate === null ) {
wp_send_json_success( wp_kses_post( $success_message ) );
$error_message = $activate->get_error_message();
wp_send_json_error( wp_kses_post( $error_message ) );
add_action( 'wp_ajax_wpforms_activate_addon', 'wpforms_activate_addon' );
* @since 1.6.2.3 Updated the permissions checking.
function wpforms_install_addon() {
check_ajax_referer( 'wpforms-admin', 'nonce' );
$generic_error = esc_html__( 'There was an error while performing your request.', 'wpforms-lite' );
$type = ! empty( $_POST['type'] ) ? sanitize_key( $_POST['type'] ) : 'addon';
// Check if new installations are allowed.
if ( ! wpforms_can_install( $type ) ) {
wp_send_json_error( $generic_error );
$error = $type === 'plugin'
? esc_html__( 'Could not install the plugin. Please download and install it manually.', 'wpforms-lite' )
wp_kses( /* translators: %1$s - addon download URL, %2$s - link to manual installation guide, %3$s - link to contact support. */
__( 'Could not install the addon. Please <a href="%1$s" target="_blank" rel="noopener noreferrer">download it from wpforms.com</a> and <a href="%2$s" target="_blank" rel="noopener noreferrer">install it manually</a>, or <a href="%3$s" target="_blank" rel="noopener noreferrer">contact support</a> for assistance.', 'wpforms-lite' ),
esc_url( wpforms_utm_link( 'https://wpforms.com/account/licenses/', 'Licenses', 'Addons Error' ) ),
esc_url( wpforms_utm_link( 'https://wpforms.com/docs/how-to-manually-install-addons-in-wpforms/', 'Addons Doc', 'Addons Error' ) ),
esc_url( wpforms_utm_link( 'https://wpforms.com/contact/', 'Contact', 'Addons Error' ) )
$plugin_url = ! empty( $_POST['plugin'] ) ? esc_url_raw( wp_unslash( $_POST['plugin'] ) ) : '';
if ( empty( $plugin_url ) ) {
wp_send_json_error( $error );
$args_str = ! empty( $_POST['args'] ) ? sanitize_text_field( wp_unslash( $_POST['args'] ) ) : '';
$args = json_decode( $args_str, true ) ?? [];
// Set the current screen to avoid undefined notices.
set_current_screen( 'wpforms_page_wpforms-settings' );
'page' => 'wpforms-addons',
$creds = request_filesystem_credentials( $url, '', false, false, null );
// Hide the filesystem credentials form.
// Check for file system permissions.
if ( $creds === false ) {
wp_send_json_error( $error );
if ( ! WP_Filesystem( $creds ) ) {
wp_send_json_error( $error );
* We do not need any extra credentials if we have gotten this far, so let's install the plugin.
require_once WPFORMS_PLUGIN_DIR . 'includes/admin/class-install-skin.php';
// 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 WPForms\Helpers\PluginSilentUpgrader( new WPForms_Install_Skin() );
if ( ! method_exists( $installer, 'install' ) ) {
wp_send_json_error( $error );
$installer->install( $plugin_url, $args );
// Flush the cache and return the newly installed plugin basename.
$plugin_basename = $installer->plugin_info();
if ( empty( $plugin_basename ) ) {
wp_send_json_error( $error );
'basename' => $plugin_basename,
// Check for permissions.
if ( ! current_user_can( 'activate_plugins' ) ) {
$result['msg'] = $type === 'plugin' ? esc_html__( 'Plugin installed.', 'wpforms-lite' ) : esc_html__( 'Addon installed.', 'wpforms-lite' );
wp_send_json_success( $result );
// Activate the plugin silently.
$activated = activate_plugin( $plugin_basename );
if ( ! is_wp_error( $activated ) ) {
* Fire after plugin activating via the WPForms installer.
* @param string $plugin_basename Path to the plugin file relative to the plugins directory.
do_action( 'wpforms_plugin_activated', $plugin_basename );
$result['is_activated'] = true;
$result['msg'] = $type === 'plugin' ? esc_html__( 'Plugin installed & activated.', 'wpforms-lite' ) : esc_html__( 'Addon installed & activated.', 'wpforms-lite' );
wp_send_json_success( $result );
// Fallback error just in case.
wp_send_json_error( $result );
add_action( 'wp_ajax_wpforms_install_addon', 'wpforms_install_addon' );
* Search pages for dropdown.
function wpforms_ajax_search_pages_for_dropdown() {
if ( ! check_ajax_referer( 'wpforms-builder', 'nonce', false ) ) {
wp_send_json_error( esc_html__( 'Your session expired. Please reload the builder.', 'wpforms-lite' ) );
if ( ! array_key_exists( 'search', $_GET ) ) {
wp_send_json_error( esc_html__( 'Incorrect usage of this operation.', 'wpforms-lite' ) );
$result_pages = wpforms_search_pages_for_dropdown(
sanitize_text_field( wp_unslash( $_GET['search'] ) )
if ( empty( $result_pages ) ) {
wp_send_json_success( [] );
wp_send_json_success( $result_pages );
add_action( 'wp_ajax_wpforms_ajax_search_pages_for_dropdown', 'wpforms_ajax_search_pages_for_dropdown' );