Skip to content

Instantly share code, notes, and snippets.

/*
* Grid container. Based on Bootstrap 4.
*
* Partially works. No offset support.
*/
.grid-container {
display: grid;
grid-template-columns: repeat($grid-columns, 1fr);
margin: 0 auto;
@IronGhost63
IronGhost63 / query.php
Last active September 30, 2020 12:18
WP_Query only parent categories
<?php
namespace App;
use \WP_Query;
$categories = get_categories( ['parent' => 0] );
$ids = array_map( function( $category ) {
return $category->term_id;
}, $categories);
@IronGhost63
IronGhost63 / date.php
Last active August 9, 2020 19:08
Find first and last date of given week
<?php
// Get timestamp
$date_string = 'June 19, 2020';
$timestamp = strtotime( $date_string );
// Get weekday for given date
// Return 0-6 for Sun to Sat
$weekday = date( 'w', $timestamp );
// Calculate first and last date of given week
@IronGhost63
IronGhost63 / functions.php
Last active May 29, 2020 10:14
hook init
<?php
add_action( 'init', function() {
// Header will contains HTTP_TRUE_CLIENT_IP if accessing via Akamai
if( isset( $_SERVER['HTTP_TRUE_CLIENT_IP'] ) ) {
ob_start( function( $output ) {
return str_replace( 'wpengineurl.com', 'realdomain.com/sub' $output );
} );
}
} );
@IronGhost63
IronGhost63 / clock.php
Last active March 19, 2020 07:32
reformat clock-in clock-out
<?php
// ประกาศตัวแปรรอทิ้งไว้ จริงๆ ใช้ $data อันเดียวก็ได้ แล้ว map ทับเอา
$raw = [];
$data = [];
// ข้อมูลตัวอย่าง
$timein = [
[
'id' => 100287,
'date' => '2020-02-26',
@IronGhost63
IronGhost63 / upload.js
Last active February 28, 2020 15:10
upload.js
jQuery('.my-form').on('submit', (e) => {
e.preventDefault();
let form = e.target;
let formData = new FormData( form );
let userdata_access_token = getUserdataAccessToken();
// ถ้าต้องการเพิ่มข้อมูล ใช้ .append ได้เลย
formData.append('userdata_access_token', userdata_access_token);
// แล้วเอา formData ส่งไปเป็น data ของ $.ajax
@IronGhost63
IronGhost63 / app.js
Last active February 16, 2020 04:20
Add or Update product (use Array.prototype.findIndex())
let products = [
{
id: 1,
quantity: 10,
},
{
id: 2,
quantity: 2,
}
];
@IronGhost63
IronGhost63 / app.js
Created February 16, 2020 02:55
Add or Update product
let products = [
{
id: 1,
quantity: 10,
},
{
id: 2,
quantity: 2,
}
];
@IronGhost63
IronGhost63 / choices.php
Last active June 23, 2022 22:02
Random choices with weight adjustable
<?php
// define options with chance weight
$choices = [
'a' => 10.50,
'b' => 30,
'c' => 24.50,
'd' => 35,
];
$total = array_sum( $choices ); // total chance
@IronGhost63
IronGhost63 / form.js
Last active November 27, 2019 05:57
Reinit gravity form after submission
import '@nobleclem/jquery-multiselect';
export default () => {
let FormElement = $('.content-form__form-wrapper');
if ( FormElement.length ) {
let FormId = FormElement.attr('data-form-id'),
FormHtml = $('<div />').append(FormElement.clone()).html();
$(document).on('gform_confirmation_loaded', function() {