PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / includes / import / theme-options / redux.php

redux.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.0, at includes/import/theme-options/redux.php

86 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for the Redux importer.
4 *
5 * @see https://wordpress.org/plugins/redux-framework/
6 * @package ABlocks
7 */
8
9 namespace ABlocks\import\ThemeOptions;
10
11 use ABlocks\Helper;
12 use ReduxFrameworkInstances;
13
14 class Redux {
15
16 public static function import( array $import_data ) {
17 // Redux plugin is not active!
18 if ( ! class_exists( 'ReduxFramework' ) ) {
19 Helper::emit_sse_message([
20 'action' => 'log',
21 'level' => 'warning',
22 'message' => __( 'The Redux plugin is not activated, so the Redux import was skipped!', 'ablocks' ),
23 ]);
24
25 return;
26 }
27
28 Helper::emit_sse_message([
29 'action' => 'log',
30 'level' => 'info',
31 'message' => __( 'Redux options import started.', 'ablocks' ),
32 ]);
33 foreach ( $import_data as $redux_item ) {
34 $file_path = Helper::remote_to_tmp_file( $redux_item['file_url'] );
35 if ( ! file_exists( $file_path ) ) {
36 Helper::emit_sse_message( [
37 'action' => 'log',
38 'level' => 'warning',
39 'message' => __( 'Redux import file does not exist.', 'ablocks' ),
40 ] );
41 continue;
42 }
43
44 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
45 $redux_options_raw_data = file_get_contents( $file_path );
46 if ( ! $redux_options_raw_data ) {
47 Helper::emit_sse_message( [
48 'action' => 'log',
49 'level' => 'warning',
50 'message' => __( 'Redux import file could not be read.', 'ablocks' ),
51 ] );
52 continue;
53 }
54
55 $redux_options_data = json_decode( $redux_options_raw_data, true );
56 $redux_framework = ReduxFrameworkInstances::get_instance( $redux_item['option_name'] );
57
58 if ( isset( $redux_framework->args['opt_name'] ) ) {
59 // Import Redux settings.
60 if ( ! empty( $redux_framework->options_class ) && method_exists( $redux_framework->options_class, 'set' ) ) {
61 $redux_framework->options_class->set( $redux_options_data );
62 } else {
63 // Handle backwards compatibility.
64 $redux_framework->set_options( $redux_options_data );
65 }
66
67 Helper::emit_sse_message( [
68 'action' => 'log',
69 'level' => 'info',
70 /* translators: %s - the name of the Redux option. */
71 'message' => sprintf( esc_html__(
72 'Redux settings import for: %s finished successfully!', 'ablocks' ), $redux_item['option_name'] ),
73 ] );
74 } else {
75 Helper::emit_sse_message( [
76 'action' => 'log',
77 'level' => 'warning',
78 /* translators: %s - the name of the Redux option. */
79 'message' => sprintf( esc_html__(
80 'The Redux option name: %s, was not found in this WP site, so it was not imported!', 'ablocks' ), $redux_item['option_name'] ),
81 ] );
82 }//end if
83 }//end foreach
84 }
85 }
86