Skip to content

Instantly share code, notes, and snippets.

View musamamasood's full-sized avatar
🎯
Focusing

Muhammad Usama Masood musamamasood

🎯
Focusing
View GitHub Profile
function wishlist_refresh(){
if ( isset($_GET['flush']) ){
global $wp;
$current_url = home_url( remove_query_arg('flush', $wp->request) );
if ( wp_redirect( $current_url ) ) {
exit;
}
}
}
add_action('init', 'wihslist_refresh');
@musamamasood
musamamasood / gitBash_windows.md
Created March 23, 2017 20:44 — forked from evanwill/gitBash_windows.md
how to add more utilities to git bash for windows, wget, make

How to add more to Git Bash on Windows

Git for Windows is bundled with "Git Bash" terminal which is incredibly handy for unix-like commands on a windows machine. It is missing a few standard linux utilities, but it is easy to add ones that have a windows binary available.

The basic idea is that C:\Program Files\Git\mingw64\ is your / directory according to Git Bash (note: depending on how you installed it, the directory might be different. from the start menu, right click on the Git Bash icon and open file location. It might be something like C:\Users\name\AppData\Local\Programs\Git, the mingw64 in this directory is your root). If you go to that directory, you will find the typical linux root folder structure (bin, etc, lib and so on). If you are missing a utility, such as wget, track down a binary for windows and copy the files to the corrisponding directories. Sometimes the windows binary have funny prefixes, so you should rename the exe file to the

@musamamasood
musamamasood / functions.php
Created April 4, 2017 18:12
Plugin To Disabled the Ninja Form Trash Submission after 30 days.
/**
* Solution to disable the auto cleaning of trash submission in Ninja forms.
* http://ryansechrest.com/2013/09/prevent-wordpress-automatically-purging-trash-custom-post-type/
*
* @param $post_id
*/
function do_not_schedule_post_types( $post_id ) {
// array of post_type you don't want to be scheduled
$unscheduled_post_types = array( 'nf_sub');
@musamamasood
musamamasood / gist:68d77c7786f7aef624e5778edcdfe7f8
Created April 25, 2017 20:11 — forked from billerickson/gist:2047229
Improve performance of WP_Query
<?php
$args = array(
// Normal query goes here //
'no_found_rows' => true, // counts posts, remove if pagination required
'update_post_term_cache' => false, // grabs terms, remove if terms required (category, tag...)
'update_post_meta_cache' => false, // grabs post meta, remove if post meta required
);
@musamamasood
musamamasood / uninstall.php
Created April 25, 2017 21:02
Removed attachment for custom post type after plugin deleted.
function prefix_uninstall_attachments() {
global $wpdb;
$query = sprintf("
SELECT ID
FROM `%s`
WHERE post_type = '%s'
AND post_status NOT IN ( 'auto-draft', 'inherit' )
", $wpdb->posts, {{custom_post_type}} );
@musamamasood
musamamasood / _ide-helper.php
Created June 19, 2017 17:51 — forked from torounit/_ide-helper.php
PHPStorm等でWordPressのグローバル変数の入力補完を有効にする。プロジェクトのどこかに置いておくと補完されるようになる。
<?php
trigger_error("This file should not be included, only analyzed by your IDE", E_USER_ERROR);
$wp_the_query = new WP_Query();
/** @var WP_Query $wp_query */
$wp_query = $wp_the_query;
$wp_rewrite = new WP_Rewrite();
$wp = new WP();
@musamamasood
musamamasood / laravel-lumen-5-homestead-win.md
Created July 12, 2017 09:52 — forked from prograhammer/laravel-lumen-5-homestead-win.md
Laravel/Lumen 5.1 Homestead for Windows (includes fixes for shared-folder related slowness, npm install problems, caching, etc)

Laravel / Lumen Homestead for Windows w/fixes

###Initial installation and configuration Install Git for Windows which includes Git Bash.

Install VirtualBox and Vagrant.

Note: These fixes were not originally done for VirtualBox 5.0 and Vagrant 1.7.4. They are for the previous versions instead: VirtualBox 4.3.30 and Vagrant 1.7.3. Some of these fixes may not be needed now. For example, I recently upgraded to VirtualBox 5.0 and Vagrant 1.7.4 and I did not have to alter the Vagrant ruby (.rb) files as shown in part of this Gist below. I'll soon try from a fresh install (not upgrade) and update this Gist accordingly.

In Git Bash (always run as administrator), type cd ~ to

@musamamasood
musamamasood / functions.php
Last active September 28, 2018 04:36
Method to set order status failed or completed based on Stripe 3D.
add_action( 'wc_gateway_stripe_process_response', 'prefix_wc_gateway_stripe_process_response', 20, 2 );
function prefix_wc_gateway_stripe_process_response( $response, $order ){
if($response->source->type == 'three_d_secure'){
$order->update_status('completed', 'order_note'); ####
//WC_Stripe_Logger::log( 'wc_gateway_stripe_process_response three_d_secure response: ' . print_r( $response->source->type, true ) );
}elseif($response->source->type == 'card'){
$order->update_status('failed', 'order_note'); ####
//WC_Stripe_Logger::log( 'wc_gateway_stripe_process_response card response: ' . print_r( $response->source->type, true ) );
}
}
@musamamasood
musamamasood / functions.php
Last active November 12, 2018 15:27
Remove unused links in WordPress header
/**
* Remove junk from head
*/
// remove WordPress version number
function crave_remove_version() {
return '';
}
add_filter('the_generator', 'crave_remove_version');
remove_action('wp_head', 'wp_generator');
@musamamasood
musamamasood / CopyAsanaTasks.php
Created November 14, 2018 13:30 — forked from AWeg/CopyAsanaTasks.php
main changes: - Asana has own SSL cert -> had to add to lines of code - copies subtasks and up to 11 subtasks of subtasks - copies tags -> only tagnames not followers/descriptions
function asanaRequest($methodPath, $httpMethod = 'GET', $body = null)
{
$apiKey = 'ASANA_API_KEY_HERE'; /// Get it from http://app.asana.com/-/account_api
$url = "https://app.asana.com/api/1.0/$methodPath";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);