Skip to content

Instantly share code, notes, and snippets.

@MwieMarin
MwieMarin / findandreplace
Created January 18, 2020 23:57
SQL: Find and replace all URLs in WordPress database
UPDATE wp_options SET option_value = replace(option_value, 'altedomain.de', 'neuedomain.de') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'altedomain.de','neuedomain.de');
UPDATE wp_posts SET post_content = replace(post_content, 'altedomain.de', 'neuedomain.de');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'altedomain.de','neuedomain.de');
@MwieMarin
MwieMarin / functions.php
Created November 19, 2019 18:02
WordPress: Disable REST API User Enumeration
<?php
add_filter( 'rest_endpoints', function( $endpoints ){
if ( isset( $endpoints['/wp/v2/users'] ) ) {
unset( $endpoints['/wp/v2/users'] );
}
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
return $endpoints;
});
@MwieMarin
MwieMarin / functions.php
Created October 19, 2019 16:09
WordPress: Stop User Enumeration
<?php
if (!is_admin()) {
if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])){
die();
}
add_filter('redirect_canonical', 'check_enum', 10, 2);
}
function check_enum($redirect, $request) {
if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)){
@MwieMarin
MwieMarin / .htaccess
Created September 20, 2019 07:33
Set HSTS Security Header
Header set Strict-Transport-Security "max-age=31536000"
Header always append X-Frame-Options SAMEORIGIN
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
@MwieMarin
MwieMarin / .htaccess
Created March 15, 2018 13:28
WordPress: Stop user enumeration
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} author=\d
RewriteRule ^/? [L,R=301]
</IfModule>
@MwieMarin
MwieMarin / main.js
Created November 29, 2017 07:41
jQuery: Get Height of the largest element
$(document).ready(function(){
$maxHeight = Math.max.apply(null, $(".your-element").map(function () { return $(this).height(); }).get());
})
@MwieMarin
MwieMarin / functions.php
Last active October 24, 2024 05:24
WordPress: Add timestamp to CSS and JS
<?php
// Version CSS file in a theme
wp_enqueue_style( 'theme-styles', get_stylesheet_directory_uri() . '/style.css', array(), filemtime( get_stylesheet_directory() . '/style.css' ) );
// Version JS file in a theme
wp_enqueue_script( 'theme-scripts', get_stylesheet_directory_uri() . '/js/scripts.js', array(), filemtime( get_stylesheet_directory() . '/js/scripts.js' ) );
// Version CSS file in a plugin
wp_enqueue_style( 'plugin-styles', plugin_dir_url( __FILE__ ) . 'assets/css/plugin-styles.css', array(), filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/plugin-styles.css' ) );
// Version JS file in a plugin
wp_enqueue_script( 'plugin-scripts', plugin_dir_url( __FILE__ ) . 'assets/js/plugin-scripts.js', array(), filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/plugin-scripts.js' ) )
@MwieMarin
MwieMarin / pluginList.txt
Last active October 31, 2017 20:26
Usefull WordPress Plugins
Compress JPEG & PNG images
Clean Image Filenames
P3 (Plugin Performance Profiler)
Stop User Enumeration
BackWPup
Limit Login Attempts
UpdraftPlus
SubHeading
Regenerate Thumbnails
Duplicate Post
@MwieMarin
MwieMarin / .htaccess
Created May 10, 2017 10:08
Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@MwieMarin
MwieMarin / functions.php
Created November 24, 2016 15:25
Wordpress: Move all enqueued scripts from head to footer
<?php
function move_enqueued_scripts_into_head() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}