Contents

bp_document_check_download_folder_protection()

Description

Source

File: bp-document/bp-document-filters.php

function bp_document_check_download_folder_protection() {

	$upload_dir     = wp_get_upload_dir();
	$files = array(
			array(
					'base'    => $upload_dir['basedir'] . '/bb_documents',
					'file'    => 'index.html',
					'content' => '',
			),
			array(
					'base'    => $upload_dir['basedir'] . '/bb_documents',
					'file'    => '.htaccess',
					'content' => 'deny from all

# BEGIN BuddyBoss code execution protection
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
<IfModule mod_php7.c>
php_flag engine 0
</IfModule>

AddHandler cgi-script .php .phtml .php3 .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
# END BuddyBoss code execution protection',
			),
	);

	foreach ( $files as $file ) {
		if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
			$file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'wb' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
			if ( $file_handle ) {
				fwrite( $file_handle, $file['content'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
				fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
			}
		}
	}
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.