PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.4.1
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.4.1
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Helpers / UploadGuard.php

UploadGuard.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.4.1, at includes/Helpers/UploadGuard.php

42 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Keeps plugin upload folders from being listed.
4 *
5 * @package EasyInvoice
6 */
7
8 namespace EasyInvoice\Helpers;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 class UploadGuard {
15 /**
16 * Drop an index.php (and an .htaccess turning indexes off) into a folder
17 * the plugin writes client files to, so a directory listing never shows
18 * every payment proof or signature. Idempotent; silent on failure.
19 *
20 * @param string $dir Absolute path.
21 */
22 public static function protectDirectory( string $dir ): void {
23 if ( '' === $dir ) {
24 return;
25 }
26 if ( ! is_dir( $dir ) ) {
27 wp_mkdir_p( $dir );
28 }
29 if ( ! is_dir( $dir ) || ! is_writable( $dir ) ) {
30 return;
31 }
32 $index = trailingslashit( $dir ) . 'index.php';
33 if ( ! file_exists( $index ) ) {
34 @file_put_contents( $index, "<?php\n// Silence is golden.\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions,WordPress.PHP.NoSilencedErrors
35 }
36 $htaccess = trailingslashit( $dir ) . '.htaccess';
37 if ( ! file_exists( $htaccess ) ) {
38 @file_put_contents( $htaccess, "Options -Indexes\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions,WordPress.PHP.NoSilencedErrors
39 }
40 }
41 }
42