Skip to content

Instantly share code, notes, and snippets.

View oberonlai's full-sized avatar

Oberon Lai oberonlai

View GitHub Profile
@carlodaniele
carlodaniele / block.json
Last active December 14, 2024 11:23
An example Gutenberg block (not for production)
{
"apiVersion": 2,
"name": "my-affiliate-plugin/my-affiliate-block",
"version": "0.1.0",
"title": "Affiliate Block",
"category": "design",
"icon": "money",
"keywords": [ "kinsta", "affiliate", "money" ],
"description": "An example block for Kinsta readers",
"supports": {
@nczz
nczz / WPBakery_js_composer_hack.php
Last active October 8, 2020 08:19
WordPress WPBakery (js_composer) 的漏洞硬修正 Ref: https://www.facebook.com/a.tech.guy
<?php
//修正 wp-content/plugins/js_composer/include/classes/core/class-vc-post-admin.php 中 saveAjaxFe 方法的權限補強,補強在方法第一行
$user = wp_get_current_user();
// 僅限制「編輯」、「管理員」與「商店管理員」等級開放編輯,若有其他角色,自行補充
$allowed_roles = array('editor', 'administrator', 'shop_manager');
if (empty(array_intersect($allowed_roles, $user->roles))) {
wp_send_json_error();
exit;
}
@mrmu
mrmu / gist:ab87723d54f720a6d603eeafa9660522
Last active April 28, 2023 09:06
使用 woocommerce 內建的 wc logger,將 debug 用的 log 記錄到後台 WooCommerce / 狀態 / 記錄 裡。
<?php
/*
* arg:
* $msg: 要紀錄的內容,可用 string/array
* $source_name: 此 log 的別名,方便於後台辨識
*/
function my_wc_log($msg, $source_name) {
if (function_exists('wc_get_logger')) {
$log = wc_get_logger();
@nczz
nczz / mxp-mitake-sms.php
Last active April 15, 2024 16:09
WordPress 三竹簡訊發送外掛
<?php
/*
Plugin Name: 三竹簡訊 Webhook
Plugin URI: https://gist.github.com/nczz/750c3d8d18b9e0ca07ca06a248c11570
Description: 接收 Webhook 請求發送簡訊
Author: Chun
Version: 1.0
Author URI: https://www.mxp.tw/
*/
@nczz
nczz / export-csv-file.php
Created October 10, 2018 14:08
[PHP] 寫出一個匯出 CSV 檔案的起手式
<?php
//設定系統環境,確保輸出執行環境無礙
set_time_limit(0);
ini_set('memory_limit', '256M');
//判斷執行權限
//建立資料庫連線,開始取得資料
//撰寫資料庫欄位與可讀性資料的轉換方法
@westonruter
westonruter / wp-42573.php
Last active January 16, 2025 14:37
WP Trac #42573: Fix for theme template caching. https://core.trac.wordpress.org/ticket/42573
<?php
/**
* Plugin name: WP Trac #42573: Fix for theme template file caching.
* Description: Flush the theme file cache each time the admin screens are loaded which uses the file list.
* Plugin URI: https://core.trac.wordpress.org/ticket/42573
* Author: Weston Ruter, XWP.
* Author URI: https://weston.ruter.net
*/
function wp_42573_fix_template_caching( WP_Screen $current_screen ) {
@weihanglo
weihanglo / days-with-internet-explorer.md
Last active January 11, 2022 09:39
與 IE 相處的日子

與 IE 相處的日子

近幾年來,JavaScript 可謂風生水起,從後端到前端,從 mobile 到 desktop,各種 module 滿天飛,信手拈來就是一個 web app。不過,「沒碰過 IE,別說你會做前端」,本人從超新手的角度出發,整理最近修正 IE 相容性遇到的坑與解法,給自己日後留個參考。

(撰於 2017-07-15,基於 IE 11/Edge 15)

Contents

var preventMultipleInstances = function(window) {
var socket = (process.platform === 'win32') ? '\\\\.\\pipe\\myapp-sock' : path.join(os.tmpdir(), 'myapp.sock');
net.connect({path: socket}, function () {
var errorMessage = 'Another instance of ' + pjson.productName + ' is already running. Only one instance of the app can be open at a time.'
dialog.showMessageBox(window, {'type': 'error', message: errorMessage, buttons: ['OK']}, function() {
window.destroy()
})
}).on('error', function (err) {
if (process.platform !== 'win32') {
// try to unlink older socket if it exists, if it doesn't,
@guweigang
guweigang / git_toturial
Last active November 4, 2025 02:18
git命令大全
git init # 初始化本地git仓库(创建新仓库)
git config --global user.name "xxx" # 配置用户名
git config --global user.email "[email protected]" # 配置邮件
git config --global color.ui true # git status等命令自动着色
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
git config --global --unset http.proxy # remove proxy configuration on git
git clone git+ssh://[email protected]/VT.git # clone远程仓库
@siteoptimo
siteoptimo / WP_User_Query Order by RAND
Last active November 8, 2022 19:34
This will allow to order a wordpress user query by random.
<?php
// put this in your functions.php
add_filter('pre_user_query', function(&$query) {
if($query->query_vars["orderby"] == 'rand') {
$query->query_orderby = 'ORDER by RAND()';
}
});
// Query will look like this:
$args = array('orderby' => 'rand', 'number' => 5);