Skip to content

Instantly share code, notes, and snippets.

View sobujbd's full-sized avatar

Sobuj sobujbd

  • Bangladesh
View GitHub Profile
@sobujbd
sobujbd / Mark parent navigation active when on custom post type single page Mark (highlight) custom post type parent as active item in Wordpress Navigation.When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Get post ID, if nothing found set to NULL
$id = ( isset( $post->ID ) ? get_the_ID() : NULL );
@sobujbd
sobujbd / README.md
Created July 16, 2020 13:02 — forked from mbleigh/README.md
Firebase Hosting Fetch All Files

Fetch All Files from Firebase Hosting

This script fetches all of the files from the currently deployed version of a Firebase Hosting site. You must be signed in via the Firebase CLI and have "Site Viewer" permission on the site in question to be able to properly run the script.

Running via NPX

npx https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d <site_name>
@sobujbd
sobujbd / csv-to-json.php
Created July 30, 2019 05:53 — forked from robflaherty/csv-to-json.php
Convert CSV to JSON
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed
@sobujbd
sobujbd / set-value.md
Created June 1, 2019 04:25 — forked from JeffreyWay/set-value.md
PHP: Set value if not exist

You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:

name = name || 'joe';

This is quite common and very helpful. Another option is to do:

name || (name = 'joe');
@sobujbd
sobujbd / wp-cli-create.sh
Created April 8, 2019 14:54 — forked from oxocode/wp-cli-create.sh
wp-cli-create
#!/bin/bash
# Setup Variables
DBNAME=dbname
DBUSER=dbuser
DBPASS=dbpass
DBHOST=localhost
DBPREFIX=oxo_
URL=http://
@sobujbd
sobujbd / wp_db_create_backup.sh
Created April 8, 2019 14:54 — forked from LostinOrchid/wp_db_create_backup.sh
Create database backup in Wordpress
#!/usr/bin/env bash
sqllocation=~/.sql_backup_files
# echo $(wp --version)
wp --version >/dev/null 2>&1 || {
echo "I need 'wp' command to be able to execute further"
exit 1
}
# Check if it is a wordpress directory or is installed
@sobujbd
sobujbd / unzip.php
Created November 14, 2017 05:34 — forked from trajche/unzip.php
Unzip a file on one.com with PHP
<?php
$unzip = new ZipArchive;
$out = $unzip->open('file-name.zip');
if ($out === TRUE) {
$unzip->extractTo(getcwd());
$unzip->close();
echo 'File unzipped';
} else {
echo 'Something went wrong?';
@sobujbd
sobujbd / install.php
Created September 30, 2017 06:50 — forked from tschoffelen/install.php
A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually.
<?php
echo '<pre>';
echo '<span style="color:blue">DOWNLOADING...</span>'.PHP_EOL;
// Download file
file_put_contents('wp.zip', file_get_contents('http://wordpress.org/latest.zip'));
$zip = new ZipArchive();
$res = $zip->open('wp.zip');
if ($res === TRUE) {