Skip to content

Instantly share code, notes, and snippets.

View besrabasant's full-sized avatar
🏠
Working from home

Basant Besra besrabasant

🏠
Working from home
View GitHub Profile
@besrabasant
besrabasant / 1.md
Last active November 10, 2019 03:59
Add notification bubble for to custom admin menu page

There are two classes used by WordPress to display the notification bubbles:

  • update-plugins
  • awaiting-mod

Your notifications have nothing to do with plugins, so it will be nicer to use the second class. You should change your function like this:

function contact_form_create() {
 $notification_count = 2; // Notification value
@besrabasant
besrabasant / TreeBuilder.php
Created August 20, 2019 14:51 — forked from mistic100/TreeBuilder.php
[PHP] Recursive builder pattern
<?php
/**
* Recursive builder pattern
*
* Usage:
* $tree = \Tree\Builder::init()
* ->setName('parent')
* ->addChild()
@besrabasant
besrabasant / Laravel-Container.md
Created April 23, 2019 02:35
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@besrabasant
besrabasant / xdebug.sh
Last active April 20, 2019 04:01
XDebug Toggler
#!/bin/bash
# Simple script to enable or disable the xdebug extension
# Note that xargs removes whitespace
PHPINIDIR=`php --ini | head -1 | cut -d ":" -f 2 | xargs echo`
PHPDIR=${PHPINIDIR//"/cli"/}
case $1 in
on)
@besrabasant
besrabasant / WordPressMultisiteValetDriver.php
Created April 11, 2019 04:17
Valet WP Multisite Driver
<?php
/*
Valet driver for Wordpress Multisite
Usage: Drop this file into your ~/.valet/Drivers/ directory
*/
class WordPressMultisiteValetDriver extends WordPressValetDriver
{
/**
* @var string The public web directory, if deeper under the root directory
*/
@besrabasant
besrabasant / script.js
Last active May 7, 2020 15:02
Get Query String Parameters as JSON Object with JavaScript
function getUrlParameter(name, defaultValue = "") {
query = query.substring(location.search.indexOf("?") + 1);
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g;
var decode = function(str) {
return decodeURIComponent(str.replace(decodeRE, " "));
};
image: node:8.15.0-jessie
build:
stage: build
only:
- master
script:
- cd site/web/app/themes/$THEME_DIR
- yarn && yarn build:production
artifacts:
add_filter('upload_dir', 'cdn_upload_url');
function cdn_upload_url($args)
{
	$args['baseurl'] = 'https://your.awesomecdn.net/wp-content/uploads'; //Change to your base CDN directory - no trailing slash
	return $args;
}
@besrabasant
besrabasant / command.md
Created September 5, 2018 05:50
Exclude folder while running find command
find . -type d \( -path ./node_modules -o -path ./vendor -o -path ./bower_components \) -prune -o -print

@besrabasant
besrabasant / custom-menu-panel.php
Created September 2, 2018 11:06 — forked from nikolov-tmw/custom-menu-panel.php
This registers a custom meta box for nav menus and renders it. Obviously $my_items would ideally be not hard-coded and instead it would come somewhere from the DB. The custom items add to the menu and save properly, but will probably not be displayed correctly. You might need to hook to the 'wp_setup_nav_menu_item' filter in order to fix the men…
<?php
function my_register_menu_metabox() {
$custom_param = array( 0 => 'This param will be passed to my_render_menu_metabox' );
add_meta_box( 'my-menu-test-metabox', 'Test Menu Metabox', 'my_render_menu_metabox', 'nav-menus', 'side', 'default', $custom_param );
}
add_action( 'admin_head-nav-menus.php', 'my_register_menu_metabox' );
/**