PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / Document / Migrations / DataMigration / BackgroundImage.php

BackgroundImage.php in Depicter — Popup & Slider Builder trunk, at app/src/Document/Migrations/DataMigration/BackgroundImage.php

40 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\Document\Migrations\DataMigration;
3
4 use Averta\WordPress\Utility\JSON;
5
6 class BackgroundImage implements MigrationInterface {
7
8 public function migrate( $slider_content ) {
9
10 $slider_data = JSON::isJson( $slider_content ) ? JSON::decode( $slider_content, true ) : JSON::decode( JSON::encode( $slider_content ), true );
11 $backgrounds = [];
12 if ( ! empty( $slider_data['sections'] ) ) {
13 foreach ( $slider_data['sections'] as $section_key => $section ) {
14 if ( ! empty( $section['background']['image']['src'] ) ) {
15 if ( is_string( $section['background']['image']['src'] ) ) {
16 $backgrounds[ $section['background']['image']['src'] ] = JSON::encode( $section['background'], JSON_FORCE_OBJECT );
17 }
18 }
19 }
20 }
21
22 if ( ! empty( $backgrounds ) ) {
23
24 $modified_data = JSON::isJson( $slider_content ) ? $slider_content : JSON::encode( $slider_content );
25 foreach( $backgrounds as $backgroundID => $background ) {
26 $new_background = str_replace( '"src":"' . $backgroundID .'"', '"src":{"default":"' . $backgroundID .'"}', $background );
27 $modified_data = str_replace( $background, $new_background, $modified_data );
28 }
29
30 if ( JSON::isJson( $slider_content ) ) {
31 return $modified_data;
32 } else {
33 return JSON::decode( $modified_data, false );
34 }
35 }
36
37 return $slider_content;
38 }
39 }
40