Skip to content

Instantly share code, notes, and snippets.

@AlexanderMityaev
AlexanderMityaev / functions.php
Created June 2, 2025 13:39
Prevent woocommerce user autologin after password reset
add_action('woocommerce_customer_reset_password', function ($user) {
wp_logout();
// Immediately redirect to /login instead of continuing Woo flow
wp_redirect(home_url('/login?reset=success'));
exit; // No further hooks, templates, or code are run
});
/*
* Another nice try, but not working because redirect happens earlier
*/
@AlexanderMityaev
AlexanderMityaev / win-smb-easy-sharing.cmd
Created May 26, 2025 04:10
Win10/11 SMB easy sharing
# Run as Administrator
# 1. Set network to Private
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
# 2. Enable Network Discovery and File/Printer Sharing
Set-NetFirewallRule -DisplayGroup "Network Discovery" -Enabled True -Profile Private
Set-NetFirewallRule -DisplayGroup "File and Printer Sharing" -Enabled True -Profile Private
# 3. Disable password-protected sharing (optional, for ease of access)
@AlexanderMityaev
AlexanderMityaev / wp-wpml.md
Last active May 18, 2025 06:59
WP+WPML, multidomain+multilanguage, directory based

you want to serve WordPress on multiple domains without canonical redirects (e.g., keep users on mydomain.com.ua or mydomain.pl depending on what they visited), without forcing everything to redirect to the "Site Address (URL)" in WordPress settings.

This is absolutely possible, but WordPress has some default behavior you need to override.

✅ Goal Recap Same WordPress instance serves both mydomain.pl and mydomain.com.ua

No automatic redirect to the canonical domain (e.g., from .com.ua → .pl)

Multilingual pages work on both domains (e.g., /en, /ru)

@AlexanderMityaev
AlexanderMityaev / functions.php
Created October 7, 2024 22:09
Woocommerce duplicate subcategory slugs
/**
* Special handling duplicate product slugs
**/
add_filter( 'term_link', 'campers_term_link', 10, 3);
function campers_term_link( $link, $term, $taxonomy ) {
if ( $taxonomy !== 'product_cat' ) {
return $link;
}
// Get the parent term
@AlexanderMityaev
AlexanderMityaev / gist:b680e9af522bad8050e1c0261033617c
Last active October 7, 2024 14:00
Best practice deploying in docker projects with separate repositories but common services

To deploy a project that needs access to a PostgreSQL service (containerized in another repository, along with other services inside a custom bridge network), a common scenario in microservices or multi-repository projects, the best practices revolve around keeping your services isolated but enabling cross-repository communication in a scalable and secure way.

Here are several best practices and approaches to achieve this:

1. External Docker Network Across Repositories

  • Create an external Docker bridge network that both projects (repositories) can attach their containers to. This allows containers in different repositories to communicate while maintaining network isolation within their bridge networks.

Steps:

  • Create an external network:
# Uses the keyboard usage IDs documented in https://developer.apple.com/library/archive/technotes/tn2450/_index.html.
# The lines below, respectively, map:
# Keypad 2 and Down Arrow -> Keyboard Down Arrow
# Keypad 4 and Left Arrow -> Keyboard Left Arrow
# Keypad 6 and Right Arrow -> Keyboard Right Arrow
# Keypad 8 and Up Arrow -> Keyboard Up Arrow
#
# Keypad 1 and End -> Keyboard End
# Keypad 3 and Page Down -> Keyboard Page Down
# Keypad 7 and Home -> Keyboard Home
@AlexanderMityaev
AlexanderMityaev / gist:47091da24c6037daf7ded94990d224a6
Created April 4, 2024 11:37
Flutter / Dart check if dynamic null or empty
bool isNullEmptyOrFalse(dynamic o) {
if (o is Map<String, dynamic> || o is List<dynamic>) {
return o == null || o.length == 0;
}
return o == null || false == o || "" == o;
}
@AlexanderMityaev
AlexanderMityaev / gist:1084543e443dfeb4b926a3b838233653
Created April 11, 2023 11:45 — forked from yunusga/gist:33cf0ba9e311e12df4046722e93d4123
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
/* Produces a dump on the state of WordPress when a not found error occurs */
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */
ini_set( 'error_reporting', -1 );
ini_set( 'display_errors', 'On' );
echo '<pre>';
add_action( 'parse_request', 'debug_404_rewrite_dump' );
function debug_404_rewrite_dump( &$wp ) {
@AlexanderMityaev
AlexanderMityaev / gist:b3b97c90afb4f67e9b84629a43d1bc97
Created January 4, 2023 15:12 — forked from rainyjune/gist:4084886
The best way to retry an AJAX request on failure using jQuery
$.ajax({
url : 'someurl',
type : 'POST',
data : ....,
tryCount : 0,
retryLimit : 3,
success : function(json) {
//do something
},
error : function(xhr, textStatus, errorThrown ) {
@AlexanderMityaev
AlexanderMityaev / example.com.conf
Created November 13, 2022 10:28 — forked from ufth/example.com.conf
безопасный конфиг nginx для wordpress с php-fpm chroot
# /etc/nginx/sites-available/example.com.conf
# if you find this config useful, please consider donating bitcoin:1MjxPWAyebHhjQdjLPGcV5oZd5VbEWrAga
# а это уже непосредственно сам файл виртуального хоста
# разрешаем 30 запросов за 60 секунд с одного ip
# этот параметр работает как ограничение скорости км/ч на знаке,
# *нельзя* сделать 30 запросов за несколько секунд и ждать следующей минуты
# такая запись эквивалентна разрешённой скорости в 0.5 запроса в секунду
limit_req_zone $binary_remote_addr zone=login_user:1m rate=30r/m;