| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\import\ThemeOptions; |
| 4 |
|
| 5 |
use ABlocks\Helper; |
| 6 |
|
| 7 |
class CodeStar { |
| 8 |
|
| 9 |
public static function import( string $file_path ) { |
| 10 |
Helper::emit_sse_message([ |
| 11 |
'action' => 'log', |
| 12 |
'level' => 'info', |
| 13 |
'message' => __( 'Starting CodeStar theme options import process.', 'ablocks' ), |
| 14 |
]); |
| 15 |
if ( file_exists( $file_path ) ) { |
| 16 |
//phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 17 |
$options_data = json_decode( file_get_contents( $file_path ), true ); |
| 18 |
|
| 19 |
// Apply the options data using Codestar functions |
| 20 |
if ( function_exists( 'cs_set_option' ) ) { |
| 21 |
foreach ( $options_data as $option_key => $option_value ) { |
| 22 |
cs_set_option( $option_key, $option_value ); |
| 23 |
} |
| 24 |
} |
| 25 |
Helper::emit_sse_message([ |
| 26 |
'action' => 'log', |
| 27 |
'level' => 'info', |
| 28 |
'message' => __( 'Codestar theme options imported successfully.', 'ablocks' ), |
| 29 |
]); |
| 30 |
} else { |
| 31 |
Helper::emit_sse_message([ |
| 32 |
'action' => 'log', |
| 33 |
'level' => 'warning', |
| 34 |
'message' => __( 'Codestar theme options import file not found!', 'ablocks' ), |
| 35 |
]); |
| 36 |
}//end if |
| 37 |
} |
| 38 |
|
| 39 |
} |
| 40 |
|