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