Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / prevent_wp_login_wordpress.php
Created March 22, 2025 08:57
Prevent WP Login WordPress
<?php
// Hook the appropriate WordPress action
add_action('init', 'prevent_wp_login');
function prevent_wp_login() {
// WP tracks the current page - global the variable to access it
global $pagenow;
// Check if a $_GET['action'] is set, and if so, load it into $action variable
$action = (isset($_GET['action'])) ? $_GET['action'] : '';
@mehrshaddarzi
mehrshaddarzi / php_ftp.php
Created March 22, 2025 07:13
Test PHP FTP
<?php
// connect to FTP server
$ftp_server = "80.....";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
// login
if (@ftp_login($ftp_conn, "user", "pass"))
{
echo "Connection established.";
}
@mehrshaddarzi
mehrshaddarzi / .htaccess
Created March 22, 2025 07:11
Block Run PHP File in WordPress Storage Folder (Uploads)
# Block executables
<FilesMatch "\.(php|phtml|php3|php4|php5|pl|py|jsp|asp|html|htm|shtml|sh|cgi|suspected)$">
deny from all
</FilesMatch>
@mehrshaddarzi
mehrshaddarzi / auto_create_user_wocommerce.php
Created March 11, 2025 05:21
auto create user after payment woocommerce order by mobile
<?php
add_action( 'woocommerce_thankyou', 'ecommercehints_create_user_account_after_payment', 10, 1 );
function ecommercehints_create_user_account_after_payment( $order_id ) {
// If user is logged in, do nothing because they already have an account
if( is_user_logged_in() ) return;
// Get the newly created order
$order = wc_get_order( $order_id );
@mehrshaddarzi
mehrshaddarzi / digits_duplicate_number.php
Created February 22, 2025 06:28
Digits Duplicate numbers user_login WordPress
<?php
/*$users = include WPMU_PLUGIN_DIR .'/wp_users.php';
foreach($users as $user) {
$ID = $user['ID'];
$user_login = $user['user_login'];
echo $ID.'|'.$user_login.'|Done';
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>زوم با Transform Scale</title>
<style>
body, html {
margin: 0;
padding: 0;
@mehrshaddarzi
mehrshaddarzi / wordpress_request_timeout.php
Last active March 2, 2025 11:37
WordPress request timeout
<?php
add_filter('http_request_args', 'bal_http_request_args', 100, 1);
function bal_http_request_args($r) //called on line 237
{
$r['timeout'] = 15;
return $r;
}
@mehrshaddarzi
mehrshaddarzi / join_meta_query.php
Created February 4, 2025 10:42
WordPress mysql join meta query
```
SELECT p.ID, p.user_login, p.user_email, p.display_name, phone.meta_value AS phone,
(SELECT SUM(CASE WHEN t.type = 'credit' THEN t.amount ELSE -t.amount END) as balance FROM wp_woo_wallet_transactions AS t WHERE t.user_id=p.ID AND t.deleted=0) as balance
FROM wp_users AS p LEFT JOIN wp_usermeta AS phone ON p.ID = phone.user_id AND 'billing_phone' = phone.meta_key;
```
// More:
https://stackoverflow.com/questions/26319613/improving-a-query-using-a-lot-of-inner-joins-to-wp-postmeta-a-key-value-table
@mehrshaddarzi
mehrshaddarzi / woocommerce-role-based-price.php
Created December 4, 2024 07:07
woocommerce-role-based-price plugin
<?php
_enable_role_based_price
0 or 1
enable_role_based_price: on
role_based_price[subscriber][regular_price]: 10
role_based_price[subscriber][selling_price]: 20
role_based_price[contributor][regular_price]: 30
role_based_price[contributor][selling_price]: 40
@mehrshaddarzi
mehrshaddarzi / wc_bundle_product.php
Created November 24, 2024 11:54
Get WooCommerce bundles Product
<?php
if ( $product->is_type('bundle') ) {
$hasqty = 5;
$bundleditems = $product->get_bundled_items();
foreach ( $bundled_items as $bundleditem ) {
if ( $bundleditem->is_optional('yes')) {
$hasqty = 1;
echo "<h2> 1 product optional </h2>";
} else {