Skip to content

Instantly share code, notes, and snippets.

View MahdiAkrami01's full-sized avatar
🎯
Focusing

Mahdi Akrami MahdiAkrami01

🎯
Focusing
View GitHub Profile
@MahdiAkrami01
MahdiAkrami01 / rename-docker-volume.md
Last active July 24, 2025 14:53
How to rename a Docker volume

How to rename a Docker volume

  1. Create a new volume
sudo docker volume create newvolume
  1. Delete _data from the new volume
sudo rm -rfv /var/lib/docker/volumes/newvolume/_data
  1. Moving _data from the old to the new volume
@MahdiAkrami01
MahdiAkrami01 / wc-coupon.php
Last active October 29, 2024 17:46
WooCommerce Coupon: Force `Exclude sale items` And `Individual use only` options always enabled
<?php
/**
* Force `Exclude sale items` And `Individual use only` options always enabled.
*
* @see https://prnt.sc/zDSJuu5lyHqI
* @author Mahdi Akrami
* @url https://x.com/AkramiPro
*/
add_filter( 'get_post_metadata', static function ( $value, $object_id, $meta_key ) {
@MahdiAkrami01
MahdiAkrami01 / wc-variation.php
Last active October 29, 2024 15:35
WooCommerce get product default variation id (most efficient way)
<?php
/**
* Get default product variation
*
* note: this method check for exact match.
*
* @param mixed $product_id WC_Product|WP_Post|int|bool $product Product instance, post instance, numeric or false to use global $post.
* @param string $return Optional. The format to return the results in. Can be 'id' to return id of variation or 'object' for the product variation object. Default 'id'.
*
@MahdiAkrami01
MahdiAkrami01 / hamster-auto-clicker.js
Last active June 11, 2024 21:16
Hamster Kombat javascript auto clicker
// 1. Open firefox browser.
// 2. Use this for open hamster in browser: https://gist.github.com/NabiKAZ/10ab0c25c0703d5d3f5b9b4acd500c66
// 3. Install addon: https://addons.mozilla.org/en-US/firefox/addon/my-js-injector/
// 4. Copy & paste below code.
// tap every 0.5 second
setInterval(() => {
let tab = document.querySelector('.router-link-exact-active');
// only run if we are in home tab
if (tab && tab.getAttribute('href') === '/clicker') {
@MahdiAkrami01
MahdiAkrami01 / move-mysql-data.md
Last active July 24, 2025 14:59
WHM Move MySQL Data Folder

How to Move WHM MySQL Data Folder

  1. Make a full mysqldump file
mysqldump --all-databases | gzip > /home/alldatabases.sql.gz
  1. Uncheck monitor in WHM > Service Manager for Mysql and save the area.

  2. Stop MySQL

/etc/init.d/mysql stop
@MahdiAkrami01
MahdiAkrami01 / disable_update_plugin_notice.php
Created August 25, 2021 14:16
Wordpress Disable Plugin Update Notice
<?php
// Disable Plugin Update Notice
add_filter( 'site_transient_update_plugins', function ( $value ) {
$plugin = 'elementor/elementor.php'; // plugin slug
if ( isset( $value->response[ $plugin ] ) ) {
unset( $value->response[ $plugin ] );
}
@MahdiAkrami01
MahdiAkrami01 / wp_login_programmatically.php
Last active October 29, 2024 15:38
Wordpress Login Programmatically Using User ID - (Without a password)
<?php
// Put this code in mu-plugins or functions.php
// then open your site url with add `?switch_user=__strong_random_string__` query to end of the url.
// ex: https://test.com/?switch_user=__strong_random_string__
if ( isset( $_GET['switch_user'] ) && $_GET['switch_user'] === '__strong_random_string__' ) {
add_action( 'init', function () {
$user_id = 1; // in most of case user_id=1 is administrator.
@MahdiAkrami01
MahdiAkrami01 / php_find_and_replace_mutiple_line.php
Last active March 10, 2022 06:28
PHP Find And Replace Multiple Line Using preg_replace() - Fix line break problem
<?php
$subject = '
Lorem Ipsum 1
Lorem Ipsum 1.1
Lorem Ipsum 2
Lorem Ipsum 2.1
Lorem Ipsum 2.1.1
Lorem Ipsum 3
Lorem Ipsum 3.1
@MahdiAkrami01
MahdiAkrami01 / wp-change-jquery-version.md
Last active July 24, 2025 15:04
How to change WordPress jQuery and jQuery Migrate version

How to change wordpress jQuery and jQuery Migrate version

<?php

/**
 * Change Wordpress jQuery and jQuery Migrate Version
 */
add_action( 'init', static function () {

 // jQuery