
內容簡介
這個外掛會在文章創建時記錄原始發文者的IP位址。
管理員的文章列表會新增一欄「作者IP」,顯示最初儲存文章者的IP位址。
此外掛無法提供在使用之前已經創建的文章IP位址資訊。
連結: 外掛首頁 | 外掛目錄頁面 | GitHub | 作者首頁
鉤子(Hooks)
此外掛可進一步透過四個過濾器進行自訂。通常,使用過濾器的程式碼應該放置在 mu-plugin 或特定網站的插件中 (這超出了本自述檔案的範圍)。
c2c_show_post_author_ip_column (過濾器)
「c2c_show_post_author_ip_column」過濾器允許您決定在管理文章列表中是否應該出現文章作者的IP欄位。您的鉤子函式可以傳送1個引數:
引數:
$show_column (bool) 是否應顯示欄位?預設為真。
範例:
/**
* 只有管理員才顯示文章作者的 IP 欄位。
*
* @param bool $show_column 是否應顯示欄位?預設為真。
* @return bool
*/
function post_author_ip_column_admin_only( $show ) {
if ( ! current_user_can( 'manage_options' ) ) {
$show = false;
}
return $show;
}
add_filter( 'c2c_show_post_author_ip_column', 'post_author_ip_column_admin_only' );
c2c_get_post_author_ip (過濾器)
「c2c_get_post_author_ip」過濾器允許您自訂作為文章作者IP位址儲存的值。您的鉤子函式可以傳送2個引數:
引數:
$ip (string) 文章作者IP位址。
$post_id (int) 文章ID。
範例:
/**
* 將所有來自本機子網路位址的IP地址視為相同的IP位址。
*
* @param string $ip 文章作者IP位址。
* @param int $post_id 文章ID。
* @return string
*/
function customize_post_author_ip( $ip, $post_id ) {
if ( 0 === strpos( $ip, '192.168.' ) ) {
$ip = '192.168.1.1';
}
return $ip;
}
add_filter( 'c2c_get_post_author_ip', 'customize_post_author_ip', 10, 2 );
c2c_get_current_user_ip (過濾器)
「c2c_get_current_user_ip」過濾器允許您自訂外掛所使用的當前用戶的IP位址。您的鉤子函式可以傳送1個引數:
引數:
$ip (string) 文章作者IP位址。
範例:
/**
* 覆蓋本地主機IP地址。
*
* @param string $ip 文章作者IP位址。
* @param int $post_id 文章ID。
* @return string
*/
function customize_post_author_ip( $ip, $post_id ) {
if ( 0 === strpos( $ip, '192.168.' ) ) {
$ip = '192.168.1.1';
}
return $ip;
}
add_filter( 'c2c_get_post_author_ip', 'customize_post_author_ip', 10, 2 );
c2c_post_author_ip_allowed (過濾器)
「c2c_post_author_ip_allowed」過濾器允許您在每篇文章上決定是否應存儲文章作者IP。您的鉤子函式可以傳送3個引數:
引數:
外掛標籤
開發者團隊
原文外掛簡介
This plugin records the IP address of the original post author when a post first gets created.
The admin listing of posts is amended with a new “Author IP” column that shows the IP address of the author who first saved the post.
The plugin is unable to provide IP address information for posts that were created prior to the use of this plugin.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Hooks
The plugin is further customizable via four filters. Typically, code making use of filters should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain).
c2c_show_post_author_ip_column (filter)
The ‘c2c_show_post_author_ip_column’ filter allows you to determine if the post author IP column should appear in the admin post listing table. Your hooking function can be sent 1 argument:
Argument :
$show_column (bool) Should the column be shown? Default true.
Example:
/**
* Don't show the post author IP column except to admins.
*
* @param bool $show_column Should the column be shown? Default true.
* @return bool
*/
function post_author_ip_column_admin_only( $show ) {
if ( ! current_user_can( 'manage_options' ) ) {
$show = false;
}
return $show;
}
add_filter( 'c2c_show_post_author_ip_column', 'post_author_ip_column_admin_only' );
c2c_get_post_author_ip (filter)
The ‘c2c_get_post_author_ip’ filter allows you to customize the value stored as the post author IP address. Your hooking function can be sent 2 arguments:
Arguments :
$ip (string) The post author IP address.
$post_id (int) The post ID.
Example:
/**
* Store all IP addresses from local subnet IP addresses as the same IP address.
*
* @param string $ip The post author IP address.
* @param int $post_id The post ID.
* @return string
*/
function customize_post_author_ip( $ip, $post_id ) {
if ( 0 === strpos( $ip, '192.168.' ) ) {
$ip = '192.168.1.1';
}
return $ip;
}
add_filter( 'c2c_get_post_author_ip', 'customize_post_author_ip', 10, 2 );
c2c_get_current_user_ip (filter)
The ‘c2c_get_current_user_ip’ filter allows you to customize the current user’s IP address, as used by the plugin. Your hooking function can be sent 1 argument:
Argument :
$ip (string) The post author IP address.
Example:
/**
* Overrides localhost IP address.
*
* @param string $ip The post author IP address.
* @param int $post_id The post ID.
* @return string
*/
function customize_post_author_ip( $ip, $post_id ) {
if ( 0 === strpos( $ip, '192.168.' ) ) {
$ip = '192.168.1.1';
}
return $ip;
}
add_filter( 'c2c_get_post_author_ip', 'customize_post_author_ip', 10, 2 );
c2c_post_author_ip_allowed (filter)
The ‘c2c_post_author_ip_allowed’ filter allows you to determine on a per-post basis if the post author IP should be stored. Your hooking function can be sent 3 arguments:
Arguments :
$allowed (bool) Can post author IP be saved for post? Default true.
$post_id (int) The post ID.
$ip (string) The post author IP address.
Example:
/**
* Don't bother storing localhost IP addresses.
*
* @param bool $allowed Can post author IP be saved for post? Default true.
* @param int $post_id The post ID.
* @param string $ip The post author IP address.
* @return string
*/
function disable_localhost_post_author_ips( $allowed, $post_id, $ip ) {
if ( $allowed && 0 === strpos( $ip, '192.168.' ) ) {
$allowed = false;
}
return $allowed;
}
add_filter( 'c2c_post_author_ip_allowed', 'disable_localhost_post_author_ips', 10, 3 );
