<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:media="http://search.yahoo.com/mrss/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>plugin &#8211; 馬修 IT</title>
	<atom:link href="https://blog.ocam.live/archives/tag/plugin/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.ocam.live</link>
	<description>生活中所接觸各種電腦及網路問題與懷舊模擬器的專業問題解決與新資訊介紹的網站</description>
	<lastBuildDate>Mon, 09 Jun 2025 07:45:06 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.ocam.live/wp-content/uploads/2025/03/cropped-logo-1-300x300.png</url>
	<title>plugin &#8211; 馬修 IT</title>
	<link>https://blog.ocam.live</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress 如何記錄使用者登錄的 IP 跟時間方便未來分析使用</title>
		<link>https://blog.ocam.live/archives/4095</link>
		
		<dc:creator><![CDATA[blog.ocam.live]]></dc:creator>
		<pubDate>Mon, 09 Jun 2025 07:45:02 +0000</pubDate>
				<category><![CDATA[程式設言]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://blog.ocam.live/?p=4095</guid>

					<description><![CDATA[記錄使用者登錄 這簡單的功能 wordpress 隨便都有一堆外掛可用。我這邊介紹的是最簡單方便，不用安裝外掛 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>記錄使用者登錄 這簡單的功能 wordpress 隨便都有一堆外掛可用。我這邊介紹的是最簡單方便，不用安裝外掛單一 function 程式幾乎不影響效能。</p>



<pre class="wp-block-code"><code>&lt;?php

function log_successful_login_info($user_login, $user) {
    // 取得 IP：優先 HTTP_X_FORWARDED_FOR，再用 REMOTE_ADDR
    $ip_raw = $_SERVER&#091;'HTTP_X_FORWARDED_FOR'] ?? $_SERVER&#091;'REMOTE_ADDR'] ?? 'UNKNOWN';
    $ip = explode(',', $ip_raw)&#091;0]; // 若有多個 IP，取第一個

    $time = current_time('mysql'); // WordPress 時區格式

    $log_entry = sprintf(
        "&#091;%s] 使用者：%s | IP：%s\n",
        $time,
        sanitize_text_field($user_login),
        sanitize_text_field($ip)
    );

    $log_file = WP_CONTENT_DIR . '/login_log.txt';
    file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);
}
add_action('wp_login', 'log_successful_login_info', 10, 2);
</code></pre>



<p>把上面的程式貼到子主題的 function.php 裡即可。如未啟用子主題的可在 wp-content\mu-plugins 建立1個 login-logger.php 檔案。然後把下方程式貼進去存檔</p>



<pre class="wp-block-code"><code>&lt;?php
/**
 * Plugin Name: Login Logger
 * Description: 紀錄登入成功的使用者帳號、IP（HTTP_X_FORWARDED_FOR 或 REMOTE_ADDR）與登入時間。
 * Author: Matthew Wang
 */

function log_successful_login_info($user_login, $user) {
    // 取得 IP：優先 HTTP_X_FORWARDED_FOR，再用 REMOTE_ADDR
    $ip_raw = $_SERVER&#091;'HTTP_X_FORWARDED_FOR'] ?? $_SERVER&#091;'REMOTE_ADDR'] ?? 'UNKNOWN';
    $ip = explode(',', $ip_raw)&#091;0]; // 若有多個 IP，取第一個

    $time = current_time('mysql'); // WordPress 時區格式

    $log_entry = sprintf(
        "&#091;%s] 使用者：%s | IP：%s\n",
        $time,
        sanitize_text_field($user_login),
        sanitize_text_field($ip)
    );

    $log_file = WP_CONTENT_DIR . '/login_log.txt';
    file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);
}
add_action('wp_login', 'log_successful_login_info', 10, 2);
</code></pre>



<p>由於文字檔是寫在 wp-content 裡。這邊建議在 .htaccess 加上下方程式阻擋由 web 讀取</p>



<pre class="wp-block-code"><code>&lt;Files login_log.txt>
order deny,allow
deny from all
&lt;/Files></code></pre>


<div class="wp-block-stackable-heading stk-block-heading stk-block-heading--v2 stk-block stk-7280d78" id="x-68000-games-supporting" data-block-id="7280d78"><h2 class="stk-block-heading__text">延伸閱讀</h2></div><div class="reading-grid"><a href="https://blog.ocam.live/archives/4729" class="card">
      <img fetchpriority="high" decoding="async" width="300" height="300" src="https://blog.ocam.live/wp-content/uploads/2025/12/Bingbot-is-spamming-my-site-300x300.png" class="attachment-thumbnail size-thumbnail" alt="Bingbot is spamming my site" title="Wordpress 如何記錄使用者登錄的 IP 跟時間方便未來分析使用">
      <div class="card-content">
        <div class="card-title">為什麼 Bingbot 一直用隨機搜尋字詞來灌爆 WordPress 網站</div>
      </div>
		</a><a href="https://blog.ocam.live/archives/4035" class="card">
      <img decoding="async" width="300" height="300" src="https://blog.ocam.live/wp-content/uploads/2025/05/Custom-Simple-Rss-300x300.jpg" class="attachment-thumbnail size-thumbnail" alt="Custom Simple Rss" title="Wordpress 如何記錄使用者登錄的 IP 跟時間方便未來分析使用">
      <div class="card-content">
        <div class="card-title">WordPress 外掛介紹：Custom Simple Rss</div>
      </div>
		</a><a href="https://blog.ocam.live/archives/4860" class="card">
      <img decoding="async" width="300" height="300" src="https://blog.ocam.live/wp-content/uploads/2026/02/dq3_ai-300x300.png" class="attachment-thumbnail size-thumbnail" alt="dq3 ai" title="Wordpress 如何記錄使用者登錄的 IP 跟時間方便未來分析使用">
      <div class="card-content">
        <div class="card-title">RetroArch &#8211; 使用 Gemini AI 即時翻譯懷舊遊戲</div>
      </div>
		</a></div></ul>



<p></p>
]]></content:encoded>
					
		
		
		<media:content url="https://blog.ocam.live/wp-content/uploads/2025/06/WordPress-Login-Log.jpg" medium="image"></media:content>
            	</item>
		<item>
		<title>用 ChatGPT 4o 寫 WordPress 外掛</title>
		<link>https://blog.ocam.live/archives/3908</link>
		
		<dc:creator><![CDATA[blog.ocam.live]]></dc:creator>
		<pubDate>Thu, 08 May 2025 00:36:00 +0000</pubDate>
				<category><![CDATA[程式設言]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://blog.ocam.live/?p=3908</guid>

					<description><![CDATA[用 ChatGPT 能快速產生 WordPress 外掛的基本結構（英文 skeleton ）省去重複性工作， [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>用 ChatGPT 能快速產生 WordPress 外掛的基本結構（英文 skeleton ）省去重複性工作，讓你專注於邏輯和功能設計。這篇文章會給你一個基本的提示詞只要貼上 chatGPT 即可產快外掛原始碼</p>



<div class="wp-block-rank-math-toc-block" id="rank-math-toc"><h2>文章大綱</h2><nav><ul><li class=""><a href="#提示詞">提示詞</a></li><li class=""><a href="#解釋">解釋</a></li><li class=""><a href="#chat-gpt-產出">ChatGPT 產出</a></li><li class=""><a href="#composer-說明">Composer 說明</a></li><li class=""><a href="#結果畫面">結果畫面</a></li></ul></nav></div>



<h2 class="wp-block-heading" id="提示詞">提示詞</h2>



<pre class="wp-block-code"><code>Build a WordPress plugin named ocam_related_post that uses Carbon Fields to create a Theme Options Page in the WordPress admin dashboard. The plugin should include three select fields:

1.Number Range – A select field with numeric options from 1 to 10.

2.Sort Order – A select field with the following options:

rand → Random Text

desc → Descending Text

asc → Ascending Text

3.Type Filter – A select field with the following options:

category → Text Category

tag → Text Tag

Ensure that Carbon Fields is properly initialized within the plugin, and the options page appears under Theme Options in the admin menu.</code></pre>



<h2 class="wp-block-heading" id="解釋">解釋</h2>



<p>Carbon Fields：是 1 個原件能夠讓你快速的產出你要的欄位。</p>



<p>fields：欄位。因為 Carbon Fields 提供十數種不同的欄位選項。這邊得給 GPT 說明你要的欄位跟定義為何。範例中我選了 3 種。1：select  。值可由 1 到 10 個選項。2：也是 select 。值其 3 種。3：也是 select 值有 3 種。通常欄位的值跟你寫的程式有絕對的關係在使用提示詞前必需事先想好。</p>



<h2 class="wp-block-heading" id="chat-gpt-產出">ChatGPT 產出</h2>



<pre class="wp-block-code"><code>&lt;?php
/**
 * Plugin Name: Ocam Related Post
 * Description: Adds a theme options page with select fields using Carbon Fields.
 * Version: 1.0
 * Author: Your Name
 */

use Carbon_Fields\Container;
use Carbon_Fields\Field;

defined('ABSPATH') || exit;

// Load Carbon Fields
add_action('after_setup_theme', function() {
    require_once plugin_dir_path(__FILE__) . '/vendor/autoload.php';
    \Carbon_Fields\Carbon_Fields::boot();
});

// Register the theme options
add_action('carbon_fields_register_fields', function() {
    Container::make('theme_options', __('Ocam Related Post Options', 'ocam_related_post'))
        -&gt;set_icon('dashicons-admin-generic')
        -&gt;add_fields(&#091;
            Field::make('select', 'ocam_number_range', __('Number Range'))
                -&gt;set_options(array_combine(range(1, 10), range(1, 10)))
                -&gt;set_default_value(5),

            Field::make('select', 'ocam_sort_order', __('Sort Order'))
                -&gt;set_options(&#091;
                    'rand' =&gt; 'Random Text',
                    'desc' =&gt; 'Descending Text',
                    'asc' =&gt; 'Ascending Text',
                ])
                -&gt;set_default_value('rand'),

            Field::make('select', 'ocam_type_filter', __('Type Filter'))
                -&gt;set_options(&#091;
                    'category' =&gt; 'Text Category',
                    'tag' =&gt; 'Text Tag',
                ])
                -&gt;set_default_value('category'),
        ]);
});
</code></pre>



<pre class="wp-block-code"><code>composer require htmlburger/carbon-fields</code></pre>



<h2 class="wp-block-heading" id="composer-說明">Composer 說明</h2>



<p>這段程式必需要在上傳外掛的目錄上執行。要事先安裝 carbon-fields library 才可啟用外掛。因為程式的欄位建立都是靠這個 library 。</p>



<h2 class="wp-block-heading" id="結果畫面">結果畫面</h2>



<figure class="wp-block-image size-large"><img decoding="async" src="https://blog.ocam.live/wp-content/uploads/2025/05/chatgpt_plugin-1024x274.png" alt="Wordpress 外掛 screen shot" class="wp-image-3910" title="用 ChatGPT 4o 寫 Wordpress 外掛"></figure>



<p>要取得參數可用 carbon_get_theme_option 來取得。如 </p>



<pre class="wp-block-code"><code>carbon_get_theme_option('ocam_number_range')</code></pre>



<p>這也只是後台畫面骨架。但實際的程式流程你也可自已整合或另開 chatgpt 詢問，之後再自已整合兩邊程式。當然你也可再修改提示詞把你要的功能全部寫好。</p>



<p><a href="https://carbonfields.net/" target="_blank" rel="noopener">Carbon Fields 官網</a></p>


<div class="wp-block-stackable-heading stk-block-heading stk-block-heading--v2 stk-block stk-7280d78" id="x-68000-games-supporting" data-block-id="7280d78"><h2 class="stk-block-heading__text">延伸閱讀</h2></div><div class="reading-grid"><a href="https://blog.ocam.live/archives/4040" class="card">
      <img loading="lazy" decoding="async" width="300" height="300" src="https://blog.ocam.live/wp-content/uploads/2025/05/duck-dns-300x300.webp" class="attachment-thumbnail size-thumbnail" alt="Duck DNS feature image" title="用 ChatGPT 4o 寫 Wordpress 外掛">
      <div class="card-content">
        <div class="card-title">免費的 DDNS Duck DNS 簡單快速設定方式</div>
      </div>
		</a><a href="https://blog.ocam.live/archives/3863" class="card">
      <img loading="lazy" decoding="async" width="150" height="150" src="https://blog.ocam.live/wp-content/uploads/2025/04/ASF_Logo.svg-150x150.png" class="attachment-thumbnail size-thumbnail" alt="apache logo" title="用 ChatGPT 4o 寫 Wordpress 外掛">
      <div class="card-content">
        <div class="card-title">如何簡單用 apache 的 htaccess 來防止非特定 ip 安裝主題跟外掛跟防止登入</div>
      </div>
		</a><a href="https://blog.ocam.live/archives/4095" class="card">
      <img loading="lazy" decoding="async" width="300" height="300" src="https://blog.ocam.live/wp-content/uploads/2025/06/WordPress-Login-Log-300x300.jpg" class="attachment-thumbnail size-thumbnail" alt="WordPress Login Log" title="用 ChatGPT 4o 寫 Wordpress 外掛">
      <div class="card-content">
        <div class="card-title">WordPress 如何記錄使用者登錄的 IP 跟時間方便未來分析使用</div>
      </div>
		</a></div></ul>
]]></content:encoded>
					
		
		
		<media:content url="https://blog.ocam.live/wp-content/uploads/2025/05/chatgpt_build_a_wordpress_plugin.jpg" medium="image"></media:content>
            	</item>
	</channel>
</rss>
