PluginProbe
Prevent Direct Access – Protect WordPress Files / trunk
Prevent Direct Access – Protect WordPress Files vtrunk
2.8.8.9 2.8.9.0 2.8.9.1 trunk 1.0 1.1 2.7.10 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.6.1 2.8.7 2.8.8 2.8.8.1 2.8.8.2 All 31 releases
prevent-direct-access / includes / function.php

function.php in Prevent Direct Access – Protect WordPress Files trunk, at includes/function.php

65 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) die('You do not have sufficient permissions to access this file.');
3 // phpcs:disable WordPress.WP.AlternativeFunctions
4 class Pda_Function {
5
6 function get_htaccess_file_path() {
7
8 //global $wp_rewrite;
9 $home_path = get_home_path();
10 $htaccess_file = $home_path . '.htaccess';
11
12 return $htaccess_file;
13 }
14
15 function htaccess_writable() {
16 $htaccess_file = $this->get_htaccess_file_path();
17
18 if ( ! file_exists( $htaccess_file ) ) {
19 return '.htaccess file not existed';
20 }
21
22 if ( is_writable( $htaccess_file ) ) {
23 return true;
24 }
25
26 @chmod( $htaccess_file, 0666 );
27
28 if ( ! is_writable( $htaccess_file ) ) {
29 return 'Please ask host manager to grant write permission for .htaccess file.';
30 }
31
32 return true;
33 }
34
35 function get_htaccess_content() {
36
37 //global $wp_rewrite;
38
39 $htaccess_file = $this->get_htaccess_file_path();
40
41 if (!file_exists($htaccess_file)) {
42 return false;
43 }
44
45 if (!is_writable($htaccess_file)) {
46 @chmod($htaccess_file, 0666);
47 }
48
49 if (!$f = fopen($htaccess_file, 'r')) {
50 return false;
51 }
52
53 return file_get_contents($htaccess_file);
54 }
55
56 function sanitized_rule($rule) {
57 $rule = trim($rule);
58 $rule = str_replace('\\\\', '\\', $rule);
59 $rule = str_replace('\"', '"', $rule);
60
61 return $rule;
62 }
63
64 }
65