Skip to content

Instantly share code, notes, and snippets.

View finallyRaunak's full-sized avatar
💻
Writing Useless commit messages

Raunak Gupta finallyRaunak

💻
Writing Useless commit messages
View GitHub Profile
@finallyRaunak
finallyRaunak / wp custom error handaling.php
Created October 8, 2016 08:44
Customize wp_die so it doesn't look so cheesy. Preventing white wp-error screen.
<?php
/**
* Customize wp_die so it doesn't look so cheesy
*/
function my_custom_die_handler($message, $title = '', $args = array()) {
// Get the path to the custom die template
$template = get_theme_root() . '/' . get_template() . '/custom_die.php';
// If not an admin page, and if the custom die template exists
if (!is_admin() && file_exists($template)) {
@finallyRaunak
finallyRaunak / new_gist_file.php
Created October 8, 2016 09:38
Add Search Form To A WordPress Menu
<?php
//Add Search Form To A WordPress Menu
add_filter('wp_nav_menu_items', 'add_search_form', 10, 2);
function add_search_form($items, $args) {
if( $args->theme_location == 'CHANGE-THIS-TO-YOUR-MENU-NAME' )
$items .= '<li class="search">
<form role="search" method="get" id="searchform" action="'.home_url( '/' ).'">
<input type="text" value="search" name="s" id="s" />
@finallyRaunak
finallyRaunak / new_gist_file.php
Created October 8, 2016 09:50
How to Create Your Own WordPress Shortcodes
<?php
//Simple shortcodes
function HelloWorldShortcode() {
return '<p>Hello World!</p>';
}
add_shortcode('helloworld', 'HelloWorldShortcode');
//usage
@finallyRaunak
finallyRaunak / import-export-sql-file
Created October 11, 2016 06:54
Import an SQL file using the command line in MySQL
MySQL command line
Copy the SQL fiel into C:\xampp\mysql\bin path
then run mysql using command
C:\xampp\mysql\bin> mysql -u root -p
mysql> use db_name;
mysql> source backup-file.sql;
@finallyRaunak
finallyRaunak / post-ablity-for-woocommerce-customerfile.php
Created October 11, 2016 06:57
WordPress backend for WooCommerce customer user role. This will allow customer user role to access to wordpress backend and to publish/edit posts (with this last feature you should take care as customer user role will have the ability to add/edit/publish posts, so backup your database before).
<?php
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1);
add_filter('woocommerce_prevent_admin_access', '_wc_prevent_admin_access', 10, 1);
function _wc_prevent_admin_access($prevent_admin_access) {
$user_data = get_userdata( get_current_user_id() );
$user_roles = $user_data->roles;
$customer_role = get_role( 'customer' );
// For "customer" WooCommerce user role only
if (in_array('customer', $user_roles)) {
@finallyRaunak
finallyRaunak / new_gist_file_0
Created October 11, 2016 07:58
Disallow direct php file access
<Files *.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
@finallyRaunak
finallyRaunak / gravatar php function.php
Created October 11, 2016 07:59
PHP function to get Gravatar by email id.
<?php
if (!function_exists('getAvatar')) {
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
* ------------------------------------------------
* @param string $email The email address
* @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
@finallyRaunak
finallyRaunak / usefull php function.php
Last active October 27, 2016 12:30
Very usefully php function for web development.
<?php
if (!function_exists('isValidateDate')) {
/**
* Validate Date (i/p format YYYY-MM-DD)
* ------------------------------------------------
* '2013-13-01' - false
* '20132-13-01' - false
* '2013-11-32' - false
@finallyRaunak
finallyRaunak / get-current-controller-name.php
Created October 11, 2016 08:06
Laravel Helper function to get current controller name. This code can be written in app/Helpers/Helpers.php.
<?php
if (!function_exists('getControllerName')) {
function getControllerName($string) {
$pices = explode('\\', $string);
$pices1 = explode('@', end($pices));
$controller_name = current($pices1);
return ucfirst(str_replace('Controller', '', $controller_name));
}
}
@finallyRaunak
finallyRaunak / dynamically-add-active-class-to-a-navigation-menu-based-on-URL-laravel.php
Created October 11, 2016 08:11
The cleanest way to add the active class to bootstrap link components How to Dynamically Add Active Class to a Navigation Menu Based on URL. This code can be written in app/Helpers/Helpers.php.
<?php
if (!function_exists('isActiveRoute')) {
/*
|--------------------------------------------------------------------------
| Detect Active Route
|--------------------------------------------------------------------------
|
| Compare given route with current route and return output if they match.
| Very useful for navigation, marking if the link is active.
| class="{{ isActiveRoute('dashboard') }}"