Skip to content

Instantly share code, notes, and snippets.

View musamamasood's full-sized avatar
🎯
Focusing

Muhammad Usama Masood musamamasood

🎯
Focusing
View GitHub Profile
@musamamasood
musamamasood / CreateTrigger.php
Created December 11, 2019 16:06 — forked from me-shaon/CreateTrigger.php
Sample Laravel migration to create MySQL Trigger
<?php
use Illuminate\Database\Migrations\Migration;
class CreateTrigger extends Migration
{
public function up()
{
DB::unprepared('
CREATE TRIGGER tr_after_main_insert AFTER INSERT ON `main` FOR EACH ROW
@musamamasood
musamamasood / LogAfterRequest.php
Created December 4, 2019 10:48
Laravel Middleware for Request & Response
<?php
namespace App\Http\Middleware;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class LogAfterRequest {
protected $timestamp;
<?php
/*
Plugin Name: Disable Plugin for URl
Plugin URI: https://www.glowlogix.com
Description: Disable plugins for for specific backend pages.
Author: Muhammad Usama M.
Version: 1.0.0
*/
add_filter( 'option_active_plugins', 'disable_plugins_per_page' );
function disable_plugins_per_page( $plugin_list ) {
@musamamasood
musamamasood / functions.php
Created January 9, 2019 16:33 — forked from douglasanro/functions.php
Create WordPress settings page For custom options
<?php
// Let’s instantiate this class in our functions.php file:
if( is_admin() ) {
require 'simple_settings_page.php';
new simple_settings_page();
}
@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);
@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 / 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 / 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 / _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 / 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}} );