{"id":12374661,"date":"2026-03-17T18:49:55","date_gmt":"2026-03-17T10:49:55","guid":{"rendered":"https:\/\/www.likacloud.com\/knowledge\/wordpress-%e6%8f%92%e4%bb%b6%e5%bc%80%e5%8f%91%e5%85%a5%e9%97%a8%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bb%8e%e9%9b%b6%e6%9e%84%e5%bb%ba%e4%bd%a0%e7%9a%84%e7%ac%ac%e4%b8%80%e4%b8%aa%e8%87%aa%e5%ae%9a%e4%b9%89\/"},"modified":"2026-06-03T20:43:59","modified_gmt":"2026-06-03T12:43:59","slug":"wordpress-plugin-development-guide-custom-extension","status":"publish","type":"knowledge_post","link":"https:\/\/www.likacloud.com\/pt\/knowledge\/wordpress\/wordpress-plugin-development-guide-custom-extension\/","title":{"rendered":"Guia introdut\u00f3rio para o desenvolvimento de plugins do WordPress: crie a sua primeira extens\u00e3o de funcionalidade personalizada do zero."},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e3a\u4f55\u9700\u8981\u5f00\u53d1\u81ea\u5b9a\u4e49\u63d2\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress \u4ee5\u5176\u5f3a\u5927\u7684\u53ef\u6269\u5c55\u6027\u800c\u95fb\u540d\uff0c\u5176\u6838\u5fc3\u79d8\u8bc0\u4e4b\u4e00\u4fbf\u662f\u63d2\u4ef6\u7cfb\u7edf\u3002\u5f53\u7f51\u7ad9\u5bf9\u529f\u80fd\u7684\u9700\u6c42\u8d85\u51fa\u4e3b\u9898\u6216\u73b0\u6709\u63d2\u4ef6\u7684\u80fd\u529b\u8303\u56f4\u65f6\uff0c\u81ea\u884c\u5f00\u53d1\u4fbf\u6210\u4e3a\u6700\u4f73\u9009\u62e9\u3002\u4e0e\u76f4\u63a5\u4fee\u6539\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u76f8\u6bd4\uff0c\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684\u63d2\u4ef6\u5177\u6709\u663e\u8457\u4f18\u52bf\u3002\u63d2\u4ef6\u4e0e\u4e3b\u9898\u5206\u79bb\uff0c\u8fd9\u610f\u5473\u7740\u5373\u4f7f\u5207\u6362\u4e3b\u9898\uff0c\u63d2\u4ef6\u7684\u529f\u80fd\u4f9d\u7136\u53ef\u4ee5\u5b8c\u6574\u4fdd\u7559\uff0c\u786e\u4fdd\u4e86\u529f\u80fd\u7684\u72ec\u7acb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u6b64\u5916\uff0c\u4e00\u4e2a\u7ed3\u6784\u826f\u597d\u7684\u63d2\u4ef6\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4e0d\u540c\u7f51\u7ad9\u95f4\u8fc1\u79fb\u548c\u590d\u7528\uff0c\u751a\u81f3\u901a\u8fc7\u5b98\u65b9\u6216\u7b2c\u4e09\u65b9\u6e20\u9053\u8fdb\u884c\u5206\u53d1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f00\u53d1\u81ea\u5b9a\u4e49\u63d2\u4ef6\u5141\u8bb8\u4f60\u7cbe\u786e\u5730\u63a7\u5236\u529f\u80fd\u903b\u8f91\uff0c\u907f\u514d\u56e0\u5b89\u88c5\u8fc7\u591a\u901a\u7528\u63d2\u4ef6\u800c\u5e26\u6765\u7684\u6027\u80fd\u5f00\u9500\u548c\u6f5c\u5728\u7684\u4ee3\u7801\u51b2\u7a81\u3002\u4ece\u7b80\u5355\u7684\u77ed\u4ee3\u7801\u751f\u6210\u5230\u590d\u6742\u7684\u6570\u636e\u5904\u7406\u548c\u5de5\u4f5c\u6d41\u7ba1\u7406\uff0c\u63d2\u4ef6\u5f00\u53d1\u4e3a\u4f60\u6253\u5f00\u4e86\u6df1\u5ea6\u5b9a\u5236 WordPress \u7684\u5927\u95e8\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u642d\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u57fa\u7840\u7ed3\u6784<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a WordPress \u63d2\u4ef6\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u4f4d\u4e8e <code>wp-content\/plugins\/<\/code> \u76ee\u5f55\u4e0b\u7684 PHP \u6587\u4ef6\u3002\u521b\u5efa\u63d2\u4ef6\u7684\u7b2c\u4e00\u6b65\u662f\u5efa\u7acb\u5176\u57fa\u7840\u7ed3\u6784\u3002<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/sv\/knowledge\/wordpress\/wordpress-plugin-development-beginner-guide-build-first-functional-plugin\/\">WordPress\u63d2\u4ef6\u5f00\u53d1\u5165\u95e8\u6307\u5357\uff1a\u4ece\u96f6\u5230\u4e00\u6784\u5efa\u4f60\u7684\u7b2c\u4e00\u4e2a\u529f\u80fd\u63d2\u4ef6<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<h3 class=\"wp-block-heading\">\u521b\u5efa\u4e3b\u63d2\u4ef6\u6587\u4ef6\u4e0e\u6dfb\u52a0\u5934\u90e8\u6ce8\u91ca<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5728 <code>wp-content\/plugins\/<\/code> \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u4f8b\u5982 <code>my-first-plugin<\/code>\u3002\u7136\u540e\uff0c\u5728\u8be5\u6587\u4ef6\u5939\u5185\u521b\u5efa\u4e3b PHP \u6587\u4ef6\uff0c\u901a\u5e38\u4e0e\u6587\u4ef6\u5939\u540c\u540d\uff1a<code>my-first-plugin.php<\/code>\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\/pt\/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\/pt\/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\/pt\/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<p class=\"wp-block-paragraph\">\u6587\u4ef6\u7684\u5f00\u5934\u5fc5\u987b\u5305\u542b\u7b26\u5408 WordPress \u6807\u51c6\u7684\u63d2\u4ef6\u5934\u90e8\u6ce8\u91ca\uff0c\u8fd9\u662f WordPress \u8bc6\u522b\u63d2\u4ef6\u7684\u5173\u952e\u3002\u8fd9\u4e9b\u6ce8\u91ca\u63d0\u4f9b\u4e86\u63d2\u4ef6\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u4f1a\u663e\u793a\u5728\u540e\u53f0\u7684\u63d2\u4ef6\u7ba1\u7406\u9875\u9762\u4e2d\u3002<\/p>\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\u7684 WordPress \u81ea\u5b9a\u4e49\u63d2\u4ef6\u793a\u4f8b\u3002\n * Version:           1.0.0\n * Author:            \u4f60\u7684\u540d\u5b57\n * Author URI:        https:\/\/example.com\n * License:           GPL v2 or later\n * Text Domain:       my-first-plugin\n * Domain Path:       \/languages\n *\/<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u767b\u5f55 WordPress \u540e\u53f0\uff0c\u8fdb\u5165\u201c\u63d2\u4ef6\u201d\u9875\u9762\uff0c\u4f60\u5e94\u8be5\u80fd\u770b\u5230\u540d\u4e3a\u201c\u6211\u7684\u7b2c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u63d2\u4ef6\u201d\u7684\u63d2\u4ef6\u51fa\u73b0\u5728\u5217\u8868\u4e2d\uff0c\u5e76\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u6fc0\u6d3b\u6216\u505c\u7528\u64cd\u4f5c\u3002\u76ee\u524d\u5b83\u8fd8\u6ca1\u6709\u4efb\u4f55\u5b9e\u9645\u529f\u80fd\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e3a\u63d2\u4ef6\u529f\u80fd\u521b\u5efa\u5b89\u5168\u5305\u88c5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u907f\u514d\u51fd\u6570\u540d\u4e0e\u4e3b\u9898\u6216\u5176\u4ed6\u63d2\u4ef6\u51b2\u7a81\uff0c\u6700\u4f73\u5b9e\u8df5\u662f\u5c06\u6240\u6709\u529f\u80fd\u5305\u88c5\u5728\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u6216\u8005\u4e3a\u6240\u6709\u51fd\u6570\u6dfb\u52a0\u72ec\u7279\u7684\u524d\u7f00\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u7c7b\u7684\u65b9\u5f0f\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u5c01\u88c5\u6027\u548c\u7ec4\u7ec7\u7ed3\u6784\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u6587\u4ef6\u4e2d\uff0c\u5934\u90e8\u6ce8\u91ca\u4e4b\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5b9a\u4e49\u63d2\u4ef6\u7684\u4e3b\u7c7b\u3002<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/sv\/knowledge\/wordpress\/wordpress-plugin-development-complete-guide-first-functional-plugin\/\">WordPress\u63d2\u4ef6\u5f00\u53d1\u5b8c\u5168\u6307\u5357\uff1a\u4ece\u96f6\u6253\u9020\u4f60\u7684\u7b2c\u4e00\u4e2a\u529f\u80fd\u63d2\u4ef6<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">if ( ! defined( &#039;ABSPATH&#039; ) ) {\n    exit; \/\/ \u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\u6587\u4ef6\n}\n\nclass My_First_Plugin {\n    \/**\n     * \u6784\u9020\u65b9\u6cd5\uff0c\u7528\u4e8e\u521d\u59cb\u5316\u63d2\u4ef6\n     *\/\n    public function __construct() {\n        \/\/ \u521d\u59cb\u5316\u94a9\u5b50\n        $this-&gt;init_hooks();\n    }\n\n\/**\n     * \u521d\u59cb\u5316 WordPress \u94a9\u5b50\uff08\u52a8\u4f5c\u548c\u8fc7\u6ee4\u5668\uff09\n     *\/\n    private function init_hooks() {\n        \/\/ \u540e\u7eed\u7684\u94a9\u5b50\u5c06\u5728\u8fd9\u91cc\u6dfb\u52a0\n    }\n}\n\n\/\/ \u521d\u59cb\u5316\u63d2\u4ef6\nnew My_First_Plugin();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7 <code>if ( ! defined( 'ABSPATH' ) )<\/code> \u8fd9\u884c\u4ee3\u7801\uff0c\u6211\u4eec\u786e\u4fdd\u4e86\u8be5\u6587\u4ef6\u53ea\u80fd\u901a\u8fc7 WordPress \u73af\u5883\u8bbf\u95ee\uff0c\u63d0\u5347\u4e86\u5b89\u5168\u6027\u3002\u73b0\u5728\uff0c\u63d2\u4ef6\u7684\u57fa\u672c\u6846\u67b6\u5df2\u7ecf\u5c31\u7eea\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5229\u7528\u94a9\u5b50\u6269\u5c55 WordPress \u6838\u5fc3\u529f\u80fd<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress \u7684\u63d2\u4ef6 API \u6838\u5fc3\u662f\u201c\u94a9\u5b50\u201d\uff08Hooks\uff09\uff0c\u5b83\u5141\u8bb8\u4f60\u5728\u7279\u5b9a\u7684\u65f6\u95f4\u70b9\u6216\u5bf9\u7279\u5b9a\u7684\u6570\u636e\u6267\u884c\u81ea\u5b9a\u4e49\u4ee3\u7801\u3002\u94a9\u5b50\u5206\u4e3a\u4e24\u79cd\uff1a\u52a8\u4f5c\uff08Actions\uff09\u548c\u8fc7\u6ee4\u5668\uff08Filters\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7406\u89e3\u5e76\u6dfb\u52a0\u4e00\u4e2a\u7b80\u5355\u52a8\u4f5c\u94a9\u5b50<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u4f5c\u94a9\u5b50\u5728\u7279\u5b9a\u4e8b\u4ef6\u53d1\u751f\u65f6\u6267\u884c\u4f60\u7684\u4ee3\u7801\uff0c\u4f8b\u5982\u53d1\u5e03\u6587\u7ae0\u3001\u52a0\u8f7d\u7ba1\u7406\u9875\u9762\u7b49\u3002\u5b83\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\uff0c\u53ea\u662f\u201c\u505a\u201d\u4e00\u4e9b\u4e8b\u60c5\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\/pt\/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\/pt\/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\/pt\/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<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u6dfb\u52a0\u4e00\u4e2a\u529f\u80fd\uff1a\u5728\u6bcf\u7bc7\u6587\u7ae0\u5185\u5bb9\u7684\u672b\u5c3e\u81ea\u52a8\u6dfb\u52a0\u4e00\u6bb5\u81ea\u5b9a\u4e49\u6587\u672c\u3002\u6211\u4eec\u5c06\u4f7f\u7528 <code>the_content<\/code> \u8fd9\u4e2a\u8fc7\u6ee4\u5668\uff08\u662f\u7684\uff0c\u867d\u7136\u540d\u4e3a\u8fc7\u6ee4\u5668\uff0c\u4f46\u5b83\u5e38\u88ab\u7528\u4e8e\u6dfb\u52a0\u5185\u5bb9\uff0c\u6280\u672f\u4e0a\u5b83\u662f\u4e00\u4e2a\u8fc7\u6ee4\u5668\uff0c\u56e0\u4e3a\u5b83\u63a5\u6536\u5e76\u8fd4\u56de\u5185\u5bb9\uff09\u3002\u4f46\u4e3a\u4e86\u5148\u6f14\u793a\u4e00\u4e2a\u7eaf\u7cb9\u7684\u52a8\u4f5c\uff0c\u6211\u4eec\u540c\u65f6\u6dfb\u52a0\u4e00\u4e2a\u5728\u540e\u53f0\u7ba1\u7406\u680f\u663e\u793a\u6d88\u606f\u7684\u52a8\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5728 <code>init_hooks<\/code> \u65b9\u6cd5\u4e2d\u6dfb\u52a0\u94a9\u5b50\u6ce8\u518c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">private function init_hooks() {\n    \/\/ \u5728\u6587\u7ae0\u5185\u5bb9\u672b\u5c3e\u6dfb\u52a0\u4fe1\u606f\u7684\u8fc7\u6ee4\u5668\n    add_filter( &#039;the_content&#039;, array( $this, &#039;append_custom_text&#039; ) );\n    \/\/ \u5728\u7ba1\u7406\u680f\u6dfb\u52a0\u8282\u70b9\u7684\u52a8\u4f5c\n    add_action( &#039;admin_bar_menu&#039;, array( $this, &#039;add_admin_bar_node&#039; ), 999 );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u5728\u7c7b\u4e2d\u5b9a\u4e49\u5bf9\u5e94\u7684\u56de\u8c03\u65b9\u6cd5\uff1a<\/p>\n<!-- AUTO_INTERNAL_LINKS_START --><p>\u63a8\u8350\u9605\u8bfb <a href=\"https:\/\/www.likacloud.com\/sv\/knowledge\/wordpress\/wordpress-plugin-development-complete-guide-from-beginner-to-expert-12374342\/\">WordPress\u63d2\u4ef6\u5f00\u53d1\u5b8c\u6574\u6307\u5357\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\u6784\u5efa\u81ea\u5b9a\u4e49\u529f\u80fd<\/a>\u3002<\/p><!-- AUTO_INTERNAL_LINKS_END -->\n\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">\/**\n * \u5728\u6587\u7ae0\u5185\u5bb9\u672b\u5c3e\u6dfb\u52a0\u81ea\u5b9a\u4e49\u6587\u672c\uff08\u8fc7\u6ee4\u5668\u56de\u8c03\uff09\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 *\/\npublic function append_custom_text( $content ) {\n    if ( is_single() &amp;&amp; in_the_loop() &amp;&amp; is_main_query() ) {\n        $custom_text = &#039;&lt;p&gt;&lt;em&gt;\u6b64\u6587\u7531\u201c\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u201d\u63d0\u4f9b\u6280\u672f\u652f\u6301\u3002&lt;\/em&gt;&lt;\/p&gt;&#039;;\n        $content .= $custom_text;\n    }\n    return $content;\n}\n\n\/**\n * \u5728\u7ba1\u7406\u5de5\u5177\u680f\u6dfb\u52a0\u4e00\u4e2a\u81ea\u5b9a\u4e49\u8282\u70b9\uff08\u52a8\u4f5c\u56de\u8c03\uff09\n *\n * @param WP_Admin_Bar $wp_admin_bar WordPress \u7ba1\u7406\u680f\u5bf9\u8c61\u3002\n *\/\npublic function add_admin_bar_node( $wp_admin_bar ) {\n    $args = array(\n        &#039;id&#039;    =&gt; &#039;my_plugin_node&#039;,\n        &#039;title&#039; =&gt; &#039;\u6211\u7684\u63d2\u4ef6&#039;,\n        &#039;href&#039;  =&gt; admin_url( &#039;plugins.php&#039; ),\n        &#039;meta&#039;  =&gt; array( &#039;class&#039; =&gt; &#039;my-plugin-node&#039; )\n    );\n    $wp_admin_bar-&gt;add_node( $args );\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u6fc0\u6d3b\u63d2\u4ef6\u540e\uff0c\u524d\u53f0\u7684\u5355\u7bc7\u6587\u7ae0\u5e95\u90e8\u4f1a\u51fa\u73b0\u6dfb\u52a0\u7684\u6587\u672c\uff0c\u540e\u53f0\u9876\u90e8\u7ba1\u7406\u680f\u4e5f\u4f1a\u51fa\u73b0\u4e00\u4e2a\u201c\u6211\u7684\u63d2\u4ef6\u201d\u83dc\u5355\u9879\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u8fc7\u6ee4\u5668\u4fee\u6539\u6570\u636e\u8f93\u51fa<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fc7\u6ee4\u5668\u7528\u4e8e\u4fee\u6539\u5728\u7279\u5b9a\u70b9\u4f20\u9012\u7684\u6570\u636e\u3002\u5b83\u63a5\u6536\u4e00\u4e2a\u503c\uff0c\u5e76\u5fc5\u987b\u8fd4\u56de\u4fee\u6539\u540e\u7684\u503c\u3002\u6211\u4eec\u4e0a\u9762\u7528\u5230\u7684 <code>append_custom_text<\/code> \u65b9\u6cd5\u5b9e\u9645\u4e0a\u5c31\u662f\u4e00\u4e2a\u8fc7\u6ee4\u5668\u56de\u8c03\u3002\u8ba9\u6211\u4eec\u518d\u521b\u5efa\u4e00\u4e2a\u66f4\u5178\u578b\u7684\u8fc7\u6ee4\u5668\u793a\u4f8b\uff1a\u4fee\u6539\u6587\u7ae0\u6458\u8981\u7684\u957f\u5ea6\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\/pt\/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\/pt\/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\/pt\/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<p class=\"wp-block-paragraph\">\u5728 <code>init_hooks<\/code> \u4e2d\u6dfb\u52a0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">add_filter( &#039;excerpt_length&#039;, array( $this, &#039;custom_excerpt_length&#039; ), 999 );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u5b9a\u4e49\u56de\u8c03\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">\/**\n * \u4fee\u6539\u6587\u7ae0\u6458\u8981\u7684\u9ed8\u8ba4\u5b57\u6570\u957f\u5ea6\n *\n * @param int $length \u9ed8\u8ba4\u7684\u6458\u8981\u957f\u5ea6\u3002\n * @return int \u4fee\u6539\u540e\u7684\u6458\u8981\u957f\u5ea6\u3002\n *\/\npublic function custom_excerpt_length( $length ) {\n    \/\/ \u5c06\u6458\u8981\u957f\u5ea6\u8bbe\u7f6e\u4e3a 30 \u4e2a\u5b57\n    return 30;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u73b0\u4e00\u4e2a\u53ef\u914d\u7f6e\u7684\u63d2\u4ef6\u9009\u9879\u9875\u9762<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u8ba9\u63d2\u4ef6\u66f4\u7075\u6d3b\uff0c\u901a\u5e38\u9700\u8981\u4e3a\u7528\u6237\u63d0\u4f9b\u4e00\u4e2a\u8bbe\u7f6e\u9875\u9762\u3002WordPress \u63d0\u4f9b\u4e86\u201c\u8bbe\u7f6e API\u201d\u6765\u5b89\u5168\u3001\u89c4\u8303\u5730\u521b\u5efa\u9009\u9879\u9875\u9762\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u521b\u5efa\u7ba1\u7406\u83dc\u5355\u4e0e\u5b50\u9875\u9762<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728 WordPress \u540e\u53f0\u6dfb\u52a0\u4e00\u4e2a\u83dc\u5355\u9879\u3002\u6211\u4eec\u5c06\u4f7f\u7528 <code>add_options_page<\/code> \u51fd\u6570\u5728\u201c\u8bbe\u7f6e\u201d\u4e3b\u83dc\u5355\u4e0b\u6dfb\u52a0\u4e00\u4e2a\u5b50\u9875\u9762\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 <code>init_hooks<\/code> \u4e2d\u6dfb\u52a0\u52a8\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">add_action( &#039;admin_menu&#039;, array( $this, &#039;add_plugin_admin_menu&#039; ) );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9a\u4e49\u6dfb\u52a0\u83dc\u5355\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">\/**\n * \u5411 WordPress \u540e\u53f0\u6dfb\u52a0\u63d2\u4ef6\u8bbe\u7f6e\u9875\u9762\n *\/\npublic function add_plugin_admin_menu() {\n    add_options_page(\n        &#039;\u6211\u7684\u63d2\u4ef6\u8bbe\u7f6e&#039;,          \/\/ \u9875\u9762\u6807\u9898\n        &#039;\u6211\u7684\u63d2\u4ef6&#039;,             \/\/ \u83dc\u5355\u6807\u9898\n        &#039;manage_options&#039;,       \/\/ \u6240\u9700\u6743\u9650\n        &#039;my-first-plugin&#039;,      \/\/ \u83dc\u5355 Slug\n        array( $this, &#039;display_plugin_admin_page&#039; ) \/\/ \u56de\u8c03\u51fd\u6570\n    );\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u8bbe\u7f6e API \u6ce8\u518c\u548c\u6e32\u67d3\u5b57\u6bb5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49 <code>display_plugin_admin_page<\/code> \u65b9\u6cd5\u6765\u6e32\u67d3\u9875\u9762\u5185\u5bb9\uff0c\u5e76\u6ce8\u518c\u8bbe\u7f6e\u3001\u5b57\u6bb5\u548c\u7ae0\u8282\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u6dfb\u52a0\u53e6\u4e00\u4e2a\u94a9\u5b50\u6765\u6ce8\u518c\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">add_action( &#039;admin_init&#039;, array( $this, &#039;register_plugin_settings&#039; ) );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u5b9e\u73b0\u76f8\u5173\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">\/**\n * \u4f7f\u7528 WordPress \u8bbe\u7f6e API \u6ce8\u518c\u8bbe\u7f6e\u3001\u5b57\u6bb5\u548c\u7ae0\u8282\n *\/\npublic function register_plugin_settings() {\n    \/\/ \u6ce8\u518c\u4e00\u4e2a\u8bbe\u7f6e\uff0c\u5b58\u50a8\u5230\u4e00\u4e2a\u9009\u9879 `my_first_plugin_options`\n    register_setting(\n        &#039;my_first_plugin_options_group&#039;, \/\/ \u9009\u9879\u7ec4\u540d\n        &#039;my_first_plugin_options&#039;        \/\/ \u9009\u9879\u540d\n    );\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u8bbe\u7f6e\u7ae0\u8282\n    add_settings_section(\n        &#039;my_first_plugin_main_section&#039;,  \/\/ \u7ae0\u8282 ID\n        &#039;\u4e3b\u8981\u8bbe\u7f6e&#039;,                      \/\/ \u7ae0\u8282\u6807\u9898\n        array( $this, &#039;render_section_description&#039; ), \/\/ \u7ae0\u8282\u63cf\u8ff0\u56de\u8c03\n        &#039;my-first-plugin&#039;                \/\/ \u9875\u9762 Slug\n    );\n\n\/\/ \u5411\u7ae0\u8282\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6587\u672c\u5b57\u6bb5\n    add_settings_field(\n        &#039;custom_text_field&#039;,             \/\/ \u5b57\u6bb5 ID\n        &#039;\u81ea\u5b9a\u4e49\u6587\u672c&#039;,                    \/\/ \u5b57\u6bb5\u6807\u9898\n        array( $this, &#039;render_text_field&#039; ), \/\/ \u5b57\u6bb5\u6e32\u67d3\u56de\u8c03\n        &#039;my-first-plugin&#039;,               \/\/ \u9875\u9762 Slug\n        &#039;my_first_plugin_main_section&#039;   \/\/ \u6240\u5c5e\u7ae0\u8282 ID\n    );\n}\n\n\/**\n * \u6e32\u67d3\u8bbe\u7f6e\u7ae0\u8282\u7684\u63cf\u8ff0\u6587\u5b57\n *\/\npublic function render_section_description() {\n    echo &#039;&lt;p&gt;\u5728\u8fd9\u91cc\u914d\u7f6e\u4f60\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u7684\u8bbe\u7f6e\u3002&lt;\/p&gt;&#039;;\n}\n\n\/**\n * \u6e32\u67d3\u81ea\u5b9a\u4e49\u6587\u672c\u8f93\u5165\u5b57\u6bb5\n *\/\npublic function render_text_field() {\n    $options = get_option( &#039;my_first_plugin_options&#039; );\n    $value = isset( $options[&#039;custom_text_field&#039;] ) ? $options[&#039;custom_text_field&#039;] : &#039;&#039;;\n    echo &#039;&lt;input type=&quot;text&quot; name=&quot;my_first_plugin_options[custom_text_field]&quot; value=&quot;&#039; . esc_attr( $value ) . &#039;&quot; class=&quot;regular-text&quot; \/&gt;&#039;;\n    echo &#039;&lt;p class=&quot;description&quot;&gt;\u8fd9\u91cc\u8f93\u5165\u7684\u6587\u5b57\u5c06\u5728\u6587\u7ae0\u672b\u5c3e\u663e\u793a\u3002&lt;\/p&gt;&#039;;\n}\n\n\/**\n * \u6e32\u67d3\u63d2\u4ef6\u7ba1\u7406\u9875\u9762\u7684\u4e3b\u8981\u5185\u5bb9\n *\/\npublic function display_plugin_admin_page() {\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=&quot;options.php&quot; method=&quot;post&quot;&gt;\n            &lt;?php\n            \/\/ \u8f93\u51fa\u5b89\u5168\u5b57\u6bb5\u3001\u7ae0\u8282\u548c\u5b57\u6bb5\n            settings_fields( &#039;my_first_plugin_options_group&#039; );\n            do_settings_sections( &#039;my-first-plugin&#039; );\n            submit_button( &#039;\u4fdd\u5b58\u8bbe\u7f6e&#039; );\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\u6211\u4eec\u9700\u8981\u4fee\u6539\u4e4b\u524d\u7684 <code>append_custom_text<\/code> \u65b9\u6cd5\uff0c\u4ece\u9009\u9879\u4e2d\u8bfb\u53d6\u7528\u6237\u4fdd\u5b58\u7684\u6587\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-php\">public function append_custom_text( $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        $custom_text = isset( $options[&#039;custom_text_field&#039;] ) &amp;&amp; ! empty( $options[&#039;custom_text_field&#039;] ) ?\n            &#039;&lt;p&gt;&lt;em&gt;&#039; . esc_html( $options[&#039;custom_text_field&#039;] ) . &#039;&lt;\/em&gt;&lt;\/p&gt;&#039; :\n            &#039;&lt;p&gt;&lt;em&gt;\u6b64\u6587\u7531\u201c\u6211\u7684\u7b2c\u4e00\u4e2a\u63d2\u4ef6\u201d\u63d0\u4f9b\u6280\u672f\u652f\u6301\u3002&lt;\/em&gt;&lt;\/p&gt;&#039;;\n        $content .= $custom_text;\n    }\n    return $content;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u7528\u6237\u5c31\u53ef\u4ee5\u5728\u201c\u8bbe\u7f6e\u201d-&gt;\u201c\u6211\u7684\u63d2\u4ef6\u201d\u9875\u9762\u4e2d\u81ea\u5b9a\u4e49\u663e\u793a\u5728\u6587\u7ae0\u672b\u5c3e\u7684\u6587\u672c\u4e86\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\u6307\u5357\uff0c\u6211\u4eec\u5b8c\u6574\u5730\u8d70\u8fc7\u4e86\u5f00\u53d1\u4e00\u4e2a WordPress \u81ea\u5b9a\u4e49\u63d2\u4ef6\u7684\u57fa\u672c\u6d41\u7a0b\uff1a\u4ece\u521b\u5efa\u57fa\u7840\u6587\u4ef6\u7ed3\u6784\u548c\u5b89\u5168\u7684\u4ee3\u7801\u5305\u88c5\u5f00\u59cb\uff0c\u5230\u6df1\u5165\u7406\u89e3\u5e76\u8fd0\u7528 WordPress \u7684\u6838\u5fc3\u6269\u5c55\u673a\u5236\u2014\u2014\u52a8\u4f5c\u4e0e\u8fc7\u6ee4\u5668\u94a9\u5b50\uff0c\u6700\u540e\u5b9e\u73b0\u4e86\u5305\u542b\u540e\u53f0\u8bbe\u7f6e\u9875\u9762\u7684\u53ef\u914d\u7f6e\u63d2\u4ef6\u3002\u6211\u4eec\u5c55\u793a\u4e86\u5982\u4f55\u89c4\u8303\u5730\u4f7f\u7528 WordPress \u8bbe\u7f6e API \u6765\u521b\u5efa\u9009\u9879\u9875\u9762\uff0c\u8fd9\u786e\u4fdd\u4e86\u6570\u636e\u7684\u5b89\u5168\u5b58\u50a8\u548c\u754c\u9762\u7684\u4e00\u81f4\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u638c\u63e1\u8fd9\u4e9b\u57fa\u7840\u77e5\u8bc6\u662f\u8fc8\u5411\u66f4\u590d\u6742\u63d2\u4ef6\u5f00\u53d1\u7684\u575a\u5b9e\u4e00\u6b65\u3002\u540e\u7eed\u4f60\u53ef\u4ee5\u63a2\u7d22\u66f4\u9ad8\u7ea7\u7684\u4e3b\u9898\uff0c\u5982\u81ea\u5b9a\u4e49\u6570\u636e\u5e93\u8868\u3001\u521b\u5efa\u77ed\u4ee3\u7801\u3001\u6dfb\u52a0\u5c0f\u5de5\u5177\uff08Widget\uff09\u3001\u7f16\u5199 REST API \u7aef\u70b9\u4ee5\u53ca\u5b9e\u73b0 AJAX \u4ea4\u4e92\u7b49\u3002\u8bb0\u4f4f\uff0c\u826f\u597d\u7684\u4ee3\u7801\u7ec4\u7ec7\u3001\u5145\u5206\u7684\u5b89\u5168\u6821\u9a8c\uff08\u5982\u80fd\u529b\u68c0\u67e5\u3001\u6570\u636e\u6e05\u7406\u548c\u8f6c\u4e49\uff09\u4ee5\u53ca\u5bf9 WordPress \u7f16\u7801\u6807\u51c6\u7684\u9075\u5faa\uff0c\u662f\u5f00\u53d1\u9ad8\u8d28\u91cf\u3001\u53ef\u7ef4\u62a4\u63d2\u4ef6\u7684\u5173\u952e\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\">\u63d2\u4ef6\u5f00\u53d1\u9700\u8981\u54ea\u4e9b\u5148\u51b3\u77e5\u8bc6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u9700\u8981\u5177\u5907 PHP \u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u5305\u62ec\u8bed\u6cd5\u3001\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\u548c\u5bf9\u8c61\u7b49\u6982\u5ff5\u3002\u540c\u65f6\uff0c\u5bf9 HTML\u3001CSS \u548c JavaScript \u6709\u57fa\u672c\u4e86\u89e3\u4e5f\u4f1a\u975e\u5e38\u6709\u5e2e\u52a9\uff0c\u5c24\u5176\u662f\u5728\u521b\u5efa\u6d89\u53ca\u524d\u7aef\u4ea4\u4e92\u6216\u590d\u6742\u540e\u53f0\u754c\u9762\u7684\u63d2\u4ef6\u65f6\u3002\u4e86\u89e3 WordPress \u7684\u57fa\u672c\u64cd\u4f5c\u548c\u67b6\u6784\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u8c03\u8bd5\u6b63\u5728\u5f00\u53d1\u7684\u63d2\u4ef6<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u786e\u4fdd\u5728\u4f60\u7684 <code>wp-config.php<\/code> \u6587\u4ef6\u4e2d\u5c06 <code>WP_DEBUG<\/code> \u8bbe\u7f6e\u4e3a <code>true<\/code>\uff0c\u8fd9\u5c06\u5f00\u542f WordPress \u7684\u9519\u8bef\u62a5\u544a\u529f\u80fd\u3002\u4f7f\u7528\u6d4f\u89c8\u5668\u7684\u5f00\u53d1\u8005\u5de5\u5177\uff08Console \u548c Network \u6807\u7b7e\u9875\uff09\u6765\u68c0\u67e5 JavaScript \u9519\u8bef\u548c\u7f51\u7edc\u8bf7\u6c42\u3002\u5bf9\u4e8e PHP \u4ee3\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>error_log()<\/code> \u51fd\u6570\u5c06\u53d8\u91cf\u6216\u4fe1\u606f\u8bb0\u5f55\u5230\u670d\u52a1\u5668\u7684\u8c03\u8bd5\u65e5\u5fd7\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u4e13\u95e8\u7684\u8c03\u8bd5\u63d2\u4ef6\u6765\u8ffd\u6eaf\u4ee3\u7801\u6267\u884c\u6d41\u7a0b\u548c\u53d8\u91cf\u72b6\u6001\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u662f\u5426\u53ef\u4ee5\u5c06\u4e3b\u9898\u7684 functions.php \u4ee3\u7801\u76f4\u63a5\u79fb\u5230\u63d2\u4ef6\u4e2d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5f88\u591a\u60c5\u51b5\u4e0b\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u8def\u5f84\u548c URL \u7684\u5f15\u7528\u95ee\u9898\u3002\u4e3b\u9898\u4e2d\u4f7f\u7528 <code>get_template_directory_uri()<\/code> \u6765\u83b7\u53d6\u4e3b\u9898\u76ee\u5f55 URI\uff0c\u5728\u63d2\u4ef6\u4e2d\u5e94\u6539\u4e3a\u4f7f\u7528 <code>plugin_dir_url(FILE)<\/code>\u3002\u540c\u6837\uff0c\u4e3b\u9898\u76ee\u5f55\u8def\u5f84\u51fd\u6570 <code>get_template_directory()<\/code> \u4e5f\u5e94\u66ff\u6362\u4e3a\u63d2\u4ef6\u7684 <code>plugin_dir_path(FILE)<\/code>\u3002\u6b64\u5916\uff0c\u8981\u786e\u4fdd\u4ee3\u7801\u4e2d\u6240\u6709\u529f\u80fd\u90fd\u59a5\u5584\u5730\u5305\u88c5\u5728\u7c7b\u6216\u5e26\u524d\u7f00\u7684\u51fd\u6570\u4e2d\uff0c\u4ee5\u907f\u514d\u51b2\u7a81\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f00\u53d1\u5546\u4e1a\u63d2\u4ef6\u9700\u8981\u6ce8\u610f\u4ec0\u4e48<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f00\u53d1\u8ba1\u5212\u5206\u53d1\u7684\u5546\u4e1a\u63d2\u4ef6\uff0c\u9700\u8981\u66f4\u52a0\u6ce8\u91cd\u4ee3\u7801\u8d28\u91cf\u3001\u5b89\u5168\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5fc5\u987b\u8fdb\u884c\u5f7b\u5e95\u7684\u56fd\u9645\u5316\u548c\u672c\u5730\u5316\u51c6\u5907\uff08\u4f7f\u7528 <code>__()<\/code>\u3001<code>_e()<\/code> \u51fd\u6570\u548c\u6587\u672c\u57df\uff09\uff0c\u4ee5\u4fbf\u7ffb\u8bd1\u3002\u4ee3\u7801\u5e94\u9075\u5faa WordPress \u7f16\u7801\u6807\u51c6\u3002\u9700\u8981\u8003\u8651\u8bb8\u53ef\u8bc1\uff08\u901a\u5e38\u4e3a GPL\uff09\u548c\u540e\u7eed\u7684\u66f4\u65b0\u673a\u5236\u3002\u4e3a\u63d2\u4ef6\u63d0\u4f9b\u6e05\u6670\u3001\u8be6\u5c3d\u7684\u4f7f\u7528\u6587\u6863\u548c\u6280\u672f\u652f\u6301\u6e20\u9053\u4e5f\u81f3\u5173\u91cd\u8981\u3002\u5728 2026 \u5e74\u7684\u751f\u6001\u4e2d\uff0c\u786e\u4fdd\u63d2\u4ef6\u4e0e\u65b0\u7248 WordPress\u3001PHP \u7248\u672c\u4ee5\u53ca\u6d41\u884c\u4e3b\u9898\u548c\u5176\u4ed6\u63d2\u4ef6\u7684\u517c\u5bb9\u6027\uff0c\u662f\u6301\u7eed\u7ef4\u62a4\u7684\u91cd\u8981\u90e8\u5206\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u4e3a\u63d2\u4ef6\u6dfb\u52a0\u591a\u8bed\u8a00\u652f\u6301<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress \u4f7f\u7528 GNU gettext \u6280\u672f\u5b9e\u73b0\u56fd\u9645\u5316\uff08i18n\uff09\u3002\u9996\u5148\uff0c\u5728\u63d2\u4ef6\u4e2d\u6240\u6709\u9700\u8981\u7ffb\u8bd1\u7684\u5b57\u7b26\u4e32\u90fd\u5e94\u4f7f\u7528\u7279\u5b9a\u7684\u51fd\u6570\u5305\u88f9\uff0c\u5982 <code>__('\u6587\u672c', 'my-first-plugin')<\/code> \u7528\u4e8e\u8fd4\u56de\u7ffb\u8bd1\uff0c<code>_e('\u6587\u672c', 'my-first-plugin')<\/code> \u7528\u4e8e\u8f93\u51fa\u7ffb\u8bd1\u3002\u7136\u540e\uff0c\u4f7f\u7528\u50cf Poedit \u8fd9\u6837\u7684\u5de5\u5177\u626b\u63cf\u63d2\u4ef6\u6e90\u4ee3\u7801\uff0c\u751f\u6210 <code>.pot<\/code> \u6a21\u677f\u6587\u4ef6\u3002\u8bd1\u8005\u57fa\u4e8e\u6b64\u6a21\u677f\u521b\u5efa\u5bf9\u5e94\u8bed\u8a00\u7684 <code>.po<\/code> \u6587\u4ef6\uff0c\u5e76\u7f16\u8bd1\u6210\u673a\u5668\u53ef\u8bfb\u7684 <code>.mo<\/code> \u6587\u4ef6\u3002\u6700\u540e\uff0c\u9700\u8981\u5c06 <code>load_plugin_textdomain()<\/code> \u51fd\u6570\u96c6\u6210\u5230\u63d2\u4ef6\u521d\u59cb\u5316\u4ee3\u7801\u4e2d\uff0c\u4ee5\u6b63\u786e\u7684\u8def\u5f84\u52a0\u8f7d\u7ffb\u8bd1\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Este artigo apresenta a necessidade de desenvolver plugins personalizados para o WordPress e fornece orienta\u00e7\u00f5es passo a passo sobre como estruturar uma base para um novo plugin. Isso inclui a cria\u00e7\u00e3o do arquivo principal, a adi\u00e7\u00e3o de coment\u00e1rios de cabe\u00e7alho padr\u00e3o, o uso de classes para encapsular funcionalidades e aumentar a seguran\u00e7a, bem como a utiliza\u00e7\u00e3o inicial do mecanismo de \u201cganchos\u201d (hooks) para expandir as funcionalidades nativas do WordPress. Oferece, assim, um caminho claro para iniciantes no processo de desenvolvimento de plugins.<\/p>","protected":false},"author":7,"featured_media":0,"template":"","meta":{"_acf_changed":false,"footnotes":""},"tags":[1978,436,2096,1960,1967],"knowledge_category":[280],"class_list":["post-12374661","knowledge_post","type-knowledge_post","status-publish","hentry","tag-wordpress-plugin-development","tag-wordpress-tutorial","tag-plugin-development-basics","tag-plugin-development-guide","tag-custom-plugins","knowledge_category-wordpress"],"acf":{"site_seo_keywords":"WordPress\u63d2\u4ef6\u5f00\u53d1,\u81ea\u5b9a\u4e49\u63d2\u4ef6,WordPress\u6559\u7a0b,\u63d2\u4ef6\u5165\u95e8\u6307\u5357,\u94a9\u5b50(Hooks),\u52a8\u4f5c\u548c\u8fc7\u6ee4\u5668,\u63d2\u4ef6\u5b89\u5168,\u4ece\u96f6\u5f00\u59cb\u5f00\u53d1\u63d2\u4ef6"},"_links":{"self":[{"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/knowledge_posts\/12374661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/knowledge_posts"}],"about":[{"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/types\/knowledge_post"}],"author":[{"embeddable":true,"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/users\/7"}],"version-history":[{"count":1,"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/knowledge_posts\/12374661\/revisions"}],"predecessor-version":[{"id":12404148,"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/knowledge_posts\/12374661\/revisions\/12404148"}],"wp:attachment":[{"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/media?parent=12374661"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/tags?post=12374661"},{"taxonomy":"knowledge_category","embeddable":true,"href":"https:\/\/www.likacloud.com\/pt\/wp-json\/wp\/v2\/knowledge_category?post=12374661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}