Skip to content

Instantly share code, notes, and snippets.

Avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
@nczz
nczz / artzustudio.com.har
Created Jun 3, 2022
artzustudio.com 與 wpbuildershop.com 的 HAR 瀏覽紀錄
View artzustudio.com.har
This file has been truncated, but you can view the full file.
{
"log": {
"version": "1.2",
"creator": {
"name": "WebInspector",
"version": "537.36"
},
"pages": [
{
@nczz
nczz / LightSail WordPress Cluster
Created May 2, 2022 — forked from mukeshwani/LightSail WordPress Cluster
Command, Code Snippts and Instructions for following video tutorial on setting up LightSail WordPress Cluster
View LightSail WordPress Cluster
# Welcome to the lightsail-wordpress-cluster wiki!
## Instructions, commands and code snippets to use and follow along the Video Tutorial on YouTube.
## Create Four LightSail Ubuntu Servers with the appropriate sizing. Name Three instances WP1, WP2, WP3, and name 4th instance LoadBalancer
##
## Open Ports 443 and 9443 (on LoadBalancer and WP1 in the LightSail Instance networking section)
## Run all commands with root (sudo su)
### Run following on each of the 3 WordPress instances
`ufw allow 80,443,9443,3306,4444,4567,4568/tcp;`
View import_json_appsscript.js
// import_json_appsscript.js
// https://gist.github.com/allenyllee/c764c86ed722417948fc256b7a5077c4
//
// Changelog:
// (Oct. 16 2019) tag: allenyllee-20191016
// 1. Fixed google script error: urlfetchapp - service invoked too many times https://stackoverflow.com/questions/10598179/google-apps-script-urlfetchapp-service-invoked-too-many-times
// (Jul. 16 2018) tag: allenyllee-20180716
// 1. Fixed the issue "If you try to query /arrayA[k]/arrayB[n]/arrayC[m]/.../member, you will always get /arrayA[k]/arrayB[k]/arrayC[k]/.../member."
// (Nov. 30 2017) tag: allenyllee-20171130
// 1. Add the ability to query array elements by using xpath like "/array[n]/member" where "n" is array index
@nczz
nczz / facebook_export_json_decode.php
Created Aug 26, 2021
Facebook 匯出 JSON 檔案編碼修正
View facebook_export_json_decode.php
<?php
/**
** 使用方式:在下載回來解壓的最上層目錄,執行 php -f facebook_export_json_decode.php 會將目錄下所有 JSON 檔案都轉檔編碼過。
**/
function glob_recursive($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
}
return $files;
@nczz
nczz / wordpress_fake_post_method.php
Last active Dec 25, 2020
[WordPress] 建立不存在 WP_POSTS 資料表中的「假文章/頁面」 https://www.mxp.tw/9104/
View wordpress_fake_post_method.php
<?php
function create_fake_post($content, $title = 'Slider Revolution') {
$post = new stdClass();
$post->ID = -1;
$post->post_author = get_current_user_id();
$post->post_date = current_time('mysql');
$post->post_date_gmt = current_time('mysql', 1);
$post->post_title = $title;
$post->post_content = $content;
$post->post_status = 'publish';
@nczz
nczz / WPBakery_js_composer_hack.php
Last active Oct 8, 2020
WordPress WPBakery (js_composer) 的漏洞硬修正 Ref: https://www.facebook.com/a.tech.guy
View WPBakery_js_composer_hack.php
<?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;
}
@nczz
nczz / get_instagram_media.php
Last active Sep 10, 2020 — forked from gsarig/get_instagram_media.php
[WordPress] 使用 Instagram API 嵌入圖文至網站的正確做法(2020/07後適用) https://www.mxp.tw/9037/
View get_instagram_media.php
<?php
/**
* 使用 Instagram (Facebook) API 取得用戶圖文的方法,翻譯自原文: https://www.gsarigiannidis.gr/instagram-feed-api-after-june-2020/
*
* @param $token // 存取權杖
* @param $user // 用戶編號,查詢工具: https://developers.facebook.com/tools/debug/accesstoken/
* @param int $limit // 查詢圖文筆數(不建議設定太多).
* @param string $fields // 其他欄位參考: https://developers.facebook.com/docs/instagram-basic-display-api/reference/media
* @param array $restrict // 取得媒體類型: IMAGE, VIDEO, CAROUSEL_ALBUM
*
@nczz
nczz / find_first_img_to_set_cover.php
Last active Jun 23, 2020
[WordPress] 抓取文章第一張媒體庫圖片設定為封面特色圖片 https://www.mxp.tw/8997/
View find_first_img_to_set_cover.php
<?php
include 'wp-load.php';
set_time_limit(0);
ini_set('memory_limit', '256M');
add_action('after_setup_theme', function () {
add_filter('intermediate_image_sizes', '__return_empty_array');
add_filter('wp_get_attachment_image_src', function ($image, $attachment_id, $size, $icon) {
// get a thumbnail or intermediate image if there is one
$image = image_downsize($attachment_id, 'full');
@nczz
nczz / fail2ban-wordpress-filter.conf
Last active May 19, 2020
Fail2Ban 針對 Nginx 伺服器架構下的 WordPress 防護 https://www.mxp.tw/8978/
View fail2ban-wordpress-filter.conf
[Definition]
failregex = ^<HOST>.*POST.*wp-admin/.*HTTP\.*\" (500|503|400|403|404).*
^<HOST>.*POST.*\" (500|503|400|403|404).*
^<HOST>.*POST.*wp-content/.*(php|js|jpg|png).*
^<HOST>.*POST.*wp-include/.*(php|js|jpg|png).*
@nczz
nczz / mxp-google-adsense-management-with-line-notify.php
Last active Apr 26, 2020
[PHP] 串接 AdSense Management API 取得網站廣告收益報表 https://www.mxp.tw/8930/
View mxp-google-adsense-management-with-line-notify.php
<?php
require_once '../vendor/autoload.php';
define('TOKEN_FILENAME', '/PATH/TO/YOUR/TOKENFILE.dat', true);
$client = new Google_Client();
$client->addScope('https://www.googleapis.com/auth/adsense.readonly');
$client->setAccessType('offline');
$client->setApprovalPrompt('force');
$client->setAuthConfig('/PATH/TO/YOUR/client_secrets.json');
$auth = "";