- users
- ID
- user_login
- user_pass
- user_nicename
- user_email
- user_url
- user_registered
- display_name
- user_meta
- first_name
- last_name
- nickname
- description
- wp_capabilities (array)
- admin_color (Theme of your admin page. Default is fresh.)
- closedpostboxes_page
- primary_blog
- rich_editing
- source_domain
星期三, 8月 31, 2016
[Wordpress] wp_users 與 wp_usermeta tables取值的key
記錄一下常用到get_userdata與get_user_meta常要用取值key的值!!!
星期一, 8月 29, 2016
[MySQL] 如何判斷要插入新資料還是更新
今天要算一下統計表格需要的sql,如果資料已存在就要更新,反之就插入一筆,記錄一下。
Step1: 未設unique key是會失敗的
ALTER TABLE 你的表格名 ADD UNIQUE (要UNIQUE的欄位)
Step2:
INSERT ... ON DUPLICATE KEY UPDATE:
http://stackoverflow.com/questions/14383503/on-duplicate-key-update-same-as-insert
Step1: 未設unique key是會失敗的
ALTER TABLE 你的表格名 ADD UNIQUE (要UNIQUE的欄位)
Step2:
INSERT ... ON DUPLICATE KEY UPDATE:
http://stackoverflow.com/questions/14383503/on-duplicate-key-update-same-as-insert
星期四, 8月 18, 2016
[Wordpress] sql查詢特色圖片(featured images)
如果要查詢縮圖的資訊直接查詢postmeta這張表的_wp_attached_file這個meta_key即可。文章縮圖的id則為_thumbnail_id
[Wordpress] 使用自訂的sql抓取WMPL翻譯的文章類型
記錄如何自已下sql取得文章的多國類型,裝的外掛為WMPL。
請注意WMPL此外掛是將翻譯的關連資訊存到mywp_icl_translations
select
posts.ID,
posts.post_name,
posts.post_date,
IFNULL((SELECT PM.meta_value FROM mywp_postmeta AS PM WHERE posts.ID = PM.post_id AND PM.meta_key = "your_post_type"),'') as link,
IFNULL((SELECT PM.meta_value FROM mywp_postmeta AS PM WHERE posts.ID = PM.post_id AND PM.meta_key = "_thumbnail_id"),'') as thumbnail_id
FROM mywp_posts AS posts
where
post_status = 'publish'
AND
post_type = 'emel_ad_slider'
AND
ID
IN
(
select element_id from mywp_icl_translations
where element_type = 'post_your_post_type' and language_code = 'zh-hans'
)
order by posts.post_date desc
請注意WMPL此外掛是將翻譯的關連資訊存到mywp_icl_translations
以下為sql語句
select
posts.ID,
posts.post_name,
posts.post_date,
IFNULL((SELECT PM.meta_value FROM mywp_postmeta AS PM WHERE posts.ID = PM.post_id AND PM.meta_key = "your_post_type"),'') as link,
IFNULL((SELECT PM.meta_value FROM mywp_postmeta AS PM WHERE posts.ID = PM.post_id AND PM.meta_key = "_thumbnail_id"),'') as thumbnail_id
FROM mywp_posts AS posts
where
post_status = 'publish'
AND
post_type = 'emel_ad_slider'
AND
ID
IN
(
select element_id from mywp_icl_translations
where element_type = 'post_your_post_type' and language_code = 'zh-hans'
)
order by posts.post_date desc
星期日, 8月 14, 2016
[Paypal] paypal direct payment 直接使用信用卡付款
測試paypal direct payment api的筆記過程。
簡介Website Payments Pro
https://developer.paypal.com/docs/classic/paypal-payments-pro/integration-guide/WPWebsitePaymentsPro/
Website Payments Pro 解決方案
https://developer.paypal.com/docs/classic/products/website-payments-pro/
在Website Payments Pro這一包的產品下,裡面包含以下的整合技術
在Website Payments Pro這一包的產品下,裡面包含以下的整合技術
Direct Payment, Express Checkout, and additional PayPal solutions and tools — like Virtual Terminal, Fraud Management Filters, and reference transactions.
簡介Website Payments Pro
https://developer.paypal.com/docs/classic/paypal-payments-pro/integration-guide/WPWebsitePaymentsPro/
星期一, 8月 08, 2016
[Wordpress] WooCommerce 自訂頁面呼叫相關API
今天要在自訂的php頁面呼叫wc的api記錄,因為老闆說要另外做一頁就這樣搞了XD不要問
載入WP的函式庫
require_once(dirname(dirname(__FILE__)).'/wp-load.php');
星期日, 8月 07, 2016
[Wordpress] 取出指定user meta值的用戶清單
這次想要在wordpress的帳號管理的查詢功能新增自已的user meta key查詢。
使用到的Hook分別為如下:
- restrict_manage_users ACTION:
這個Action可以替users表格上面的filter區塊自訂我們要的html 語法,這次要做的效果一樣弄一個下拉式選單就OK了。送出後你會發現網址QueryString會加了我們指定的值
// Adds a dropdown to filter users based on a meta field
function add_recommand_filter_into_user_table() {
global $pagenow;
if (is_admin() && $pagenow == 'users.php') {
$optNone = '';
$optYes = '';
$optNo = '';
if(isset($_GET['recommand'])){
if(strcmp($_GET['recommand'],'1') == 0){
$optYes = 'selected="selected"';
}else{
$optNo = 'selected="selected"';
}
}else{
$optNone = 'selected="selected"';
}
echo '';
}
}
add_action('restrict_manage_users', 'add_recommand_filter_into_user_table');
- pre_get_users FILTER:
這個Filter簡言之就是要處理我們新增的action所送出的值為何,然後可以重改變動query物件的meta參數
// Updates user query based on filtering criteria
function query_recommand_query_from_user_table($query) {
global $pagenow;
if (is_admin() && $pagenow == 'users.php' && isset($_GET['recommand'])) {
$recommandValue = wp_strip_all_tags($_GET['recommand']);
if(strcmp($recommandValue,'') != 0){
$meta_query = array(
array(
'key' => RECOMMAND_KEY,
'value' => $recommandValue
)
);
$query->set('meta_key', RECOMMAND_KEY);
$query->set('meta_query', $meta_query);
}
}
}
add_filter('pre_get_users','query_recommand_query_from_user_table');
參考
- http://wordpress.stackexchange.com/questions/189077/how-to-get-users-by-a-custom-field-by-user-meta-data
- http://www.davemccourt.com/wp-user-filtering/
星期四, 8月 04, 2016
[jQuery] 滿版的Dialog外掛
效果不錯的滿版型動畫Modal外掛,留著以後參考。
http://joaopereirawd.github.io/animatedModal.js/
http://joaopereirawd.github.io/animatedModal.js/
官方demo
http://joaopereirawd.github.io/animatedModal.js/http://joaopereirawd.github.io/animatedModal.js/
星期三, 8月 03, 2016
[jQuery] 偵測元素是否進入到viewpoint外掛
今天想要處理偵測用戶scroll的位置判斷是否有進入指定元素viewpoint的議題。
找到以下三個jQuery外掛
http://imakewebthings.com/waypoints/guides/getting-started/
https://github.com/protonet/jquery.inview
https://github.com/morr/jquery.appear
比較過後,暫時先用inview即可解決,
其他二個外掛有比inview強的地方就是增加了offset的參數可設定。
不過inview有pull-request已解決這個功能
找到以下三個jQuery外掛
http://imakewebthings.com/waypoints/guides/getting-started/
https://github.com/protonet/jquery.inview
https://github.com/morr/jquery.appear
比較過後,暫時先用inview即可解決,
其他二個外掛有比inview強的地方就是增加了offset的參數可設定。
不過inview有pull-request已解決這個功能
星期一, 8月 01, 2016
[Wordpress] 擴充User management 的表格欄位
如果你想要自已擴充全部帳號(users.php)頁面,只需要透過二個hook機制就可以快速完成。
所以你就可以自已加欄位加按鈕,做更多客製化操作啦。
所以你就可以自已加欄位加按鈕,做更多客製化操作啦。
- 使用filter hook: manage_users_columns來擴充欄位
- 使用action hook: manage_users_custom_column來修改欄位值
範例
參考
https://www.tipsandtricks-hq.com/adding-a-custom-column-to-the-users-table-in-wordpress-7378[Wordpress] 如何ajax來呼叫 php function
記錄一下如何在wp操作ajax function呼叫php function,意思就是你可以透過hook機制寫自已的api嚕
在頁面render一個jquery的方法(因為是範例所以方法很簡單,page_load之後就打)可以搭配admin_enqueue_scripts來整理你自已外掛所需的js
官網的sample說明
- action命名規則wp_ajax_[你的方法]
- action function 命名規則 [你的方法]_callback
tips: 請注意你的方法命名不可以長的不一樣,會無法對應呼叫
add_action( 'wp_ajax_my_action', 'my_action_callback' );
function my_action_callback() {
global $wpdb; // this is how you get access to the database
$whatever = intval( $_POST['whatever'] );
$whatever += 10;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
在頁面render一個jquery的方法(因為是範例所以方法很簡單,page_load之後就打)可以搭配admin_enqueue_scripts來整理你自已外掛所需的js jQuery(document).ready(function($) {
var data = {
'action': 'my_action',
'whatever': 1234
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
參考
https://codex.wordpress.org/AJAX_in_Plugins[Wordpress] wp_enqueue_script / wp_enqueue_style 在wp自訂你的js與css檔
wp_enqueue_script 允許我們快速的在wp的頁面加入js函式庫,
反之 wp_enqueue_style讓我們加入樣式檔。
你可以寫法functions.php做全域的載入或至到外掛模組與佈景主題裡面做客製化的載入唷
反之 wp_enqueue_style讓我們加入樣式檔。
你可以寫法functions.php做全域的載入或至到外掛模組與佈景主題裡面做客製化的載入唷
範例
以下範例教你怎麼加入bootstrap框架function reg_scripts() {
wp_enqueue_style( 'bootstrapstyle', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'bootstrapthemestyle', get_template_directory_uri() . '/css/bootstrap-theme.min.css' );
wp_enqueue_script( 'bootstrap-script', get_template_directory_uri() . '/js/bootstrap.min.js', array(), true );
}
add_action('wp_enqueue_scripts', 'reg_scripts');
參考
- https://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/
- http://stackoverflow.com/questions/26583978/how-to-load-bootstrap-script-and-style-in-functions-php-wordpress
- https://codex.wordpress.org/zh-cn:%E5%87%BD%E6%95%B0%E5%8F%82%E8%80%83/wp_enqueue_script
星期四, 7月 28, 2016
[GIT] 分支更新至master最新版本的處理方法筆記
常常遇到branch開工到一半遇到要更新master上面的code,
找了一些Stackoverflow上面的方法來研究看看:
git checkout develop
git merge master
找了一些Stackoverflow上面的方法來研究看看:
Merge
git checkout develop
git merge master
Cheey-Pick
Rebase
參考
[jQuery] 視差滾動元件: scrollme 簡單、快速、好上手
最近在做某個網站使用視差效果,原來使用stellar.js,
但網頁滾動起來發生很卡的現像,非常不平滑。
於是又找了到 scrollme這個元件,由於我們的目的可以針對元件某些元素進行一些特效,
加上scrollme的效能非常的平滑,使用語意也超級簡單(連教學都不用寫了XD),所以推給大家使用。
http://scrollme.nckprsn.com/
星期三, 7月 27, 2016
[Linux] 常用的一些Server狀態指令
記錄一下Server常用指令集
linux基礎的檔案目錄說明
| 目錄名稱 | 說明 | 例 |
| bin | 系統的一些重要執行檔 | Kill、cp、df |
| boot | 系統開機的一些載入檔 | |
| cdrom | 光碟機裡的資料被掛上來的地方 | |
| dosc | 開機時把dos檔案系統掛上來的地方 | |
| etc | 系統設定檔 | |
| home | 使用者的自家目錄所在、ftp server | |
| lib | 基本函數庫 | |
| Lost+found | 系統檢查結果 | |
| mnt | 可以掛上其它檔案系統 | |
| proc | 整個系統運作資訊 | |
| root | 系統管理者的自家目錄所在 | |
| sbin | 一些設定的可執行程式、設定網路 | |
| tmp | 雜七雜八的東西 | |
| usr | 應用程式 | X-window |
| var | 記載著各種系統上的變數的地方 | |
| vmlinuz | 系統核心檔案 |
星期一, 7月 25, 2016
[MAMP] 手動變更php版本
如果想要自行變動php版本的話,可以下載php版本後
放置以下目錄
再修正httpd.conf
sudo vim /Applications/MAMP/conf/apache/httpd.conf
開啟後再修正版本模組即可
放置以下目錄
再修正httpd.conf
sudo vim /Applications/MAMP/conf/apache/httpd.conf
開啟後再修正版本模組即可
#LoadModule php5_module /Applications/MAMP/bin/php/php5.6.10/modules/libphp5.so
#你想要的版本
LoadModule php5_module /Applications/MAMP/bin/php/php5.6.24/modules/libphp5.so
[MAMP] Mac的php版本改用MAMP的php版本的方法
直接用MAMP來取代mac原本裝裝php5版本,
請參考下面流程,請注意MAMP_PHP改為你要使用的版本號即可
http://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp-path
請參考下面流程,請注意MAMP_PHP改為你要使用的版本號即可
open terminal, type
touch ~/.bash_profile; open ~/.bash_profile
edit as follows below, save, quite and restart terminal or alternately
source ~/.bash_profile
to execute new PATH without restarting terminal
and in the fashion of the DavidYell's post above, also add the following. You can stack various variables by exporting them followed by a single PATH export which I demonstrated below
export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.10/bin
export MAMP_BINS=/Applications/MAMP/Library/bin
export USERBINS=~/bins
export PATH="$USERBINS:$MAMP_PHP:$MAMP_BINS:$PATH"
星期六, 6月 25, 2016
[Javascript] 在網頁畫線的方法蒐集
星期四, 6月 23, 2016
[php] 用命令提示字元檢查語法是否有誤
今天寫物件發生一些sytax錯誤,
開了display_errors, error_reporting都沒什麼錯誤印出來。
於是直接使用cmd line語法檢查..
開了display_errors, error_reporting都沒什麼錯誤印出來。
於是直接使用cmd line語法檢查..
php -l UserScoreGradeDAO.class.php
No syntax errors detected in UserScoreGradeDAO.class.php
就會告訴你錯在哪一行了,真的方便多了。
訂閱:
意見 (Atom)




