{"id":12366113,"date":"2026-03-13T17:18:48","date_gmt":"2026-03-13T09:18:48","guid":{"rendered":"https:\/\/www.likacloud.com\/knowledge\/%e6%b7%b1%e5%85%a5%e6%b5%85%e5%87%bawordpress%e6%8f%92%e4%bb%b6%e5%bc%80%e5%8f%91%ef%bc%9a%e4%bb%8e%e9%9b%b6%e5%bc%80%e5%a7%8b%e6%9e%84%e5%bb%ba%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aa%e8%87%aa\/"},"modified":"2026-06-03T21:20:30","modified_gmt":"2026-06-03T13:20:30","slug":"wordpress-plugin-development-tutorial-custom-plugin-from-scratch","status":"publish","type":"knowledge_post","link":"https:\/\/www.likacloud.com\/ja\/knowledge\/wordpress\/wordpress-plugin-development-tutorial-custom-plugin-from-scratch\/","title":{"rendered":"\u5fb9\u5e95\u7684\u306aWordPress\u30d7\u30e9\u30b0\u30a4\u30f3\u958b\u767a\uff1a\u6700\u521d\u306e\u30ab\u30b9\u30bf\u30e0\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u30bc\u30ed\u304b\u3089\u4f5c\u308b"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">WordPress\u63d2\u4ef6\u57fa\u7840\u4e0e\u5f00\u53d1\u73af\u5883<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u7406\u89e3WordPress\u63d2\u4ef6\u7684\u57fa\u672c\u6982\u5ff5\u5e76\u642d\u5efa\u5408\u9002\u7684\u5f00\u53d1\u73af\u5883\u81f3\u5173\u91cd\u8981\u3002\u4e00\u4e2aWordPress\u63d2\u4ef6\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5305\u542bPHP\u4ee3\u7801\u7684\u6587\u4ef6\u5939\uff0c\u5b83\u901a\u8fc7WordPress\u63d0\u4f9b\u7684\u4e30\u5bccAPI\u6765\u6269\u5c55\u6838\u5fc3\u529f\u80fd\u3002\u63d2\u4ef6\u53ef\u4ee5\u5c0f\u5230\u53ea\u6dfb\u52a0\u4e00\u4e2a\u77ed\u4ee3\u7801\uff0c\u5927\u5230\u6784\u5efa\u4e00\u4e2a\u5b8c\u6574\u7684\u7ba1\u7406\u7cfb\u7edf\u3002\u5176\u6838\u5fc3\u601d\u60f3\u662f\u201c\u4e0d\u4fee\u6539\u6838\u5fc3\u4ee3\u7801\u201d\uff0c\u8fd9\u4fdd\u8bc1\u4e86WordPress\u5347\u7ea7\u65f6\u4f60\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u9ad8\u6548\u5f00\u53d1\uff0c\u4f60\u9700\u8981\u4e00\u4e2a\u672c\u5730\u5f00\u53d1\u73af\u5883\u3002\u53ef\u4ee5\u4f7f\u7528XAMPP\u3001MAMP\u3001Local by Flywheel\u6216Docker\u7b49\u5de5\u5177\u5feb\u901f\u642d\u5efa\u4e00\u4e2a\u5305\u542bPHP\u548cMySQL\u7684\u670d\u52a1\u5668\u3002\u7136\u540e\uff0c\u5b89\u88c5\u4e00\u4e2a\u6700\u65b0\u7684WordPress\u5b9e\u4f8b\u3002\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5efa\u8bae\u5728<code>wp-config.php<\/code>\u6587\u4ef6\u4e2d\u542f\u7528<code>WP_DEBUG<\/code>\uff0c\u4ee5\u4fbf\u53ca\u65f6\u66b4\u9732\u9519\u8bef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d2\u4ef6\u7684\u201c\u5fc3\u810f\u201d\u662f\u4e00\u4e2a\u4e3bPHP\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u7684\u5934\u90e8\u6ce8\u91ca\u662f\u5b83\u7684\u8eab\u4efd\u8bc1\uff0cWordPress\u901a\u8fc7\u8bfb\u53d6\u8fd9\u4e9b\u5143\u4fe1\u606f\u6765\u5728\u540e\u53f0\u8bc6\u522b\u548c\u7ba1\u7406\u63d2\u4ef6\u3002\u4e00\u4e2a\u6807\u51c6\u7684\u63d2\u4ef6\u4e3b\u6587\u4ef6\u5934\u90e8\u6ce8\u91ca\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/en\/knowledge\/wordpress\/what-is-a-wordpress-theme\/\">\u4ec0\u4e48\u662f WordPress \u4e3b\u9898<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">&lt;?php\n\/**\n * Plugin Name: \u6211\u7684\u7b2c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u63d2\u4ef6\n * Plugin URI:  https:\/\/example.com\/my-first-plugin\n * Description: \u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u5b66\u4e60\u63d2\u4ef6\u5f00\u53d1\u7684\u7b80\u5355\u63d2\u4ef6\uff0c\u5b83\u5c06\u5728\u6587\u7ae0\u672b\u5c3e\u6dfb\u52a0\u81ea\u5b9a\u4e49\u5185\u5bb9\u3002\n * Version:     1.0.0\n * Author:      \u5f00\u53d1\u8005\u540d\u79f0\n * License:     GPL v2 or later\n * Text Domain: my-first-plugin\n *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u521b\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u529f\u80fd\u63d2\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u4ece\u4e00\u4e2a\u5b9e\u9645\u7684\u529f\u80fd\u5f00\u59cb\uff1a\u5728\u7f51\u7ad9\u7684\u6bcf\u7bc7\u6587\u7ae0\u5185\u5bb9\u672b\u5c3e\u81ea\u52a8\u6dfb\u52a0\u4e00\u6bb5\u81ea\u5b9a\u4e49\u6587\u672c\u3002\u8fd9\u4e2a\u4f8b\u5b50\u5c06\u8d2f\u7a7f\u63d2\u4ef6\u5f00\u53d1\u7684\u6838\u5fc3\u6d41\u7a0b\u3002<\/p>\n<!-- AUTO_SYNCED_PATTERN_INSERT_START -->\n\r\n<div class=\"flex justify-between items-center flex-col lg:flex-row xl:flex-col 2xl:flex-row gap-6 sm:gap-8 rounded-lg border border-gray-200 dark:border-gray-700 p-4 mb-8 lg:mb-10 sm:p-6 bg-white dark:bg-gray-750 shadow-md transition-colors duration-300\"\r\n     data-link=\"https:\/\/www.likacloud.com\/ja\/tolink\/ultahost-wordpress-hosting\/\">\r\n     \r\n  <div class=\"flex flex-col gap-3 gap-4 sm:gap-6 w-full\">\r\n    <strong class=\"text-2xl font-semibold text-gray-900 dark:text-gray-200\">\r\n      UltaHost WordPress \u4e3b\u673a    <\/strong>\r\n    <div class=\"text-gray-600 dark:text-gray-300 word-word\">30\u5929\u9000\u6b3e\u4fdd\u8bc1\uff0c\u65e0\u9650\u5e26\u5bbd\u4e0e\u6570\u636e\u5e93\uff0c\u514d\u8d39\u7684 DDoS \u9632\u62a4\uff0c\u8d2d\u4e703\u5e74\u4f18\u60e050%<\/div>\r\n  <\/div>\r\n\r\n  <div class=\"flex items-center flex-col md:flex-row lg:flex-col xl:flex-row 2xl:flex-col gap-6 shrink-0\">\r\n          <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/ultahost-wordpress-hosting\/\">\r\n                  <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/12\/20251227020448.webp\" alt=\"UltaHost LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 dark:hidden\" title=\"\">\r\n          <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/12\/20251229052118.webp\" alt=\"UltaHost LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 hidden dark:block\" title=\"\">\r\n              <\/a>\r\n    \r\n    <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/ultahost-wordpress-hosting\/\"\r\n       class=\"bg-blue-500 w-full md:w-auto lg:w-full xl:w-auto 2xl:w-full text-center !text-white dark:!text-gray-200 !px-5 !py-1.5 rounded-full hover:bg-blue-600 transition-colors\">\r\n       \u8bbf\u95ee\u9875\u9762    <\/a>\r\n  <\/div>\r\n<\/div>\n<!-- AUTO_SYNCED_PATTERN_INSERT_END -->\n\n\n\n\n\n<h3 class=\"wp-block-heading\">\u63d2\u4ef6\u4e3b\u6587\u4ef6\u4e0e\u521d\u59cb\u5316<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5728WordPress\u7684<code>wp-content\/plugins<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u5939\uff0c\u4f8b\u5982<code>my-first-plugin<\/code>\u3002\u5728\u8be5\u6587\u4ef6\u5939\u5185\uff0c\u521b\u5efa\u4e3bPHP\u6587\u4ef6\uff0c\u53ef\u4ee5\u547d\u540d\u4e3a<code>my-first-plugin.php<\/code>\u3002\u5c06\u4e0a\u9762\u7684\u5934\u90e8\u6ce8\u91ca\u4ee3\u7801\u590d\u5236\u8fdb\u53bb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u5b89\u5168\u7684\u65b9\u5f0f\u6765\u6267\u884c\u63d2\u4ef6\u7684\u521d\u59cb\u5316\u4ee3\u7801\u3002\u6700\u4f73\u5b9e\u8df5\u662f\u5c06\u6240\u6709\u529f\u80fd\u5305\u88c5\u5728\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u547d\u540d\u7a7a\u95f4\u51fd\u6570\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u7c7b\u6765\u7ec4\u7ec7\u4ee3\u7801\u3002\u5728\u4e3b\u6587\u4ef6\u4e2d\u5934\u90e8\u6ce8\u91ca\u4e4b\u540e\uff0c\u6dfb\u52a0\u5982\u4e0b\u7c7b\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">if ( ! defined( &#039;ABSPATH&#039; ) ) {\n\texit; \/\/ \u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\u6587\u4ef6\n}\n\nclass My_First_Plugin {\n    public function __construct() {\n        \/\/ \u6784\u9020\u51fd\u6570\uff0c\u5728\u8fd9\u91cc\u6302\u8f7d\u94a9\u5b50\n    }\n}\n\n\/\/ \u521d\u59cb\u5316\u63d2\u4ef6\nnew My_First_Plugin();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>if ( ! defined( \u2018ABSPATH\u2019 ) )<\/code>\u8fd9\u884c\u4ee3\u7801\u662fWordPress\u63d2\u4ef6\u5f00\u53d1\u7684\u5b89\u5168\u6807\u51c6\uff0c\u7528\u4e8e\u9632\u6b62\u7528\u6237\u76f4\u63a5\u901a\u8fc7URL\u8bbf\u95ee\u4f60\u7684\u63d2\u4ef6\u6587\u4ef6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u94a9\u5b50\u6dfb\u52a0\u6587\u7ae0\u9875\u811a\u5185\u5bb9<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress\u7684\u63d2\u4ef6\u67b6\u6784\u5efa\u7acb\u5728\u201c\u94a9\u5b50\u201d\uff08Hooks\uff09\u7cfb\u7edf\u4e4b\u4e0a\uff0c\u5206\u4e3a\u52a8\u4f5c\uff08Action\uff09\u548c\u8fc7\u6ee4\u5668\uff08Filter\uff09\u3002\u52a8\u4f5c\u5141\u8bb8\u4f60\u5728\u7279\u5b9a\u65f6\u523b\u6267\u884c\u4ee3\u7801\uff0c\u800c\u8fc7\u6ee4\u5668\u5141\u8bb8\u4f60\u4fee\u6539\u6570\u636e\u3002<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/en\/knowledge\/wordpress\/wordpress-website-performance-optimization-ultimate-guide\/\">WordPress \u7f51\u7ad9\u6027\u80fd\u4f18\u5316\u7ec8\u6781\u6307\u5357\uff1a\u4ece\u57fa\u7840\u914d\u7f6e\u5230\u7f13\u5b58\u63d2\u4ef6\u5168\u89e3\u6790<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u7684\u76ee\u6807\u662f\u5728\u6587\u7ae0\u5185\u5bb9\u540e\u6dfb\u52a0\u6587\u672c\uff0c\u8fd9\u662f\u4e00\u4e2a\u201c\u8fc7\u6ee4\u201d\u5185\u5bb9\u7684\u8fc7\u7a0b\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u5c06\u4f7f\u7528<code>the_content<\/code>\u8fd9\u4e2a\u8fc7\u6ee4\u5668\u3002\u4fee\u6539\u7c7b\u4e2d\u7684\u6784\u9020\u51fd\u6570\u548c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">class My_First_Plugin {\n    public function __construct() {\n        \/\/ \u5c06\u81ea\u5b9a\u4e49\u65b9\u6cd5\u6302\u8f7d\u5230\u2018the_content\u2019\u8fc7\u6ee4\u5668\u4e0a\n        add_filter( &#039;the_content&#039;, array( $this, &#039;add_footer_to_content&#039; ) );\n    }\n\n\/**\n     * \u5728\u6587\u7ae0\u5185\u5bb9\u540e\u6dfb\u52a0\u81ea\u5b9a\u4e49\u9875\u811a\n     *\n     * @param string $content \u539f\u59cb\u6587\u7ae0\u5185\u5bb9\u3002\n     * @return string \u4fee\u6539\u540e\u7684\u6587\u7ae0\u5185\u5bb9\u3002\n     *\/\n    public function add_footer_to_content( $content ) {\n        \/\/ \u786e\u4fdd\u53ea\u5728\u4e3b\u5faa\u73af\u7684\u5355\u7bc7\u6587\u7ae0\u9875\u9762\u663e\u793a\n        if ( is_single() &amp;&amp; in_the_loop() &amp;&amp; is_main_query() ) {\n            $custom_footer = &#039;&lt;div class=&quot;my-plugin-footer&quot;&gt;&lt;p&gt;\u611f\u8c22\u9605\u8bfb\u672c\u6587\uff01\u7531\u3010\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u3011\u751f\u6210\u3002&lt;\/p&gt;&lt;\/div&gt;&#039;;\n            $content .= $custom_footer;\n        }\n        return $content;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>add_filter()<\/code>\u51fd\u6570\u5c06\u7c7b\u65b9\u6cd5<code>add_footer_to_content<\/code>\u6ce8\u518c\u5230<code>the_content<\/code>\u8fc7\u6ee4\u5668\u3002\u5f53WordPress\u51c6\u5907\u8f93\u51fa\u6587\u7ae0\u5185\u5bb9\u65f6\uff0c\u4f1a\u8c03\u7528\u6211\u4eec\u7684\u65b9\u6cd5\uff0c\u5e76\u4f20\u5165\u539f\u59cb\u5185\u5bb9\u3002\u6211\u4eec\u901a\u8fc7\u6761\u4ef6\u5224\u65ad\u786e\u4fdd\u53ea\u5728\u5355\u72ec\u7684\u6587\u7ae0\u9875\u9762\u6dfb\u52a0\u9875\u811a\uff0c\u907f\u514d\u5728\u9996\u9875\u3001\u5f52\u6863\u9875\u91cd\u590d\u6dfb\u52a0\u3002\u6700\u540e\uff0c\u5c06\u81ea\u5b9a\u4e49HTML\u8ffd\u52a0\u5230\u5185\u5bb9\u540e\u5e76\u8fd4\u56de\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u63d2\u4ef6\u6dfb\u52a0\u7ba1\u7406\u540e\u53f0\u9009\u9879<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u6210\u719f\u7684\u63d2\u4ef6\u901a\u5e38\u5141\u8bb8\u7528\u6237\u5728\u540e\u53f0\u8fdb\u884c\u914d\u7f6e\u3002\u6211\u4eec\u5c06\u4e3a\u521a\u624d\u7684\u9875\u811a\u6587\u672c\u6dfb\u52a0\u4e00\u4e2a\u7b80\u5355\u7684\u8bbe\u7f6e\u9009\u9879\uff0c\u8ba9\u7528\u6237\u80fd\u81ea\u5b9a\u4e49\u663e\u793a\u7684\u6587\u5b57\u3002<\/p>\n<!-- AUTO_SYNCED_PATTERN_INSERT_START -->\n\r\n<div class=\"flex justify-between items-center flex-col lg:flex-row xl:flex-col 2xl:flex-row gap-6 sm:gap-8 rounded-lg border border-gray-200 dark:border-gray-700 p-4 mb-8 lg:mb-10 sm:p-6 bg-white dark:bg-gray-750 shadow-md transition-colors duration-300\"\r\n     data-link=\"https:\/\/www.likacloud.com\/ja\/tolink\/hosting-shared-hosting\/\">\r\n     \r\n  <div class=\"flex flex-col gap-3 gap-4 sm:gap-6 w-full\">\r\n    <strong class=\"text-2xl font-semibold text-gray-900 dark:text-gray-200\">\r\n      hosting.com \u5171\u4eab\u4e3b\u673a    <\/strong>\r\n    <div class=\"text-gray-600 dark:text-gray-300 word-word\">\u9ad8\u6027\u80fd\uff0c\u914d\u5907 AMD EPYC CPU\u3001NVMe SSD \u5b58\u50a8\u548c LiteSpeed\uff0c\u5168\u5929\u501924\u5c0f\u65f6\u3001\u5168\u5929\u5019\u7684\u4e13\u5bb6\u5185\u90e8\u652f\u6301\uff0c\u9ad8\u7ea7\u5b89\u5168\u63aa\u65bd\uff0c\u5305\u62ec SSL\u3001\u66b4\u529b\u7834\u89e3\u3001\u6076\u610f\u8f6f\u4ef6\u548c DDoS \u9632\u62a4\uff0c\u8282\u7701\u9ad8\u8fbe 73%<\/div>\r\n  <\/div>\r\n\r\n  <div class=\"flex items-center flex-col md:flex-row lg:flex-col xl:flex-row 2xl:flex-col gap-6 shrink-0\">\r\n          <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/hosting-shared-hosting\/\">\r\n                  <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/09\/20250901222940.svg\" alt=\"hosting.com LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 dark:hidden\" title=\"\">\r\n          <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/12\/20251228220957.webp\" alt=\"hosting.com LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 hidden dark:block\" title=\"\">\r\n              <\/a>\r\n    \r\n    <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/hosting-shared-hosting\/\"\r\n       class=\"bg-blue-500 w-full md:w-auto lg:w-full xl:w-auto 2xl:w-full text-center !text-white dark:!text-gray-200 !px-5 !py-1.5 rounded-full hover:bg-blue-600 transition-colors\">\r\n       \u8bbf\u95ee\u9875\u9762    <\/a>\r\n  <\/div>\r\n<\/div>\n<!-- AUTO_SYNCED_PATTERN_INSERT_END -->\n\n\n\n\n\n<h3 class=\"wp-block-heading\">\u521b\u5efa\u8bbe\u7f6e\u83dc\u5355\u9875\u9762<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u9700\u8981\u5728WordPress\u7ba1\u7406\u540e\u53f0\u7684\u201c\u8bbe\u7f6e\u201d\u83dc\u5355\u4e0b\u6dfb\u52a0\u4e00\u4e2a\u5b50\u9875\u9762\u3002\u8fd9\u9700\u8981\u4f7f\u7528<code>add_options_page()<\/code>\u51fd\u6570\uff0c\u5b83\u901a\u5e38\u6302\u8f7d\u5728<code>admin_menu<\/code>\u52a8\u4f5c\u94a9\u5b50\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5728\u63d2\u4ef6\u7c7b\u4e2d\u65b0\u589e\u4e00\u4e2a\u65b9\u6cd5\u6765\u6ce8\u518c\u83dc\u5355\u548c\u9875\u9762\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">class My_First_Plugin {\n    \/\/ ... \u4e4b\u524d\u7684\u6784\u9020\u51fd\u6570\u548c\u65b9\u6cd5 ...\n\npublic function __construct() {\n        add_filter( &#039;the_content&#039;, array( $this, &#039;add_footer_to_content&#039; ) );\n        \/\/ \u6302\u8f7d\u540e\u53f0\u7ba1\u7406\u83dc\u5355\n        add_action( &#039;admin_menu&#039;, array( $this, &#039;add_admin_menu&#039; ) );\n        \/\/ \u6302\u8f7d\u521d\u59cb\u5316\u8bbe\u7f6e\u9009\u9879\n        add_action( &#039;admin_init&#039;, array( $this, &#039;settings_init&#039; ) );\n    }\n\npublic function add_admin_menu() {\n        add_options_page(\n            &#039;\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u8bbe\u7f6e&#039;, \/\/ \u9875\u9762\u6807\u9898\n            &#039;\u81ea\u5b9a\u4e49\u9875\u811a\u8bbe\u7f6e&#039;,     \/\/ \u83dc\u5355\u6807\u9898\n            &#039;manage_options&#039;,     \/\/ \u6240\u9700\u6743\u9650\n            &#039;my-first-plugin&#039;,    \/\/ \u83dc\u5355slug\n            array( $this, &#039;options_page_html&#039; ) \/\/ \u56de\u8c03\u51fd\u6570\uff0c\u7528\u4e8e\u8f93\u51fa\u9875\u9762HTML\n        );\n    }\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u518c\u8bbe\u7f6e\u5b57\u6bb5\u4e0e\u6e32\u67d3\u9875\u9762<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528WordPress Settings API\u6765\u5b89\u5168\u5730\u6ce8\u518c\u3001\u4fdd\u5b58\u548c\u9a8c\u8bc1\u9009\u9879\u3002\u8fd9\u6d89\u53ca\u5230<code>register_setting()<\/code>, <code>add_settings_section()<\/code>\u548c<code>add_settings_field()<\/code>\u7b49\u51fd\u6570\u3002<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/en\/knowledge\/wordpress\/woocommerce-guide-core-features-use-cases\/\">WooCommerce \u662f\u4ec0\u4e48\uff1f\u4e00\u6587\u8be6\u89e3\u5176\u6838\u5fc3\u529f\u80fd\u4e0e\u5e94\u7528\u573a\u666f<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">public function settings_init() {\n    \/\/ \u6ce8\u518c\u4e00\u4e2a\u8bbe\u7f6e\u9009\u9879\u7ec4\n    register_setting( &#039;my_first_plugin_settings&#039;, &#039;my_first_plugin_options&#039; );\n\n\/\/ \u5728\u9875\u9762\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u8bbe\u7f6e\u533a\u57df\n    add_settings_section(\n        &#039;my_first_plugin_section&#039;,\n        &#039;\u9875\u811a\u5185\u5bb9\u914d\u7f6e&#039;,\n        array( $this, &#039;section_callback&#039; ),\n        &#039;my-first-plugin&#039;\n    );\n\n\/\/ \u5411\u8be5\u533a\u57df\u6dfb\u52a0\u4e00\u4e2a\u5b57\u6bb5\n    add_settings_field(\n        &#039;footer_text&#039;,\n        &#039;\u9875\u811a\u663e\u793a\u6587\u672c&#039;,\n        array( $this, &#039;footer_text_field_render&#039; ),\n        &#039;my-first-plugin&#039;,\n        &#039;my_first_plugin_section&#039;\n    );\n}\n\npublic function section_callback() {\n    echo &#039;&lt;p&gt;\u5728\u8fd9\u91cc\u914d\u7f6e\u663e\u793a\u5728\u6587\u7ae0\u672b\u5c3e\u7684\u6587\u672c\u5185\u5bb9\u3002&lt;\/p&gt;&#039;;\n}\n\npublic function footer_text_field_render() {\n    $options = get_option( &#039;my_first_plugin_options&#039; );\n    $value = $options[&#039;footer_text&#039;] ?? &#039;\u611f\u8c22\u9605\u8bfb\u672c\u6587\uff01\u7531\u3010\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u3011\u751f\u6210\u3002&#039;; \/\/ \u9ed8\u8ba4\u503c\n    ?&gt;\n    &lt;input type=&#039;text&#039; name=&#039;my_first_plugin_options[footer_text]&#039; value=&#039;&lt;?php echo esc_attr( $value ); ?&gt;&#039; style=&#039;width: 400px;&#039;&gt;\n    &lt;p class=&quot;description&quot;&gt;\u652f\u6301\u7b80\u5355\u7684HTML\u6807\u7b7e\uff0c\u5982 &lt;strong&gt;, &lt;em&gt;, &lt;a&gt;\u3002&lt;\/p&gt;\n    &lt;?php\n}\n\npublic function options_page_html() {\n    \/\/ \u68c0\u67e5\u7528\u6237\u6743\u9650\n    if ( ! current_user_can( &#039;manage_options&#039; ) ) {\n        return;\n    }\n    ?&gt;\n    &lt;div class=&quot;wrap&quot;&gt;\n        &lt;h1&gt;&lt;?php echo esc_html( get_admin_page_title() ); ?&gt;&lt;\/h1&gt;\n        &lt;form action=&#039;options.php&#039; method=&#039;post&#039;&gt;\n            &lt;?php\n            settings_fields( &#039;my_first_plugin_settings&#039; );\n            do_settings_sections( &#039;my-first-plugin&#039; );\n            submit_button();\n            ?&gt;\n        &lt;\/form&gt;\n    &lt;\/div&gt;\n    &lt;?php\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\uff0c\u4fee\u6539\u524d\u7aef\u8f93\u51fa\u51fd\u6570<code>add_footer_to_content<\/code>\uff0c\u4f7f\u5176\u4ece\u6570\u636e\u5e93\u9009\u9879\u4e2d\u8bfb\u53d6\u6587\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">public function add_footer_to_content( $content ) {\n    if ( is_single() &amp;&amp; in_the_loop() &amp;&amp; is_main_query() ) {\n        $options = get_option( &#039;my_first_plugin_options&#039; );\n        $footer_text = $options[&#039;footer_text&#039;] ?? &#039;\u611f\u8c22\u9605\u8bfb\u672c\u6587\uff01\u7531\u3010\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u3011\u751f\u6210\u3002&#039;;\n        $custom_footer = &#039;&lt;div class=&quot;my-plugin-footer&quot;&gt;&lt;p&gt;&#039; . wp_kses_post( $footer_text ) . &#039;&lt;\/p&gt;&lt;\/div&gt;&#039;;\n        $content .= $custom_footer;\n    }\n    return $content;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>wp_kses_post()<\/code>\u51fd\u6570\u786e\u4fdd\u4e86\u7528\u6237\u8f93\u5165\u7684\u6587\u672c\u4e2d\u53ea\u5141\u8bb8\u51fa\u73b0\u5b89\u5168\u7684HTML\u6807\u7b7e\uff0c\u8fd9\u662f\u91cd\u8981\u7684\u5b89\u5168\u63aa\u65bd\u3002<\/p>\n<!-- AUTO_SYNCED_PATTERN_INSERT_START -->\n\r\n<div class=\"flex justify-between items-center flex-col lg:flex-row xl:flex-col 2xl:flex-row gap-6 sm:gap-8 rounded-lg border border-gray-200 dark:border-gray-700 p-4 mb-8 lg:mb-10 sm:p-6 bg-white dark:bg-gray-750 shadow-md transition-colors duration-300\"\r\n     data-link=\"https:\/\/www.likacloud.com\/ja\/tolink\/interserver-webhosting\/\">\r\n     \r\n  <div class=\"flex flex-col gap-3 gap-4 sm:gap-6 w-full\">\r\n    <strong class=\"text-2xl font-semibold text-gray-900 dark:text-gray-200\">\r\n      InterServer \u5171\u4eab\u4e3b\u673a    <\/strong>\r\n    <div class=\"text-gray-600 dark:text-gray-300 word-word\">\u5171\u4eab\u4e3b\u673a\u6bcf\u6708 $2.50 USD , \u9996\u6708 $0.1 USD \u4f18\u60e0\u7801 tryinterserver, 461\u4e2a\u4e91\u5e94\u7528\u811a\u672c\uff0c\u4e00\u952e\u5b89\u88c5\u3002<\/div>\r\n  <\/div>\r\n\r\n  <div class=\"flex items-center flex-col md:flex-row lg:flex-col xl:flex-row 2xl:flex-col gap-6 shrink-0\">\r\n          <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/interserver-webhosting\/\">\r\n                  <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/12\/20251228045033.svg\" alt=\"InterServer LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 dark:hidden\" title=\"\">\r\n          <img decoding=\"async\" src=\"https:\/\/www.likacloud.com\/wp-content\/uploads\/2025\/12\/20251229054830.webp\" alt=\"InterServer LOGO\" class=\"content-promotion-card-icon h-9 min-h-9 hidden dark:block\" title=\"\">\r\n              <\/a>\r\n    \r\n    <a href=\"https:\/\/www.likacloud.com\/ja\/tolink\/interserver-webhosting\/\"\r\n       class=\"bg-blue-500 w-full md:w-auto lg:w-full xl:w-auto 2xl:w-full text-center !text-white dark:!text-gray-200 !px-5 !py-1.5 rounded-full hover:bg-blue-600 transition-colors\">\r\n       \u8bbf\u95ee\u9875\u9762    <\/a>\r\n  <\/div>\r\n<\/div>\n<!-- AUTO_SYNCED_PATTERN_INSERT_END -->\n\n\n\n\n\n<h2 class=\"wp-block-heading\">\u63d2\u4ef6\u56fd\u9645\u5316\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u8ba9\u63d2\u4ef6\u80fd\u88ab\u5168\u4e16\u754c\u7684\u7528\u6237\u4f7f\u7528\uff0c\u56fd\u9645\u5316\uff08i18n\uff09\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u6b65\u3002WordPress\u4f7f\u7528GNU gettext\u6846\u67b6\u6765\u5b9e\u73b0\u7ffb\u8bd1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u672c\u57df\u4e0e\u7ffb\u8bd1\u51fd\u6570<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u63d2\u4ef6\u5934\u90e8\u6ce8\u91ca\u4e2d\u5b9a\u4e49\u4e86<code>Text Domain<\/code>\uff0c\u4f8b\u5982<code>my-first-plugin<\/code>\u3002\u7136\u540e\uff0c\u5728\u63d2\u4ef6\u4e2d\u6240\u6709\u9700\u8981\u7ffb\u8bd1\u7684\u5b57\u7b26\u4e32\u5904\uff0c\u4f7f\u7528\u7279\u5b9a\u7684\u51fd\u6570\u8fdb\u884c\u5305\u88f9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u6211\u4eec\u4e4b\u524d\u7684\u4ee3\u7801\uff0c\u4e3a\u8f93\u51fa\u6587\u672c\u6dfb\u52a0\u7ffb\u8bd1\u652f\u6301\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">\/\/ \u5728\u6784\u9020\u51fd\u6570\u4e2d\u52a0\u8f7d\u7ffb\u8bd1\u6587\u4ef6\npublic function __construct() {\n    \/\/ ... \u5176\u4ed6\u94a9\u5b50 ...\n    add_action( &#039;plugins_loaded&#039;, array( $this, &#039;load_textdomain&#039; ) );\n}\n\npublic function load_textdomain() {\n    load_plugin_textdomain(\n        &#039;my-first-plugin&#039;,\n        false,\n        dirname( plugin_basename( __FILE__ ) ) . &#039;\/languages\/&#039;\n    );\n}\n\n\/\/ \u4fee\u6539\u8bbe\u7f6e\u9875\u9762\u7684\u5b57\u7b26\u4e32\npublic function section_callback() {\n    echo &#039;&lt;p&gt;&#039; . esc_html__( &#039;\u5728\u8fd9\u91cc\u914d\u7f6e\u663e\u793a\u5728\u6587\u7ae0\u672b\u5c3e\u7684\u6587\u672c\u5185\u5bb9\u3002&#039;, &#039;my-first-plugin&#039; ) . &#039;&lt;\/p&gt;&#039;;\n}\n\npublic function footer_text_field_render() {\n    $options = get_option( &#039;my_first_plugin_options&#039; );\n    $value = $options[&#039;footer_text&#039;] ?? __( &#039;\u611f\u8c22\u9605\u8bfb\u672c\u6587\uff01\u7531\u3010\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u3011\u751f\u6210\u3002&#039;, &#039;my-first-plugin&#039; );\n    ?&gt;\n    &lt;input type=&#039;text&#039; name=&#039;my_first_plugin_options[footer_text]&#039; value=&#039;&lt;?php echo esc_attr( $value ); ?&gt;&#039; style=&#039;width: 400px;&#039;&gt;\n    &lt;p class=&quot;description&quot;&gt;&lt;?php esc_html_e( &#039;\u652f\u6301\u7b80\u5355\u7684HTML\u6807\u7b7e\uff0c\u5982 &lt;strong&gt;, &lt;em&gt;, &lt;a&gt;\u3002&#039;, &#039;my-first-plugin&#039; ); ?&gt;&lt;\/p&gt;\n    &lt;?php\n}\n\n\/\/ \u6ce8\u610f\uff1a\u7528\u6237\u5728\u524d\u53f0\u8f93\u5165\u7684\u201c\u9875\u811a\u6587\u672c\u201d\u672c\u8eab\u901a\u5e38\u4e0d\u9700\u8981\u7ffb\u8bd1\uff0c\u56e0\u4e3a\u5b83\u662f\u7531\u7ba1\u7406\u5458\u8bbe\u7f6e\u7684\u5177\u4f53\u5185\u5bb9\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>__()<\/code>\u7528\u4e8e\u7ffb\u8bd1\u5e76\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c<code>esc_html__()<\/code>\u7528\u4e8e\u7ffb\u8bd1\u5e76\u8f6c\u4e49HTML\u8f93\u51fa\uff0c<code>_e()<\/code>\u7528\u4e8e\u7ffb\u8bd1\u5e76\u76f4\u63a5\u56de\u663e\u5b57\u7b26\u4e32\u3002\u51fd\u6570\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u6587\u672c\u57df\uff0c\u5fc5\u987b\u4e0e\u63d2\u4ef6\u5b9a\u4e49\u7684\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b89\u5168\u3001\u6027\u80fd\u4e0e\u4ee3\u7801\u7ec4\u7ec7<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u56fd\u9645\u5316\uff0c\u8fd8\u9700\u9075\u5faa\u4ee5\u4e0b\u6700\u4f73\u5b9e\u8df5\uff1a<br \/>\n1.  \u5b89\u5168\uff1a\u5bf9\u6240\u6709\u7528\u6237\u8f93\u5165\u8fdb\u884c\u9a8c\u8bc1\u3001\u6e05\u7406\u548c\u8f6c\u4e49\u3002\u4f7f\u7528<code>sanitize_text_field()<\/code>, <code>esc_html()<\/code>, <code>wp_kses_post()<\/code>\u7b49\u51fd\u6570\u3002\u4f7f\u7528<code>wp_nonce_field()<\/code>\u9632\u6b62CSRF\u653b\u51fb\u3002<br \/>\n2.  \u6027\u80fd\uff1a\u5408\u7406\u4f7f\u7528\u94a9\u5b50\uff0c\u907f\u514d\u5728\u6bcf\u6b21\u9875\u9762\u52a0\u8f7d\u65f6\u6267\u884c\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u5e93\u67e5\u8be2\u3002\u53ef\u4ee5\u8003\u8651\u5bf9\u8f93\u51fa\u7ed3\u679c\u8fdb\u884c transient \u7f13\u5b58\u3002<br \/>\n3.  \u4ee3\u7801\u7ec4\u7ec7\uff1a\u5bf9\u4e8e\u590d\u6742\u7684\u63d2\u4ef6\uff0c\u5e94\u5c06\u6587\u4ef6\u6309\u529f\u80fd\u6a21\u5757\u62c6\u5206\u3002\u4e3b\u6587\u4ef6\u8d1f\u8d23\u5f15\u5bfc\uff0c\u7c7b\u548c\u65b9\u6cd5\u653e\u5728<code>includes\/<\/code>\u76ee\u5f55\uff0c\u524d\u7aef\u8d44\u4ea7\uff08CSS, JS\uff09\u653e\u5728<code>assets\/<\/code>\u76ee\u5f55\u3002<br \/>\n4.  \u5378\u8f7d\u6e05\u7406\uff1a\u5982\u679c\u4f60\u7684\u63d2\u4ef6\u521b\u5efa\u4e86\u6570\u636e\u5e93\u8868\u6216\u9009\u9879\uff0c\u5e94\u8be5\u63d0\u4f9b\u5378\u8f7d\u529f\u80fd\u6765\u6e05\u7406\u6570\u636e\u3002\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e2a\u72ec\u7acb\u7684<code>uninstall.php<\/code>\u6587\u4ef6\u6765\u5b9e\u73b0\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u603b\u7ed3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u672c\u6559\u7a0b\uff0c\u6211\u4eec\u5b8c\u6210\u4e86\u4e00\u4e2a\u5177\u5907\u57fa\u7840\u529f\u80fd\u7684WordPress\u81ea\u5b9a\u4e49\u63d2\u4ef6\u7684\u5b8c\u6574\u5f00\u53d1\u6d41\u7a0b\uff1a\u4ece\u642d\u5efa\u73af\u5883\u3001\u521b\u5efa\u63d2\u4ef6\u9aa8\u67b6\u3001\u5229\u7528\u94a9\u5b50\u7cfb\u7edf\u6dfb\u52a0\u529f\u80fd\uff0c\u5230\u5b9e\u73b0\u540e\u53f0\u8bbe\u7f6e\u9875\u9762\uff0c\u6700\u540e\u6db5\u76d6\u56fd\u9645\u5316\u548c\u5b89\u5168\u5b9e\u8df5\u3002\u4f60\u5b66\u4f1a\u4e86\u5982\u4f55\u4f7f\u7528<code>add_filter<\/code>\u548c<code>add_action<\/code>\u4e0eWordPress\u6838\u5fc3\u4ea4\u4e92\uff0c\u5982\u4f55\u4f7f\u7528Settings API\u521b\u5efa\u53ef\u9760\u7684\u9009\u9879\u9875\u9762\uff0c\u4ee5\u53ca\u5982\u4f55\u901a\u8fc7<code>load_plugin_textdomain<\/code>\u4f7f\u63d2\u4ef6\u652f\u6301\u591a\u8bed\u8a00\u3002\u8bb0\u4f4f\uff0c\u5f00\u53d1\u63d2\u4ef6\u65f6\uff0c\u5b89\u5168\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u7528\u6237\u4f53\u9a8c\u662f\u9996\u8981\u8003\u8651\u56e0\u7d20\u3002\u4ee5\u6b64\u4e3a\u57fa\u7840\uff0c\u4f60\u53ef\u4ee5\u7ee7\u7eed\u63a2\u7d22\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u3001\u5143\u6570\u636e\u3001\u77ed\u4ee3\u7801\u3001REST API\u7aef\u70b9\u7b49\u66f4\u9ad8\u7ea7\u7684\u529f\u80fd\uff0c\u6784\u5efa\u66f4\u5f3a\u5927\u7684WordPress\u6269\u5c55\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ \u5e38\u89c1\u95ee\u9898<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48\u6211\u7684\u63d2\u4ef6\u5728\u540e\u53f0\u83dc\u5355\u4e2d\u4e0d\u663e\u793a\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u901a\u5e38\u662f\u7531\u4e8e\u6743\u9650\u95ee\u9898\u6216\u4ee3\u7801\u9519\u8bef\u9020\u6210\u7684\u3002\u9996\u5148\uff0c\u8bf7\u786e\u4fdd\u4f60\u7684<code>add_options_page<\/code>\u6216<code>add_menu_page<\/code>\u51fd\u6570\u4e2d\u6307\u5b9a\u7684\u6743\u9650\u53c2\u6570\uff08\u5982<code>\u2018manage_options\u2019<\/code>\uff09\u4e0e\u4f60\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u89d2\u8272\u5339\u914d\u3002\u5176\u6b21\uff0c\u68c0\u67e5<code>admin_menu<\/code>\u94a9\u5b50\u662f\u5426\u6b63\u786e\u6302\u8f7d\uff0c\u5e76\u4e14\u56de\u8c03\u51fd\u6570\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef\u5bfc\u81f4PHP\u6267\u884c\u4e2d\u65ad\u3002\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u5728WordPress\u540e\u53f0\u542f\u7528<code>WP_DEBUG<\/code>\uff0c\u67e5\u770b\u662f\u5426\u6709\u76f8\u5173\u7684\u9519\u8bef\u4fe1\u606f\u8f93\u51fa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u4e3a\u63d2\u4ef6\u6dfb\u52a0\u81ea\u5b9a\u4e49CSS\u548cJavaScript\u6587\u4ef6\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b63\u786e\u7684\u505a\u6cd5\u662f\u4f7f\u7528<code>wp_enqueue_style()<\/code>\u548c<code>wp_enqueue_script()<\/code>\u51fd\u6570\u3002\u5bf9\u4e8e\u524d\u7aef\u8d44\u6e90\uff0c\u5e94\u6302\u8f7d\u5230<code>wp_enqueue_scripts<\/code>\u52a8\u4f5c\u94a9\u5b50\u4e0a\uff1b\u5bf9\u4e8e\u7ba1\u7406\u540e\u53f0\u8d44\u6e90\uff0c\u5219\u6302\u8f7d\u5230<code>admin_enqueue_scripts<\/code>\u94a9\u5b50\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f60\u7684\u63d2\u4ef6\u7c7b\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u5982\u4e0b\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">public function enqueue_frontend_assets() {\n    wp_enqueue_style( \u2018my-plugin-style\u2019, plugin_dir_url( __FILE__ ) . \u2018assets\/css\/style.css\u2019, array(), \u20181.0.0\u2019 );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u5728\u6784\u9020\u51fd\u6570\u4e2d\u901a\u8fc7<code>add_action( \u2018wp_enqueue_scripts\u2019, array( $this, \u2018enqueue_frontend_assets\u2019 ) );<\/code>\u6ce8\u518c\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u4f9d\u8d56\u7ba1\u7406\u6b63\u786e\uff0c\u5e76\u4e14\u4e0d\u4f1a\u4e0e\u5176\u4ed6\u63d2\u4ef6\u6216\u4e3b\u9898\u51b2\u7a81\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7528\u6237\u5378\u8f7d\u63d2\u4ef6\u65f6\uff0c\u5982\u4f55\u6e05\u7406\u6211\u521b\u5efa\u7684\u6570\u636e\u9009\u9879\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e3b\u8981\u65b9\u5f0f\u3002\u7b2c\u4e00\u79cd\u662f\u6ce8\u518c\u4e00\u4e2a\u5378\u8f7d\u94a9\u5b50\uff0c\u4f46\u8fd9\u5728\u9762\u5411\u5bf9\u8c61\u7684\u63d2\u4ef6\u4e2d\u4e0d\u5e38\u7528\u3002\u66f4\u63a8\u8350\u3001\u4e5f\u66f4\u6807\u51c6\u7684\u65b9\u6cd5\u662f\u521b\u5efa\u4e00\u4e2a<code>uninstall.php<\/code>\u6587\u4ef6\uff0c\u5b83\u4e0e\u4f60\u7684\u4e3b\u63d2\u4ef6\u6587\u4ef6\u540c\u7ea7\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u7528\u6237\u901a\u8fc7WordPress\u540e\u53f0\u5220\u9664\u63d2\u4ef6\u65f6\uff0cWordPress\u4f1a\u81ea\u52a8\u68c0\u67e5\u5e76\u6267\u884c\u8fd9\u4e2a\u6587\u4ef6\u3002\u5728<code>uninstall.php<\/code>\u4e2d\uff0c\u4f60\u9700\u8981\u5148\u68c0\u67e5<code>WP_UNINSTALL_PLUGIN<\/code>\u5e38\u91cf\u662f\u5426\u88ab\u5b9a\u4e49\uff0c\u7136\u540e\u5b89\u5168\u5730\u5220\u9664\u63d2\u4ef6\u521b\u5efa\u7684\u6240\u6709\u9009\u9879\u3001\u81ea\u5b9a\u4e49\u6570\u636e\u5e93\u8868\u7b49\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">if ( ! defined( \u2018WP_UNINSTALL_PLUGIN\u2019 ) ) {\n    exit;\n}\ndelete_option( \u2018my_first_plugin_options\u2019 );\n\/\/ \u5982\u679c\u6709\u81ea\u5b9a\u4e49\u8868\uff1a$wpdb-&gt;query( \u201cDROP TABLE IF EXISTS {$wpdb-&gt;prefix}my_table\u201d );<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6211\u7684\u63d2\u4ef6\u5982\u4f55\u517c\u5bb9\u66f4\u591a\u7248\u672c\u7684WordPress\uff1f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fdd\u6301\u517c\u5bb9\u6027\u7684\u5173\u952e\u5728\u4e8e\u614e\u7528\u65b0\u7248\u672c\u7684\u51fd\u6570\u548c\u7279\u6027\uff0c\u5e76\u4e3a\u65e7\u7248\u672c\u63d0\u4f9b\u66ff\u4ee3\u65b9\u6848\u3002\u5728\u8c03\u7528\u53ef\u80fd\u5728\u65b0\u7248\u672c\u4e2d\u624d\u5b58\u5728\u7684\u51fd\u6570\u524d\uff0c\u4f7f\u7528<code>function_exists()<\/code>\u8fdb\u884c\u68c0\u67e5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u8981\u4f7f\u75285.0\u7248\u672c\u5f15\u5165\u7684<code>wp_date<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">if ( function_exists( \u2018wp_date\u2019 ) ) {\n    $date = wp_date( get_option( \u2018date_format\u2019 ), $timestamp );\n} else {\n    $date = date_i18n( get_option( \u2018date_format\u2019 ), $timestamp );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u65f6\uff0c\u5728\u63d2\u4ef6\u5934\u90e8\u6ce8\u91ca\u548creadme\u6587\u4ef6\u4e2d\u660e\u786e\u58f0\u660e\u6d4b\u8bd5\u8fc7\u7684\u6700\u4f4eWordPress\u7248\u672c\u3002\u5b9a\u671f\u5728\u8f83\u65e7\u7684WordPress\u7248\u672c\u4e0a\u8fdb\u884c\u6d4b\u8bd5\u662f\u786e\u4fdd\u517c\u5bb9\u6027\u7684\u6700\u597d\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress\u30d7\u30e9\u30b0\u30a4\u30f3\u958b\u767a\u306e\u57fa\u672c\u3068\u74b0\u5883\u69cb\u7bc9\u624b\u9806\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u57fa\u672c\u7684\u306a\u69cb\u9020\u3001\u30e1\u30a4\u30f3\u30d5\u30a1\u30a4\u30eb\u306e\u30d8\u30c3\u30c0\u30fc\u30b3\u30e1\u30f3\u30c8\u306e\u6307\u5b9a\u3001\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u306e\u521d\u671f\u5316\u65b9\u6cd5\u306b\u7126\u70b9\u3092\u5f53\u3066\u3066\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u5b9f\u969b\u306e\u30b1\u30fc\u30b9\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u6700\u5f8c\u306b\u30ab\u30b9\u30bf\u30e0\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306e\u6295\u7a3f\u3092\u901a\u3057\u3066\u3001\u30b3\u30fc\u30c9\u3092\u30ab\u30d7\u30bb\u30eb\u5316\u3057\u3001\u30b3\u30a2\u6a5f\u80fd\u3092\u5b9f\u73fe\u3059\u308b\u305f\u3081\u306e\u30d5\u30a3\u30eb\u30bf\u30d5\u30c3\u30af\u3092\u30de\u30a6\u30f3\u30c8\u3059\u308b\u305f\u3081\u306b\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3092\u793a\u3057\u307e\u3059\u3002<\/p>","protected":false},"author":7,"featured_media":0,"template":"","meta":{"_acf_changed":false,"footnotes":""},"tags":[2100,118,1927,2155,1967],"knowledge_category":[280],"class_list":["post-12366113","knowledge_post","type-knowledge_post","status-publish","hentry","tag-php","tag-wordpress","tag-plugin-development","tag-tutorial","tag-custom-plugins","knowledge_category-wordpress"],"acf":{"site_seo_keywords":"WordPress\u63d2\u4ef6\u5f00\u53d1,\u81ea\u5b9a\u4e49\u63d2\u4ef6\u6559\u7a0b,WordPress\u94a9\u5b50,\u63d2\u4ef6\u5f00\u53d1\u73af\u5883,\u63d2\u4ef6\u5b89\u5168\u89c4\u8303,\u4ece\u96f6\u5f00\u59cb\u5f00\u53d1\u63d2\u4ef6,\u6dfb\u52a0\u6587\u7ae0\u9875\u811a\u5185\u5bb9"},"_links":{"self":[{"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/knowledge_posts\/12366113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/knowledge_posts"}],"about":[{"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/types\/knowledge_post"}],"author":[{"embeddable":true,"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/users\/7"}],"version-history":[{"count":1,"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/knowledge_posts\/12366113\/revisions"}],"predecessor-version":[{"id":12404301,"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/knowledge_posts\/12366113\/revisions\/12404301"}],"wp:attachment":[{"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/media?parent=12366113"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/tags?post=12366113"},{"taxonomy":"knowledge_category","embeddable":true,"href":"https:\/\/www.likacloud.com\/ja\/wp-json\/wp\/v2\/knowledge_category?post=12366113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}