Upgarded to 4.17.4

This commit is contained in:
2022-06-23 13:17:18 +01:00
parent 80f1e87db9
commit a04fb0c7af
404 changed files with 54683 additions and 4417 deletions

View File

@ -77,6 +77,10 @@ class ET_Builder_Global_Presets_History {
$history = json_decode( stripslashes( $_POST['history'] ) );
if ( empty( $history->history ) ) {
et_core_die( esc_html__( 'Global History data is empty.', 'et_builder' ) );
}
if ( self::sanitize_and_validate( $history ) ) {
$current_settings = $history->history[ $history->index ];
et_update_option( ET_Builder_Global_Presets_Settings::GLOBAL_PRESETS_OPTION, $current_settings->settings );
@ -265,6 +269,9 @@ class ET_Builder_Global_Presets_History {
);
}
// Ensure history is an object.
$history = is_object( $history ) ? $history : (object) $history;
$this->_apply_attribute_migrations( $history );
return $history;
@ -323,7 +330,14 @@ class ET_Builder_Global_Presets_History {
* @return void
*/
protected function _apply_attribute_migrations( $history ) {
if ( empty( $history->history ) ) {
return;
}
foreach ( $history->history as $record ) {
if ( empty( $record->settings ) ) {
continue;
}
foreach ( $record->settings as $module => $preset_structure ) {
foreach ( $preset_structure->presets as $preset_id => $preset ) {
ET_Builder_Global_Presets_Settings::migrate_settings_as_module_attributes( $preset, $module );

View File

@ -6,6 +6,7 @@ class ET_Builder_Global_Presets_Settings {
const CUSTOMIZER_SETTINGS_MIGRATED_FLAG = 'customizer_settings_migrated_flag';
const GLOBAL_PRESETS_OPTION = 'builder_global_presets';
const GLOBAL_PRESETS_OPTION_TEMP = 'builder_global_presets_temp';
const CUSTOM_DEFAULTS_MIGRATED_FLAG = 'custom_defaults_migrated_flag';
const MODULE_PRESET_ATTRIBUTE = '_module_preset';
const MODULE_INITIAL_PRESET_ID = '_initial';
@ -92,6 +93,7 @@ class ET_Builder_Global_Presets_Settings {
// phpcs:enable
add_action( 'et_builder_ready', array( $this, 'migrate_custom_defaults' ), 100 );
add_action( 'et_builder_ready', array( $this, 'apply_attribute_migrations' ), 101 );
}
/**
@ -138,6 +140,51 @@ class ET_Builder_Global_Presets_Settings {
return $this->_settings;
}
/**
* Returns builder Temp Presets settings.
*
* @since 4.17.0
*
* @return object
*/
public function get_temp_presets() {
$global_presets_temp = et_get_option( self::GLOBAL_PRESETS_OPTION_TEMP, array(), '', true );
return $global_presets_temp;
}
/**
* Remove Temp Presets settings from the database.
*
* @since 4.17.0
*
* @return object
*/
public function clear_temp_presets() {
$all_presets = self::get_global_presets();
$temp_preset = self::get_temp_presets();
if ( empty( $temp_preset ) ) {
return;
}
foreach ( $temp_preset as $module => $preset_structure ) {
if ( isset( $preset_structure['presets'] ) ) {
foreach ( $preset_structure['presets'] as $preset_id => $preset ) {
if ( isset( $all_presets->$module->presets->$preset_id ) ) {
unset( $all_presets->$module->presets->$preset_id );
}
}
}
}
// Save presets without temp.
et_update_option( self::GLOBAL_PRESETS_OPTION, $all_presets );
// Clean all temp presets.
et_update_option( self::GLOBAL_PRESETS_OPTION_TEMP, array() );
}
/**
* Checks if the gives preset ID exists
*
@ -235,6 +282,7 @@ class ET_Builder_Global_Presets_Settings {
* Returns Global Presets settings with global colors injected.
*
* @since 4.10.0
* @since 4.17.2 Perform substring replacement (for compound settings like background gradient stops).
*
* @param array $attrs - The module attributes.
*
@ -247,9 +295,21 @@ class ET_Builder_Global_Presets_Settings {
$gc_info = json_decode( $attrs['global_colors_info'], true );
// Gather system-wide Global Colors info (including CSS color values and 'active' status).
$all_global_colors_info = et_get_option( 'et_global_colors' );
foreach ( $gc_info as $color_id => $option_names ) {
foreach ( $option_names as $option_name ) {
$attrs[ $option_name ] = $color_id;
// Get the CSS color value assiciated with this GCID.
if ( ! empty( $all_global_colors_info[ $color_id ]['color'] ) ) {
$gcid_color_value = $all_global_colors_info[ $color_id ]['color'];
} else {
// We can't inject the CSS color value if we don't have record of it.
continue;
}
// Replace CSS color value with GCID wherever it's found within the settings string.
$attrs[ $option_name ] = str_replace( $color_id, $gcid_color_value, $attrs[ $option_name ] );
}
}
@ -344,7 +404,7 @@ class ET_Builder_Global_Presets_Settings {
*
* @since 4.5.0
*
* @param object $custom_defaults - The previous Custom Defaults
* @param object $custom_defaults - The previous Custom Defaults.
*
* @return object
*/
@ -395,10 +455,23 @@ class ET_Builder_Global_Presets_Settings {
et_update_option( self::CUSTOM_DEFAULTS_MIGRATED_FLAG, true );
}
/**
* Apply attribute migrations.
*
* @since 4.14.0
*/
public function apply_attribute_migrations() {
foreach ( $this->_settings as $module => $preset_structure ) {
foreach ( $preset_structure->presets as $preset_id => $preset ) {
self::migrate_settings_as_module_attributes( $preset, $module );
}
}
}
/**
* Configuring and running migration of global presets via "et_pb_module_shortcode_attributes".
*
* @since ?
* @since 4.14.0
*
* @param object $preset Global preset object.
* @param string $module_slug Module slug.
@ -444,15 +517,16 @@ class ET_Builder_Global_Presets_Settings {
/**
* Converts module type (slug).
*
* Used to separate Global Presets settings for modules sharing the same slug but having different meaning
* For example: Regular, Fullwidth and Specialty section types
*
* @since 4.5.0
*
* @param string $type - The module type (slug).
* @param array $attrs - The module attributes.
* @param string $type The module type (slug).
* @param array $attrs The module attributes.
*
* @return string - The converted module type (slug)
* @return string The converted module type (slug)
*/
public function maybe_convert_module_type( $type, $attrs ) {
if ( isset( self::$_module_types_conversion_map[ $type ] ) ) {
@ -531,7 +605,7 @@ class ET_Builder_Global_Presets_Settings {
*
* Returns FALSE when the value is an Object or an array.
*
* @since ?? Included PHPDoc description.
* @since 4.13.0 Included PHPDoc description.
* @since 4.5.0
*
* @param $value - The Global Presets setting value
@ -548,13 +622,15 @@ class ET_Builder_Global_Presets_Settings {
* Also used to normalize global colors
*
* @since 4.5.0
* @since 4.17.2 Modified the global color option check to perform a substring match on multipart settings (like gradient stops).
*
* @param $presets - The object representing Global Presets settings
* @param object|array $presets The object representing Global Presets settings.
*
* @return object
*/
protected function _normalize_global_presets( $presets ) {
$result = (object) array();
$result = (object) array();
$temp_preset = self::get_temp_presets();
foreach ( $presets as $module => $preset_structure ) {
if ( isset( $preset_structure->presets ) ) {
@ -567,6 +643,7 @@ class ET_Builder_Global_Presets_Settings {
$result->$module->presets->$preset_id->created = $preset->created;
$result->$module->presets->$preset_id->updated = $preset->updated;
$result->$module->presets->$preset_id->version = $preset->version;
$result->$module->presets->$preset_id->is_temp = isset( $temp_preset[ $module ]['presets'][ $preset_id ] );
if ( isset( $preset->settings ) ) {
$result->$module->presets->$preset_id->settings = (object) array();
@ -579,8 +656,8 @@ class ET_Builder_Global_Presets_Settings {
)
);
// Since we still support PHP 5.2 we can't use `array_filter` with array keys
// So check if defaults have empty key
// Since we still support PHP 5.2 we can't use `array_filter`
// with array keys, so use this to skip any empty key that's found.
if ( isset( $settings_filtered[''] ) ) {
continue;
}
@ -589,20 +666,46 @@ class ET_Builder_Global_Presets_Settings {
$result->$module->presets->$preset_id->settings->$setting_name = $value;
}
// Insert correct global color IDs for affected settings.
$global_colors_info = isset( $settings_filtered['global_colors_info'] ) ? json_decode( $settings_filtered['global_colors_info'], true ) : array();
// Look for settings in this module that use global colors.
if ( isset( $settings_filtered['global_colors_info'] ) ) {
$module_global_colors_info = json_decode( $settings_filtered['global_colors_info'], true );
} else {
// Nothing more to be done here if this module's `global_colors_info` setting is empty,
// so advance the `$preset_structure->presets as $preset_id => $preset` loop.
continue;
}
if ( ! empty( $global_colors_info ) ) {
foreach ( $global_colors_info as $color_id => $options_list ) {
if ( empty( $options_list ) ) {
continue;
}
/**
* Presets: Global Color injection.
*
* Find GCID references and replace them with their CSS color values.
*/
foreach ( $options_list as $global_color_option ) {
if ( isset( $result->$module->presets->$preset_id->settings->$global_color_option ) ) {
$result->$module->presets->$preset_id->settings->$global_color_option = $color_id;
}
}
// Gather system-wide Global Colors info (including CSS color values and 'active' status).
$all_global_colors_info = et_get_option( 'et_global_colors' );
foreach ( $module_global_colors_info as $gcid => $settings_that_use_this_gcid ) {
if ( empty( $settings_that_use_this_gcid ) ) {
continue;
}
// Get the CSS color value assiciated with this GCID.
if ( ! empty( $all_global_colors_info[ $gcid ]['color'] ) ) {
$gcid_color_value = $all_global_colors_info[ $gcid ]['color'];
} else {
// We can't inject the CSS color value if we don't have record of it.
continue;
}
// For matching settings, replace CSS color values with their GCIDs.
foreach ( $settings_that_use_this_gcid as $uses_this_gcid ) {
$settings_match = $settings_filtered[ $uses_this_gcid ];
// Replace CSS color value with GCID wherever it's found within the settings string.
$injected_gcid = str_replace( $gcid, $gcid_color_value, $settings_match );
// Pass the GCID-injected string back to the preset setting.
$result->$module->presets->$preset_id->settings->$uses_this_gcid = $injected_gcid;
}
}
} else {