This repository has been archived on 2022-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
divi/includes/builder/module/settings/migration/ContactFormItemOptionsSerialization.php
2021-12-07 11:08:05 +00:00

58 lines
1.4 KiB
PHP

<?php
/**
* Migration for the ContactFormItem module which fixes quote serialization for checkbox, radio and select field options.
*
* @since 3.10
*/
class ET_Builder_Module_Settings_Migration_ContactFormItemOptionsSerialization extends ET_Builder_Module_Settings_Migration {
public function get_modules() {
return array( 'et_pb_contact_field' );
}
public function get_fields() {
return array(
'checkbox_options' => array(
'affected_fields' => array(
'checkbox_options' => $this->get_modules(),
),
),
'radio_options' => array(
'affected_fields' => array(
'radio_options' => $this->get_modules(),
),
),
'select_options' => array(
'affected_fields' => array(
'select_options' => $this->get_modules(),
),
),
);
}
public function migrate( $field_name, $current_value, $module_slug, $saved_value, $saved_field_name, $attrs, $content, $module_address ) {
if ( json_decode( $saved_value ) ) {
return $saved_value;
}
$pattern = '/
\{
("value":")(.*?)(",)
(
"checked":.,?
.*?
)
\}
/ix';
$saved_value = preg_replace_callback( $pattern, array( $this, 'escape_quotes' ), $saved_value );
return $saved_value;
}
public function escape_quotes( $matches ) {
return '{' . $matches[1] . preg_replace( '/(?<!\\\\)"/', '\\"', $matches[2] ) . $matches[3] . $matches[4] . '}';
}
}
return new ET_Builder_Module_Settings_Migration_ContactFormItemOptionsSerialization();