Skip to content

Instantly share code, notes, and snippets.

@muhammad-owais-javed
Created April 20, 2021 09:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save muhammad-owais-javed/38668dfc123d58238ce7cabc058df4e0 to your computer and use it in GitHub Desktop.
Save muhammad-owais-javed/38668dfc123d58238ce7cabc058df4e0 to your computer and use it in GitHub Desktop.
#Wordpress Sheet
#For verifying Core wordpress files
wp core verify-checksums
#For restricting auto update of wordpress
define( 'WP_AUTO_UPDATE_CORE', false );
#For increasing memory limit
define('WP_MEMORY_LIMIT', '256M');
"OR"
@ini_set( 'memory_limit', '256M' );
#For increasing Upload Max Size
@ini_set( 'upload_max_size' , '200M' );
#For increasing Post Max Size
@ini_set( 'post_max_size', '200M');
#For changing max file size and post max size through php-fpm
php_admin_value[upload_max_filesize] = 200M
php_admin_value[post_max_size] = 200M
#Incase if the option of 'Add New Plugins' Dissappear
define('DISALLOW_FILE_MODS',false);
#For setting Home and Site URL
define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );
#When ask for SFTP Credentials while installing any plugin
define( 'FS_METHOD', 'direct' );
#Changing permission of directory and file
define( 'FS_CHMOD_DIR', 0775);
define( 'FS_CHMOD_FILE', 0664 );
#Wordpress asking for Enabling Cookies in the browser
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );
#OR
define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');
#For setting memcache/redis cache key salt
define ('WP_CACHE_KEY_SALT', 'domain.com');
#If error shows "Sorry, this file type is not supported for security reasons?" while uploading fonts
define('ALLOW_UNFILTERED_UPLOADS', true);
#For definining encoding type
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
#For disabling cron of Wordpress
define('DISABLE_WP_CRON', true);
#Add this cron after disabling it fromm wp-config.php
*/5 * * * * wget -q -O - https://your-domain.com/wp-cron.php?doing_wp_cron
# Use X-Forwarded-For HTTP Header to Get Visitor's Real IP Address
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$http_x_headers = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] );
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
#For Search and Replace in Database
wp search-replace olddomain newdomain --all-tables --dry-run
#For Search and Replace from http to https in Database
wp search-replace http://domain https://domain --all-tables --dry-run
#For Search and Replace in all files
grep -rl "olddomain"| xargs sed -i 's#olddomain#newdomain#g'
#For viewing list of wp users
wp user list
#For creating wp-admin testing user credentials
wp user create test test@example.com --role=administrator
wp user create bob bob@example.com --role=author
#For updating user password
wp user update USERNAME --user_pass="PASSWORD"
#For deleting test user
wp user delete test --reassign=567
#For Downloading Wordpress
wp core download
#For checking wordpress crons
wp cron event list
wp cron event run --all
#For clearing wordpress cache
wp cache flush --allow-root
rm -rf ./wp-content/cache/*
#For viewing plugin list
wp plugin list
#For activating plugin
wp plugin activate plugin-name --allow-root
#For deactivating plugin
wp plugin deactivate plugin-name --allow-root
#For deactivating all plugins
wp plugin deactivate --all --allow-root
#If wordpress have some non-active plugins and we wish to save the list of active plugin only
wp plugin list --status=active --format=csv --allow-root | awk -F, '{print $1}' > plugin.txt
#Reactivate all of those specific plugin by using this
wp plugin activate $(<plugin.txt) --allow-root
#For view theme list
wp theme list --allow-root
#For activating theme
wp theme activate themename --allow-root
#For changing Files and Foldr Permission
find -type d -exec chmod 775 {} ';'
find -type f -exec chmod 664 {} ';'
#For removing login limits:
UPDATE wp_options SET option_value = '' WHERE option_name = 'limit_login_lockouts' LIMIT 1;
#If you want to unblock your specific IP e.g. 111.222.111.222, then run a query like this:
UPDATE wp_options SET option_value = REPLACE(option_value, '111.222.111.222', '') WHERE option_name = 'limit_login_lockouts' LIMIT 1;
#.htaccess Rules for Apache
#Wordpress default .htaccess rule
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
# Block WordPress xmlrpc.php requests
<Files xmlrpc.php>
order deny,allow
deny from all
allow from ipaddress
</Files>
#Blocking code.php requests
<Files code.php>
order deny,allow
deny from all
</Files>
#Blocking spamming bots request
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*(SCspider|Textbot|s2bot|MJ12bot|YandexBot|SemrushBot|AspiegelBot|BLEXBot|webmeup-crawler|oBot|Semrush|SiteExplorer|BaiDuSpider).*$ [NC]
RewriteRule .* - [F,L]
#Bot Blcking from .htaccess
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} python-requests [NC]
RewriteRule .* - [F,L]
#Blocking specific IP's
<Limit GET POST>
order allow,deny
deny from ipaddress
deny from ipaddress
deny from ipaddress
deny from ipaddress
deny from ipaddress
allow from all
</Limit>
<Limit GET POST>
order deny,allow
deny from all
# Just Allow a Single IP
allow from ipaddress
</Limit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment