在 WordPress 內寫 Markdown 語法

Markdown 還沒出來之前,要寫一篇部落格教學真的非常麻煩,尤其是要學習 html 語法及如何引用程式碼在文章內,Markdwon 的出現,改變了整個工程師寫 Blog 的習慣,現在不管使用任何網站,沒有支援 Markdwon 語法,真的就不太想留言或發文了。最早以前自己的部落格是用 WP-Markdwon 這套 Plugin,但是這套 Plugin 在整合 SyntaxHighlighter Evolved 的時候根本無法使用,需要特定的語法才可以使用。WP-Markdwon 有個好用的工具那就是 editor tool bar,幫你省下製作 hyperlink 的時間,會自動幫忙編號,如果沒有 SyntaxHighlighter 需求,我個人是推薦用 WP-Markdwon。

[Read More]

將 wordpress 強制使用 SSL 連線

Letsencrypt

繼上篇介紹 Letsencrypt 開放申請免費 SSL 憑證,就把我的 Blog 強制使用 https 連線,Wordpress 強制使用 SSL 連線有幾個步驟需要注意,底下會是搭配 Nginx 相關設定,建議如果有裝任何 Plugin,都先進去後台暫時關閉。Nginx 1.9.5 之後有把 http2 模組加入,所以本篇會是以設定 http2 為主,當然跟 spdy 設定一樣,只是換個名字而已。

[Read More]

PHP 7 vs HHVM Benchmark 比較

php-logo

2015-12-03 PHP 終於釋出 7.0 版本kinsta 工程師馬上寫出一篇 PHP7 vs HHVM 效能比較文章,直接先講結論,就是 HHVM 效能還是大於 PHP 7,所以 kinsta 最終還是採用 HHVM 來 Host WordPress 網站,文章內容都是以 CMS 平台做比較,而不是以各大 Framework 來比較,但是看結果來說,HHVM > PHP7 >> PHP 5,所以建議可以升級到 PHP 7 或者是直接上 HHVM 也可以了。底下是 WordPress benchmark 比較圖。

[Read More]

WordPress plugin 加強網址 SEO

由於網站 SEO 在大家心中都是非常重要,現在製作網站也都考慮了很多 SEO 的問題,其中一個功能就是可不可以自訂網址,Wordpress 很早之前就支援了此功能,站長我呢,在創站的時候使用 blog.wu-boy.com/2011/02/17/2542,為了使搜尋引擎更可以快速找到本站,所以打算將網址改成 blog.wu-boy.com/2011/02/php-codeigniter-google-url-shortener-api-library/,在後台 Permalink Settings 可以自訂部落格網址,將網址格式改成 /%year%/%monthnum%/%postname%/,可是改了之後,之前搜尋引擎及別人引用的網址就會變成 404 NOT Found,為瞭解決此問題,必須寫一支 Mapping Url 程式,讓之前的舊網址轉到新網址,剛好在 Roga Blog 找到一篇 加強部落格的 SEO,提供了轉換的 plugin,底下是該程式碼:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
Plugin Name: roga's url hotfix
Plugin URI: http://blog.roga.tw/2011/02/%E5%8A%A0%E5%BC%B7%E9%83%A8%E8%90%BD%E6%A0%BC%E7%9A%84-seo/
Description: redirect http requests.
Version: 0.1
Author: roga
Author URI: http://blog.roga.tw
License: GPL v2
*/

function roga_wrap()
{
	GLOBAL $wpdb;
	$request_uri = getenv('REQUEST_URI');

	$array = explode('/', $request_uri);

	$status = TRUE;

	foreach($array as $row)
	{
		if( ! is_numeric($row) && ! empty($row)) $status = FALSE;
	}

	if(count($array) != 5 || $status != TRUE)
		return NULL;

	$post_id = (int) $array[4]; // http://blog.roga.tw/2011/02/16/2484

	$wp_result = $wpdb->get_row("SELECT `post_type`, `post_name`, `post_date` FROM `$wpdb->posts` WHERE `ID` = $post_id ");

	if( ! isset($wp_result))
		return NULL;

	$post_type = $wp_result->post_type;
	$post_name = $wp_result->post_name;
	$post_date = $wp_result->post_date;

	if($post_type == 'revision')
		return NULL;

	$time = strtotime($post_date);
	$year = date('Y', $time);
	$month = date('m', $time);
	//  old:   /%year%/%monthnum%/%day%/%post_id%
	//  new:   /%year%/%monthnum%/%postname%/
	$new_request_uri = "/$year/$month/$post_name";
	$http_host = getenv('HTTP_HOST');

	$logfile = WP_CONTENT_DIR . "/cache/wp-roga-redirect.log";
	if(file_exists($logfile))
		file_put_contents($logfile, sprintf("[%s] %s -> %s / %s " . PHP_EOL, date_i18n("Y-m-d H:i:s"), $request_uri, urldecode($new_request_uri), getenv('HTTP_USER_AGENT')), FILE_APPEND);

	header("Status: 301 Moved Permanently");
	header("Location: http:/$http_host$new_request_uri");
	exit();
}

add_action('init', 'roga_wrap');
[Read More]

WordPress 3.0 Release “Thelonious”

WordPress 在6月17日 Release 3.0 版本名稱:Thelonious,官方部落格 WordPress 3.0 “Thelonious”,使用者可以在這裡下載,或者是利用後台方式升級,這次更新了 1,217 bug 修正以及功能增加,可以看底下官方網站影片:

大家可以參考 3.0 版本更

詳細介紹,以及 long list of issues in Trac。感謝 218 位 contributors 為 3.0 的貢獻,目前官方也繼續開始邁向 3.1 的開發。

WordPress 2.8.5 Hardening Release

wordpress logo WordPress 在10月20號發出安全性的更新,大家快把 2.8.4 升級到 2.8.5,可以參考 WordPress 2.8.5: Hardening Release,這次更新最主要是在安全性的議題,Wordpress 團隊在過去幾個月已經開始針對 2.9 進行新功能上的開發,但是在 2.8 branch 的版本如果有安全性的漏洞,官方網站還是會提出修正的,以增加網站的安全。 底下是一些 Release 的安全性改良:

  • A fix for the Trackback Denial-of-Service attack that is currently being seen.
  • Removal of areas within the code where php code in variables was evaluated.
  • Switched the file upload functionality to be whitelisted for all users including Admins.
  • Retiring of the two importers of Tag data from old plugins 假如您的網站最近有受到攻擊,那可以利用官網提供的弱點掃描工具 WordPress Exploit Scanner 來針對網站檔案以及資料庫內容文章,還有 comment 的資料表,以及所裝的 plugin 檔案進行漏洞檢查。 升級方式很容易,可以參考之前寫的 [wordpress] 快速升級 Upgrade 2.5.0 -> 2.5.1 for Linux & FreeBSD ps. FreeBSD commit 到 ports 裡面了,參考:ports/139812

[WordPress] post 文章不能使用 javascript 語法

之前寫了一篇讓 wordpress 可以支援 Google Map API 的教學:[AJAX] google map 的應用,不過我將 WordPress 升級到 WordPress 2.8-bleeding-edge 版本,發現 javascript 語言就不能使用了,因為在寫 javascript 的時候,有利用到
這個 Tag,不過送出後轉出來的 javascript 語言會變成編碼過後," 會變成 ” Big5 編碼,所以這個問題很困擾我,去找一下 ,Wordpress 把斷行完全用 wpautop 這個函式下去取代,所以你只要在內容寫入 <br / > 都會消失,不然就是出現怪問題。 這個問題也不是無解,在網路上找到兩個解法: 1. inline-js - wordpress plugin 您只要在 javascript 語言包一層 tag 就可以了

[Read More]

[wordpress]update 2.6 -> 2.71

好久沒來升級 wordpress,發現升級過後,後台改的還真多阿,升級可以參考 [wordpress] 快速升級 Upgrade 2.5.0 -> 2.5.1 for Linux & FreeBSD,2.7.1 是 2.7 來維護的第一個版本,如果已經是版本 2.7 的話,可以利用後台 Tools->Upgrade menu 來升級,相當方便,不過我是利用 Subversion 的方式,2.7.1 版本修正了 68 tickets,底下可以看到 2.7 版本的畫面: 34680316838 (by appleboy46)

[FreeBSD]Lighttpd + php5 + 解決 wordpress Permalinks mod_write

今天轉換跑道了,最近玩 Apache 玩的很不順,因為只要線上人數一多,就會吃很多記憶體,導致必須重新開 Apache,所以今天來玩看看 lighttpd試試看,看看結果如何,其實轉換到 lighttpd 需要注意很多事情,那就是 Lighttpd 並不支援 .htaccess 檔案,所以 mode_rewrite 功能要設定到 Lighttpd.conf 裡面,然後也去找看看 Lighttpd 的 virtual host 的寫法,然後還有一點就是 wordpress 的 Permalinks 的問題,算是今天都解決了,底下來寫一下作法:

[Read More]