Skip to content

Instantly share code, notes, and snippets.

View IronGhost63's full-sized avatar

Jirayu IronGhost63

View GitHub Profile
@IronGhost63
IronGhost63 / gist:96b1cf93ce46b7edad9e764570d85d88
Last active June 21, 2017 20:31
Generate map link according to accessing OS
/**
* Determine the mobile operating system.
* This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'.
*
* @returns {String}
*
* Source: http://stackoverflow.com/questions/21741841/detecting-ios-android-operating-system
*/
function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
@IronGhost63
IronGhost63 / functions.php
Created April 7, 2017 16:10
Enable oEmbed support in wpForo
<?php
add_filter('wpforo_get_posts', 'enable_wpforo_oembed');
function enable_wpforo_oembed($content){
global $wp_embed;
foreach($content as $single){
$single['body'] = $wp_embed->autoembed( $single['body'] );
$return[] = $single;
}
@IronGhost63
IronGhost63 / functions.php
Created May 31, 2017 12:38
[Hook] Fix Thai URL on IIS
<?php
function fix_iis_thai_url(){
global $_SERVER;
$_SERVER['REQUEST_URI'] = isset($_GET['requesturi']) ? $_GET['requesturi'] : '/';
}
add_action("plugins_loaded", "fix_iis_thai_url");
/*
Still need another fix on web.config
@IronGhost63
IronGhost63 / show-url.php
Created June 21, 2017 20:28
add .active if current url match href
<?php
function show_url($url, $text = ''){
$current = $uri = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo '<a href="'.$url.'" '.($current == $url ? 'class="active"' : '').'>'.(empty($text) ? $url : $text).'</a>';
}
?>
<div><?php show_url('https://jirayu.in.th', 'Website'); ?></div>
@IronGhost63
IronGhost63 / functions.php
Last active December 4, 2017 12:16
FacetWP Random Order with Preservation (use session_id as a seed instead of time()
<?php
// Original - https://facetwp.com/random-ordering-in-facetwp/
function preserve_random_order( $orderby ) {
if(session_id() == ""){
session_start();
}
$seed = session_id(); // use session_id as a seed
$orderby = str_replace( 'RAND()', "RAND('{$seed}')", $orderby );
return $orderby;
}
@IronGhost63
IronGhost63 / functions.php
Created December 7, 2017 12:27
lock version for specific plugin
<?php
function wp63_lock_plugin_version($data){
$lock = apply_filters( "wp63_lock_plugin_version", array() );
if(isset( $data->response )){
foreach( $data->response as $key => $value ){
if( isset($lock[$value->slug]) && $value->new_version != $lock[$value->slug]){
$data->no_update[] = $value;
unset($data->response[$key]);
}
<?php
$db_date = "2018-01-04 14:37:50"; // เวลาจากฐานข้อมูล
$timestamp = strtotime( $db_date ); // แปลงเวลาจากฐานข้อมูลเป็น timestamp
$date = date( "j F Y", $timestamp ); // แปลง timestamp เป็นวันที่
?>
@IronGhost63
IronGhost63 / functions.php
Created January 9, 2018 08:20
transient cache
<?php
function transient_example(){
global $wpdb; // WordPress database class
if(false === ($data = get_transient( "transient_name" ))) {
// transient already expired or no transient
// re-cache data to transient
$data = query_stuff_here(); // select * from wp_postmeta where `meta_key` = 'field_name'
@IronGhost63
IronGhost63 / functions.php
Last active January 12, 2018 10:11
Show posts which have search term in title first
<?php
function wp63_alter_search_weight($args, $query){
global $wpdb;
if( $query->query_vars['search_terms'][0] ){
$args['orderby'] = 'CASE WHEN `'.$wpdb->posts.'`.`post_title` LIKE "%'.$query->query_vars['search_terms'][0].'%" THEN 1 ELSE 0 END DESC' ;
}
return $args;
}
@IronGhost63
IronGhost63 / blognone-title.js
Created March 6, 2018 11:56
How to make article title properly in Blognone
jQuery(".content-title-box").each(function(index){
var title = jQuery(this).find("a").text();
if(title.substr(title.length - 4) !== "แล้ว"){
jQuery(this).find("a").text(title + "แล้ว");
}
});