Skip to content

Instantly share code, notes, and snippets.

View IronGhost63's full-sized avatar

Jirayu IronGhost63

View GitHub Profile
@IronGhost63
IronGhost63 / block-image.js
Last active February 6, 2020 13:55
Gutenberg image block - default link destination
(function(wp) {
wp.hooks.addFilter(
"blocks.registerBlockType",
"my-plugin/modify-linkDestination-default",
function (settings, name) {
if (name === "core/image") {
settings.attributes.linkDestination.default = "media";
} else if ( name === "core/gallery" ) {
settings.attributes.linkTo.default = "media";
}
@IronGhost63
IronGhost63 / filters.php
Last active May 23, 2019 10:16
Add file from media library into a zip file, then insert this zip file back into media library
<?php
/**
* Add "Download selected as a zip file" into media bulk action
*/
add_filter('bulk_actions-upload', function( $actions ) {
$actions['download'] = 'Download selected as a zip file';
return $actions;
});
/**
@IronGhost63
IronGhost63 / README.md
Last active May 13, 2019 20:11
Test Array vs Object in different approches
@IronGhost63
IronGhost63 / functions.php
Last active April 26, 2019 03:55
Gutenberg
<?php
require_once('gutenberg-blocks/sample.php');
add_action('acf/init', new WP63\Block\SampleBlock);
{
"scripts": {
"translation": "mkdir -p ./resources/lang && find ./resources ./app -iname '*.php' | xargs xgettext --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -o resources/lang/agoda.pot && find ./resources -iname '*.blade.php' | xargs xgettext --language=Python --add-comments=TRANSLATORS --force-po --from-code=UTF-8 --default-domain=de_DE -k__ -k_e -k_n:1,2 -k_x:1,2c -k_ex:1,2c -k_nx:4c,12 -kesc_attr__ -kesc_attr_e -kesc_attr_x:1,2c -kesc_html__ -kesc_html_e -kesc_html_x:1,2c -k_n_noop:1,2 -k_nx_noop:3c,1,2, -k__ngettext_noop:1,2 -j -o resources/lang/agoda.pot",
"translation:update": "for filename in ./resources/lang/*.po; do msgmerge -U $filename ./resources/lang/agoda.pot; done; rm ./resources/lang/*.po~",
"translation:compile": "rm ./resources/lang/*.mo; for filenam
@IronGhost63
IronGhost63 / bitbucket-pipelines.yml
Last active January 30, 2023 20:02
Auto deploy master to Cloudways
# This is a sample build configuration for PHP.
# Check our guides at https://confluence.atlassian.com/x/e8YWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: oneko/php-7.1-node-yarn
pipelines:
branches:
master:
@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 + "แล้ว");
}
});
@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 / 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'
<?php
$db_date = "2018-01-04 14:37:50"; // เวลาจากฐานข้อมูล
$timestamp = strtotime( $db_date ); // แปลงเวลาจากฐานข้อมูลเป็น timestamp
$date = date( "j F Y", $timestamp ); // แปลง timestamp เป็นวันที่
?>