Skip to content

Instantly share code, notes, and snippets.

View MahdiY's full-sized avatar
🎯
Focusing

Mahdi Yousefi MahdiY

🎯
Focusing
View GitHub Profile
@MahdiY
MahdiY / wpdl.php
Last active July 14, 2019 04:52
Easy download and extract last wordpress version
<?php
if( ! extension_loaded('zip') ) {
die('missing zip extension!');
}
set_time_limit(0);
$file = 'wp.zip';
@MahdiY
MahdiY / serve.py
Created May 20, 2019 17:18
Serve a directory with python
import http.server
import socketserver
import os
PORT = 786
web_dir = os.path.join(os.path.dirname(__file__), '<DIR>')
os.chdir(web_dir)
Handler = http.server.SimpleHTTPRequestHandler
@MahdiY
MahdiY / git_pull.bat
Created May 16, 2019 08:08
Serve laravel, npm run watch and repeated git pull
git pull
TIMEOUT /T 30 /NOBREAK
git_pull.bat
@MahdiY
MahdiY / wp_dropdown_categories.php
Last active March 16, 2019 14:00
wp_dropdown_categories with multiple select
<div class="ci-select">
<?php
wp_dropdown_categories( array(
'taxonomy' => 'property_location',
'hierarchical' => true,
'show_option_none' => esc_html_x( '-', 'any property location', 'ci_theme' ),
'option_none_value' => '',
'name' => 's_property_location',
'id' => 'property_location',
'selected' => isset( $_GET['s_property_location'] ) ? $_GET['s_property_location'] : '', // e.x 86,110,786
@MahdiY
MahdiY / disable-updates.php
Created March 1, 2019 15:03 — forked from willmot/disable-updates.php
Disable core, theme and plugin update checks and notices and remove the update page from nav
<?php
// Don't disable on dev
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
// Disable core update checking
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'wp_version_check', 'wp_version_check' );
@MahdiY
MahdiY / s2c-md5.php
Last active January 7, 2019 08:05
String to html hex color function
<?php
function s2c( $str ) {
return substr( md5( $str . "snippets.ir" ), -6, 6 );
}
$str = 'snippets.ir';
print '<span style="background-color:#' . s2c($str) . '">' . $str . '</span>';
$str = 'mahdiy.ir';
@MahdiY
MahdiY / get_sorted_categories.php
Created September 18, 2018 10:52
wordpress get_categories order by last post.
<?php
function get_sorted_categories( $order_by = 'id', $args = array() ){
global $wpdb;
$category = get_categories( $args );
$order = [
'id' => 'post.ID',
'date' => 'post.post_date',
@MahdiY
MahdiY / disable-free-shipping-on-coupon.php
Last active March 16, 2019 13:58
remove free shipping, when coupon applied on cart. woocommerce
<?php
add_filter( 'woocommerce_package_rates', 'woocommerce_package_rates_remove_free', 1000 );
function woocommerce_package_rates_remove_free( $rates ) {
// MahdiY.IR
foreach ( $rates as $rate_id => $rate )
if ( 'free_shipping' === $rate->method_id
&& count( wc()->cart->get_applied_coupons() ) ) {
@MahdiY
MahdiY / reading_time.php
Last active September 13, 2018 14:49
Estimated reading time in PHP, by MahdiY
<?php
function reading_time( $content ) {
$words_per_minute = 200;
$word = count( explode(" ", strip_tags( $content ) ) );
return ceil($word / $words_per_minute);
}
@MahdiY
MahdiY / benchmark_example.php
Created August 19, 2018 14:03
CPU & RAM Benchmarking in php
<?php
// Script start
$usage_start = getrusage();
echo "PHP RAM Usage 1: " . convert(memory_get_usage()) . "\n";
ob_start();
// Start Code