Skip to content

Instantly share code, notes, and snippets.

View sourovroy's full-sized avatar

Sourov Roy sourovroy

View GitHub Profile
@sourovroy
sourovroy / functions.php
Created February 14, 2018 07:02
WordPress allow any page to add extra url with it
<?php
/**
* Custom rewrite rule for career page
*/
add_action('init', function(){
add_rewrite_tag('%office_location%','([^&]+)');
add_rewrite_tag('%job_position%','([^&]+)');
});
@sourovroy
sourovroy / show-error.php
Last active January 24, 2018 10:00
Display PHP error. Enable debuging
<?php
// Show all php errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// END

Laravel install process in ubuntu

Copy Laravel Files

composer create-project --prefer-dist laravel/laravel blog

Folder Permision

@sourovroy
sourovroy / MediaController.php
Created November 20, 2017 12:43
Laravel upload file with unique file name
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class MediaController extends Controller
{
/**
@sourovroy
sourovroy / slug.php
Last active November 18, 2017 11:50
Generate a unique slug from post title
<?php
/**
* Create unique slug for post
*/
public static function generateSlug($title)
{
$slug = substr(str_slug($title), 0, 175); // Slug length will be 175 charecter
$latestSlug = static::whereRaw("slug = '$slug' or slug LIKE '$slug-%'")->value('slug');
if(!empty($latestSlug)){
@sourovroy
sourovroy / setHTTPRequest.php
Last active November 5, 2017 18:33
This is a source file of a article about PHP cURL. http://sourov.im/send-http-request-using-php-curl/
<?php
/*
|---------------------------------------------------
| PHP class to send HTTP request in better way
|---------------------------------------------------
*/
if(!class_exists('setHTTPRequest')){
class setHTTPRequest
{
/**
@sourovroy
sourovroy / wp-admin-pagination.php
Last active September 26, 2017 13:32
Custom pagination for WordPress admin panel
<?php
function affilate_list_pagination($total_items, $total_pages, $current){
$output = '<span class="displaying-num">'.sprintf(_n('%s item', '%s items', $total_items), number_format_i18n($total_items)).'</span>';
$removable_query_args = wp_removable_query_args();
$current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
@sourovroy
sourovroy / print-element.js
Created July 26, 2017 09:16
Print a element
var PrintContent = jQuery("div.col-sm-12 > div.inner"),
PrintContentClone = PrintContent.clone();
$('<iframe>', {
name: 'myprintiframe',
class: 'productPrintFrame'
})
.appendTo('body')
.contents().find('body')
.append(PrintContentClone);
@sourovroy
sourovroy / NecessaryjQueryCode.js
Created April 18, 2017 11:27
Necessary jQuery Code
//Checked Check box
jQuery(':checkbox').prop("checked", true);
//Click all buttons at a time
jQuery('.row-options .delete-field').trigger("click");
@sourovroy
sourovroy / wp-bootstrap-pagination.php
Created April 17, 2017 12:44
Use bootstrap pagination in WordPress
<?php
function wp_bootstrap_pagination(){
$search_paging = get_the_posts_pagination(array(
'prev_text' => __( 'Previous', '' ),
'next_text' => __( 'Next', '' ),
'mid_size' => 2
));