wsoe_create_protection_files

Create .htaccess file for protecting files.

Description

wsoe_create_protection_files( (bool) $force = false ); 

IMPORTANT NOTE: .htaccess would not work in nginx, it needs to add rule manually to the server block.

Parameters (1)

0. $force — Optional. (bool) => false
The force.

Usage

  1. if ( !function_exists( 'wsoe_create_protection_files' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-simply-order-export/lib/functions.php'; 
  3.  
  4. // The force. 
  5. $force = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wsoe_create_protection_files($force); 
  9.  

Defined (1)

The function is defined in the following location(s).

/lib/functions.php  
  1. function wsoe_create_protection_files( $force = false ) { 
  2.  
  3. if ( false === get_transient( 'wsoe_check_protection_files' ) || $force ) { 
  4.  
  5. $upload_path = wsoe_upload_dir(); 
  6.  
  7. // Top level .htaccess file 
  8.  
  9. if ( wsoe_htaccess_exists() ) { 
  10. $contents = @file_get_contents( $upload_path . '/.htaccess' ); 
  11. if ( $contents !== $rules || ! $contents ) { 
  12. // Update the .htaccess rules if they don't match 
  13. @file_put_contents( $upload_path . '/.htaccess', $rules ); 
  14. } elseif( wp_is_writable( $upload_path ) ) { 
  15. // Create the file if it doesn't exist 
  16. @file_put_contents( $upload_path . '/.htaccess', $rules ); 
  17.  
  18. // Top level blank index.php 
  19. if ( ! file_exists( $upload_path . '/index.php' ) && wp_is_writable( $upload_path ) ) { 
  20. @file_put_contents( $upload_path . '/index.php', '<?php' . PHP_EOL . '// Silence is golden.' ); 
  21.  
  22. // Now place index.php files in all sub folders 
  23. $folders = wsoe_scan_folders( $upload_path ); 
  24. foreach ( $folders as $folder ) { 
  25. // Create index.php, if it doesn't exist 
  26. if ( ! file_exists( $folder . 'index.php' ) && wp_is_writable( $folder ) ) { 
  27. @file_put_contents( $folder . 'index.php', '<?php' . PHP_EOL . '// Silence is golden.' ); 
  28.  
  29. // Check for the files once per day 
  30. set_transient( 'wsoe_check_protection_files', true, 3600 * 24 );