Skip to content

Instantly share code, notes, and snippets.

@saaiful
Last active August 29, 2015 14:07
Show Gist options
  • Save saaiful/37e4406667a0a08f1d7d to your computer and use it in GitHub Desktop.
Save saaiful/37e4406667a0a08f1d7d to your computer and use it in GitHub Desktop.
Theme and Plugins Folder Direct Access Deny
<?php
/*
Plugin Name: Theme and Plugins Folder Direct Access Deny
Plugin URI: htp://saiful.im/
Description: WordPress Theme and Plugins Folder Direct Access Deny
Author: Saiful Islam
Version: 0.0.2
Author URI: http://saiful.im/
*/
function bugFixactivate(){
$rule = '
<Files /index.php>
Order Allow,Deny
Allow from all
</Files>
<FilesMatch ".*\.(php)$">
deny from all
</FilesMatch>
ErrorDocument 404 /index.php?error=404
ErrorDocument 403 /index.php?error=404
';
@file_put_contents(__DIR__."/../themes/.htaccess", $rule);
@file_put_contents(__DIR__."/../plugins/.htaccess", $rule);
@file_put_contents(__DIR__."/../../wp-content/.htaccess", $rule);
@file_put_contents(__DIR__."/../../wp-admin/includes/.htaccess", $rule);
}
function bugFixdeactivation(){
if(file_exists(__DIR__.'/../themes/.htaccess'))
{
@unlink(__DIR__."/../themes/.htaccess");
}
if(file_exists(__DIR__."/../../wp-content/.htaccess"))
{
@unlink(__DIR__."/../../wp-content/.htaccess");
}
if(file_exists(__DIR__."/../../wp-content/.htaccess"))
{
@unlink(__DIR__."/../../wp-content/.htaccess");
}
if(file_exists(__DIR__."/../../wp-admin/includes/.htaccess"))
{
@unlink(__DIR__."/../../wp-admin/includes/.htaccess");
}
}
register_activation_hook( __FILE__ , 'bugFixactivate' );
register_deactivation_hook( __FILE__ , 'bugFixdeactivation');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment