Skip to content

Instantly share code, notes, and snippets.

View tanftw's full-sized avatar
😅
Fixing bugs

Tan Nguyen tanftw

😅
Fixing bugs
View GitHub Profile
@tanftw
tanftw / php-get.js
Last active August 29, 2015 14:15
PHP $_GET for Javascript
var parts = window.location.search.substr(1).split("&");
var $_GET = {};
for (var i = 0; i < parts.length; i++) {
var temp = parts[i].split("=");
$_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
}
@tanftw
tanftw / gist:a776f381f5e44c0c2828
Created April 19, 2015 19:14
Meta Box field demo
$meta_boxes[] = array(
'id' => 'select_post',
'title' => 'Post Selector',
'pages' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Post',
@tanftw
tanftw / array_unflatten.php
Last active December 21, 2020 02:24
Array Unflatten with PHP
<?php
if ( ! function_exists( 'array_unflatten' ) )
{
/**
* Convert flatten collection (with dot notation) to multiple dimmensionals array
* @param Collection $collection Collection to be flatten
* @return Array
*/
function array_unflatten( $collection )
@tanftw
tanftw / array_swap.php
Last active August 29, 2015 14:22
array_swap
<?php
if ( ! function_exists( 'array_swap' ) )
{
/**
* This function works like array_flip but allows users use values as array
* For example,
* [ foo => ['bar', 'baz'] ]
* will becomes
* [
* 'bar' => 'foo',
@tanftw
tanftw / str_snake.php
Last active August 29, 2015 14:22
Snake case in WP
<?php
/**
* Convert a regular string to snake_case
* For example, Hello World => hello_world
*
* @param String $str String to be converted
* @return String String in snake_case
**/
function str_snake( $str )
{
@tanftw
tanftw / array_symetry.php
Created June 4, 2015 16:53
Array Symetry
<?php
/**
* Put an array. Then make the key same as value. Or key will become slug of value of slug is set to true
*
* @param Array $array Array to convert
* @param boolean $slug Slug the key or not
* @return Array output
*/
function array_symmetry( $array, $slug = false )
{
@tanftw
tanftw / conditional-logic-example.php
Last active October 30, 2015 23:42
Conditional Logic Basic Syntax
<?php
add_filter( 'rwmb_meta_boxes', function( $meta_boxes )
{
$meta_boxes[] = array(
'id' => 'brand_product',
'title' => 'Brands and Products',
'post_types' => array( 'post', 'page' ),
'context' => 'normal',
'priority' => 'high',
// Conditional Logic can be applied to Meta Box
@tanftw
tanftw / import.php
Last active August 29, 2015 14:25
Import Solar Companies
<?php
include 'wp-load.php';
set_time_limit(0);
session_start();
if ( ! isset( $_SESSION['import_3'] ) ) :
@tanftw
tanftw / lamp.sh
Created October 10, 2015 05:58
Ubuntu LAMP Server Startup
#Install LAMP Server
#--------------------------
sudo apt-get update
sudo apt-get install tasksel
sudo tasksel install lamp-server
#Install PHPMyAdmin
#----------------------------
sudo apt-get install phpmyadmin
# Open file below and add the following line to the end
@tanftw
tanftw / CanUseMeta.php
Created October 13, 2015 03:20
CanUseMeta traits for Laravel
<?php
namespace App;
trait CanUseMeta
{
public function getMetaTable()
{
return $this->table . '_meta';
}