: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace WPForms\Integrations\Gutenberg;
use WPForms\Frontend\CSSVars;
use WPForms\Integrations\IntegrationInterface;
use WPForms\Admin\Education\StringsTrait;
use WP_Error; // phpcs:ignore WPForms.PHP.UseStatement.UnusedUseStatement
use WP_REST_Response; // phpcs:ignore WPForms.PHP.UseStatement.UnusedUseStatement
* Form Selector Gutenberg block with live preview.
abstract class FormSelector implements IntegrationInterface {
const DEFAULT_ATTRIBUTES = [
'backgroundImage' => CSSVars::ROOT_VARS['background-image'],
'backgroundPosition' => CSSVars::ROOT_VARS['background-position'],
'backgroundRepeat' => CSSVars::ROOT_VARS['background-repeat'],
'backgroundSizeMode' => CSSVars::ROOT_VARS['background-size'],
'backgroundSize' => CSSVars::ROOT_VARS['background-size'],
'backgroundWidth' => CSSVars::ROOT_VARS['background-width'],
'backgroundHeight' => CSSVars::ROOT_VARS['background-height'],
'backgroundUrl' => CSSVars::ROOT_VARS['background-url'],
'backgroundColor' => CSSVars::ROOT_VARS['background-color'],
'fieldBorderRadius' => CSSVars::ROOT_VARS['field-border-radius'],
'fieldBorderStyle' => CSSVars::ROOT_VARS['field-border-style'],
'fieldBorderSize' => CSSVars::ROOT_VARS['field-border-size'],
'fieldBackgroundColor' => CSSVars::ROOT_VARS['field-background-color'],
'fieldBorderColor' => CSSVars::ROOT_VARS['field-border-color'],
'fieldTextColor' => CSSVars::ROOT_VARS['field-text-color'],
'fieldMenuColor' => CSSVars::ROOT_VARS['field-menu-color'],
'labelColor' => CSSVars::ROOT_VARS['label-color'],
'labelSublabelColor' => CSSVars::ROOT_VARS['label-sublabel-color'],
'labelErrorColor' => CSSVars::ROOT_VARS['label-error-color'],
'buttonSize' => 'medium',
'buttonBorderStyle' => CSSVars::ROOT_VARS['button-border-style'],
'buttonBorderSize' => CSSVars::ROOT_VARS['button-border-size'],
'buttonBorderRadius' => CSSVars::ROOT_VARS['button-border-radius'],
'buttonBackgroundColor' => CSSVars::ROOT_VARS['button-background-color'],
'buttonTextColor' => CSSVars::ROOT_VARS['button-text-color'],
'buttonBorderColor' => CSSVars::ROOT_VARS['button-border-color'],
'pageBreakColor' => CSSVars::ROOT_VARS['page-break-color'],
'containerPadding' => CSSVars::ROOT_VARS['container-padding'],
'containerBorderStyle' => CSSVars::ROOT_VARS['container-border-style'],
'containerBorderWidth' => CSSVars::ROOT_VARS['container-border-width'],
'containerBorderColor' => CSSVars::ROOT_VARS['container-border-color'],
'containerBorderRadius' => CSSVars::ROOT_VARS['container-border-radius'],
'containerShadowSize' => CSSVars::CONTAINER_SHADOW_SIZE['none']['box-shadow'],
'copyPasteJsonValue' => '',
* Rest API class instance.
* Rest API class instance.
protected $themes_data_obj;
protected $render_engine;
protected $disable_css_setting;
* Instance of CSSVars class.
* Callbacks registered for wpforms_frontend_container_class filter.
* Currently displayed form Id.
private $current_form_id = 0;
* Indicate if current integration is allowed to load.
public function allow_load(): bool {
return function_exists( 'register_block_type' );
$this->render_engine = wpforms_get_render_engine();
$this->disable_css_setting = (int) wpforms_setting( 'disable-css', '1' );
$this->css_vars_obj = wpforms()->get( 'css_vars' );
wpforms()->register_instance( 'formselector_themes_data', $this->themes_data_obj );
protected function hooks() {
add_action( 'init', [ $this, 'register_block' ] );
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] );
add_action( 'wpforms_frontend_output_container_after', [ $this, 'replace_wpforms_frontend_container_class_filter' ] );
add_filter( 'wpforms_frontend_form_action', [ $this, 'form_action_filter' ], 10, 2 );
* Replace the filter registered for wpforms_frontend_container_class.
* @param array $form_data Form data.
public function replace_wpforms_frontend_container_class_filter( $form_data ) { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
if ( empty( $this->callbacks[ $form_data['id'] ] ) ) {
$callback = array_shift( $this->callbacks[ $form_data['id'] ] );
remove_filter( 'wpforms_frontend_container_class', $callback );
if ( ! empty( $this->callbacks[ $form_data['id'] ] ) ) {
add_filter( 'wpforms_frontend_container_class', reset( $this->callbacks[ $form_data['id'] ] ), 10, 2 );
* Register WPForms Gutenberg block on the backend.
public function register_block() {
'fieldBackgroundColor' => [
'labelSublabelColor' => [
'buttonBorderRadius' => [
'buttonBackgroundColor' => [
'backgroundPosition' => [
'backgroundSizeMode' => [
'containerBorderStyle' => [
'containerBorderWidth' => [
'containerBorderColor' => [
'containerBorderRadius' => [
'containerShadowSize' => [
'copyPasteJsonValue' => [
$this->register_styles();
* Modify WPForms block attributes.
* @param array $attributes Attributes.
'attributes' => apply_filters( 'wpforms_gutenberg_form_selector_attributes', $attributes ), // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
'style' => 'wpforms-gutenberg-form-selector',
'editor_style' => 'wpforms-integrations',
'render_callback' => [ $this, 'get_form_html' ],
* Register WPForms Gutenberg block styles.
protected function register_styles() {
$min = wpforms_get_min_suffix();
WPFORMS_PLUGIN_URL . "assets/css/admin-integrations{$min}.css",
if ( $this->disable_css_setting === 3 ) {
$css_file = $this->disable_css_setting === 2 ? 'base' : 'full';
'wpforms-gutenberg-form-selector',
WPFORMS_PLUGIN_URL . "assets/css/frontend/{$this->render_engine}/wpforms-{$css_file}{$min}.css",
[ 'wp-edit-blocks', 'wpforms-integrations' ],
* Load WPForms Gutenberg block scripts.
public function enqueue_block_editor_assets() {
$min = wpforms_get_min_suffix();
wp_enqueue_style( 'wpforms-integrations' );
wp_set_script_translations( 'wpforms-gutenberg-form-selector', 'wpforms-lite' );
// jQuery.Confirm Reloaded.
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.css',
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.js',
// Support for the legacy form selector.
// It is located in the common namespace.
if ( $this->is_legacy_block() ) {
'wpforms-gutenberg-form-selector',
WPFORMS_PLUGIN_URL . "assets/js/integrations/gutenberg/formselector-legacy.es5{$min}.js",
[ 'wp-blocks', 'wp-i18n', 'wp-element', 'jquery' ],
if ( $this->render_engine === 'modern' ) {
WPFORMS_PLUGIN_URL . "assets/js/frontend/wpforms-modern{$min}.js",
[ 'wpforms-gutenberg-form-selector' ],
'wpforms-admin-education-core',
WPFORMS_PLUGIN_URL . "assets/js/admin/education/core{$min}.js",
[ 'jquery', 'jquery-confirm' ],
'wpforms-admin-education-core',
* Whether the block is legacy.
protected function is_legacy_block() {
return version_compare( $GLOBALS['wp_version'], '6.0', '<' );
* Register API route for Gutenberg block.
public function register_api_route() {
_deprecated_function( __METHOD__, '1.8.8 of the WPForms plugin', '\WPForms\Integrations\Gutenberg\RestApi::register_api_routes()' );
$this->rest_api_obj->register_api_routes();
* Wrap localized data in a protected WP_REST_Response object.
* @see https://developer.wordpress.org/reference/functions/rest_ensure_response/
* @return WP_Error|WP_REST_Response
public function protected_data_callback() {
_deprecated_function( __METHOD__, '1.8.8 of the WPForms plugin', '\WPForms\Integrations\Gutenberg\RestApi::get_forms()' );
return $this->rest_api_obj->get_forms();