Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / nginx
Last active May 4, 2023 08:04
nginx wordpress
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
@mehrshaddarzi
mehrshaddarzi / HTTP Block Request WordPress.md
Last active March 12, 2023 16:30
HTTP Block Request WordPress
define( 'WP_HTTP_BLOCK_EXTERNAL', true );
define( 'WP_ACCESSIBLE_HOSTS', '*.wordpress.org, *.samyarcloud2.ir' );
@mehrshaddarzi
mehrshaddarzi / GROUP CONCAT for get Meta Query in WordPress.php
Created March 9, 2023 05:33
GROUP CONCAT for get Meta Query in WordPress
<?php
/**
* Get Post Ids With GROUP_CONCAT
* https://stackoverflow.com/questions/11140647/mysql-concat-two-fields-and-use-them-in-where-clause
* https://makitweb.com/how-to-concatenate-multiple-columns-in-mysql/
* https://stackoverflow.com/questions/9693099/using-group-concat-in-my-sql-query-with-wp-usermeta-table
*/
// User Table {ID, name, user_email}
@mehrshaddarzi
mehrshaddarzi / php-curl-wordpress.php
Created February 22, 2023 07:02
php curl for wordpress
<?php
$route = 'https://www.quiz24.ir/api/v1/xxxx';
$argument = array(
CURLOPT_URL => $route,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 15,
CURLOPT_FOLLOWLOCATION => true,
@mehrshaddarzi
mehrshaddarzi / get.php
Created February 9, 2023 08:38
Create Hook Between Two WordPress Push Data
<?php
$post_input_data = json_decode(file_get_contents("php://input"), true);
if (isset($post_input_data['woocommerce_order']) and !empty($post_input_data['woocommerce_order'])) {
$array = $post_input_data['woocommerce_order'];
$data = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
file_put_contents(getcwd() . "/order.json", $data);
echo 'File is Saved';
exit;
}
@mehrshaddarzi
mehrshaddarzi / digits_plugin.php
Created February 7, 2023 12:11
Digits Plugin User Meta
<?php
// Set digits Plugin Phone Number
$phoneNonZero = ltrim($user_login, '0');
update_user_meta($user_id, 'digt_countrycode', '+98');
update_user_meta($user_id, 'digits_phone', '+98' . $phoneNonZero);
update_user_meta($user_id, 'digits_phone_no', $phoneNonZero);
@mehrshaddarzi
mehrshaddarzi / logged-as.php
Last active January 16, 2024 17:32
Login by User
<?php
/*
* Plugin Name: Login a User
*/
add_action('init', function(){
if(isset($_GET['_login_user'])) {
// Get By Users ID
$user_id = 'Khazaeimilad';
$user = get_user_by( 'login', $user_id );
@mehrshaddarzi
mehrshaddarzi / cronjob-log-user.php
Last active January 31, 2024 17:33
Log User in PHP
<?php
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$log = "User: " . $_SERVER['REMOTE_ADDR'] . ' - ' . date("F j, Y, g:i a") . "\n" .
"Url: " . $url . "\n" .
"Method: " . $_SERVER['REQUEST_METHOD'] . "\n" .
"------" . "\n";
//Save string to log, use FILE_APPEND to append.
file_put_contents(getcwd() . '/log_user.log', $log, FILE_APPEND);
// https://wpml.org/forums/topic/get-current-language-3/
// https://wpml.org/faq/how-to-get-current-language-with-wpml/
// https://wpml.org/wpml-hook/wpml_display_language_names/
// https://wpml.org/wpml-hook/wpml_active_languages/
<?php
$_lang = apply_filters( 'wpml_current_language', NULL );
if($_lang == "en") {
echo 'Language';
} else {