| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global functions related to the filesystem. |
| 4 |
* |
| 5 |
* @since 0.1.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Provides an instance of WordPress' native direct filesystem. |
| 16 |
* |
| 17 |
* @since 0.1.0 |
| 18 |
* |
| 19 |
* @return WP_Filesystem_Direct |
| 20 |
*/ |
| 21 |
function swpsp_direct_filesystem() { |
| 22 |
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) { |
| 23 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; |
| 24 |
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; |
| 25 |
} |
| 26 |
|
| 27 |
if ( ! defined( 'FS_CHMOD_FILE' ) ) { |
| 28 |
define( 'FS_CHMOD_FILE', swpsp_get_file_mode() ); |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! defined( 'FS_CHMOD_DIR' ) ) { |
| 32 |
define( 'FS_CHMOD_DIR', swpsp_get_dir_mode() ); |
| 33 |
} |
| 34 |
|
| 35 |
return new WP_Filesystem_Direct( [] ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Gets the default file mode as an octal integer. |
| 40 |
* |
| 41 |
* @since 0.1.0 |
| 42 |
* |
| 43 |
* @return int |
| 44 |
*/ |
| 45 |
function swpsp_get_file_mode() { |
| 46 |
if ( defined( 'FS_CHMOD_FILE' ) ) { |
| 47 |
return FS_CHMOD_FILE; |
| 48 |
} |
| 49 |
|
| 50 |
return ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Gets the default file mode as an octal integer. |
| 55 |
* |
| 56 |
* @since 0.1.0 |
| 57 |
* |
| 58 |
* @return int |
| 59 |
*/ |
| 60 |
function swpsp_get_dir_mode() { |
| 61 |
if ( defined( 'FS_CHMOD_DIR' ) ) { |
| 62 |
return FS_CHMOD_DIR; |
| 63 |
} |
| 64 |
|
| 65 |
return ( fileperms( ABSPATH ) & 0777 | 0755 ); |
| 66 |
} |
| 67 |
|