Skip to content

Instantly share code, notes, and snippets.

View AkramiPro's full-sized avatar
🎯
Focusing

Mahdi Akrami AkramiPro

🎯
Focusing
View GitHub Profile
@AkramiPro
AkramiPro / 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 ) {
@AkramiPro
AkramiPro / 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'.
*
@AkramiPro
AkramiPro / 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') {
@AkramiPro
AkramiPro / move-mysql-data.md
Created February 3, 2023 03:28
WHM Move 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
@AkramiPro
AkramiPro / 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 ] );
}
@AkramiPro
AkramiPro / 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.
@AkramiPro
AkramiPro / 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
@AkramiPro
AkramiPro / wp_change_jquery_version.php
Last active August 25, 2021 14:01
Change Wordpress jQuery AND jQuery Migrate Version
<?php
/**
* Change Wordpress jQuery AND jQuery Migrate Version
*/
add_action( 'init', function () {
// jQuery
$core = wp_scripts()->registered['jquery-core'];
$core->ver = '1.12.4';