array( 'affected_fields' => array( 'background_color_gradient_overlays_image' => $this->get_modules( 'module_bg' ), ), ), 'background_color_gradient_overlays_image_tablet' => array( 'affected_fields' => array( 'background_color_gradient_overlays_image_tablet' => $this->get_modules( 'module_bg' ), ), ), 'background_color_gradient_overlays_image_phone' => array( 'affected_fields' => array( 'background_color_gradient_overlays_image_phone' => $this->get_modules( 'module_bg' ), ), ), 'background_color_gradient_overlays_image__hover' => array( 'affected_fields' => array( 'background_color_gradient_overlays_image__hover' => $this->get_modules( 'module_bg' ), ), ), 'background_color_gradient_overlays_image__sticky' => array( 'affected_fields' => array( 'background_color_gradient_overlays_image__sticky' => $this->get_modules( 'module_bg' ), ), ), ); } /** * Migrate. * * @param string $to_field_name This migration's target field. * @param string|array $affected_field_value Affected field reference value. * @param string|number $module_slug Current module type. * @param string $to_field_value Migration target's current value. * @param string $affected_field_name Affected field attribute name. * @param array $module_attrs Current module's full attributes. * @param string $module_content Current module's content. * @param string|number $module_address Current module's address. * * @return string * * @since 4.15.0 */ public function migrate( $to_field_name, $affected_field_value, $module_slug, $to_field_value, $affected_field_name, $module_attrs, $module_content, $module_address ) { // Early exit if affected field ("Use Gradient" or "Parallax") is not "on". if ( 'on' !== $affected_field_value ) { return $affected_field_value; } $default_settings = array( 'use_gradient' => 'off', 'overlays_image' => ET_Global_Settings::get_value( 'all_background_gradient_overlays_image' ), 'parallax' => 'off', ); $old_values = $default_settings; // Collect the old settings. switch ( $affected_field_name ) { // Desktop View. case 'background_color_gradient_overlays_image': if ( ! isset( $module_attrs[ $affected_field_name ] ) ) { return $affected_field_value; } else { $old_values['use_gradient'] = $this->_get_attr_value( 'use_background_color_gradient', $module_attrs ); $old_values['overlays_image'] = $this->_get_attr_value( 'background_color_gradient_overlays_image', $module_attrs ); $old_values['parallax'] = $this->_get_attr_value( 'parallax', $module_attrs ); } break; // Tablet View. case 'background_color_gradient_overlays_image_tablet': if ( ! isset( $module_attrs[ $affected_field_name ] ) ) { return $affected_field_value; } else { $old_values['use_gradient'] = $this->_get_attr_value( 'use_background_color_gradient_tablet', $module_attrs ); $old_values['overlays_image'] = $this->_get_attr_value( 'background_color_gradient_overlays_image_tablet', $module_attrs ); $old_values['parallax'] = $this->_get_attr_value( 'parallax_tablet', $module_attrs ); } break; // Phone View. case 'background_color_gradient_overlays_image_phone': if ( ! isset( $module_attrs[ $affected_field_name ] ) ) { return $affected_field_value; } else { $old_values['use_gradient'] = $this->_get_attr_value( 'use_background_color_gradient_phone', $module_attrs ); $old_values['overlays_image'] = $this->_get_attr_value( 'background_color_gradient_overlays_image_phone', $module_attrs ); $old_values['parallax'] = $this->_get_attr_value( 'parallax_phone', $module_attrs ); } break; // Hover Mode. case 'background_color_gradient_overlays_image__hover': if ( ! isset( $module_attrs[ $affected_field_name ] ) ) { return $affected_field_value; } else { $old_values['use_gradient'] = $this->_get_attr_value( 'use_background_color_gradient__hover', $module_attrs ); $old_values['overlays_image'] = $this->_get_attr_value( 'background_color_gradient_overlays_image__hover', $module_attrs ); $old_values['parallax'] = $this->_get_attr_value( 'parallax__hover', $module_attrs ); } break; // Sticky Mode. case 'background_color_gradient_overlays_image__sticky': if ( ! isset( $module_attrs[ $affected_field_name ] ) ) { return $affected_field_value; } else { $old_values['use_gradient'] = $this->_get_attr_value( 'use_background_color_gradient__sticky', $module_attrs ); $old_values['overlays_image'] = $this->_get_attr_value( 'background_color_gradient_overlays_image__sticky', $module_attrs ); $old_values['parallax'] = $this->_get_attr_value( 'parallax__sticky', $module_attrs ); } break; default: return $affected_field_value; } // If overlays_image aren't defined, pull in global default settings. if ( empty( $old_values['use_gradient'] ) ) { $old_values['use_gradient'] = $default_settings['use_gradient']; } if ( empty( $old_values['overlays_image'] ) ) { $old_values['overlays_image'] = $default_settings['overlays_image']; } if ( empty( $old_values['parallax'] ) ) { $old_values['parallax'] = $default_settings['parallax']; } // New value for overlays_image. return 'on' === $old_values['use_gradient'] && 'on' === $old_values['overlays_image'] && 'on' === $old_values['parallax'] ? 'off' : $affected_field_value; } /** * Get attributes value by field_name. * * @param string $field_name Field name. * @param array $module_attrs Module's full attributes. * * @return string */ private function _get_attr_value( $field_name, $module_attrs ) { if ( array_key_exists( $field_name, $module_attrs ) ) { return $module_attrs[ $field_name ]; } return ''; } } return new ET_Builder_Module_Settings_Migration_BackgroundGradientOverlaysImage();