{"id":32866,"date":"2024-11-25T12:15:53","date_gmt":"2024-11-25T04:15:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32866\/"},"modified":"2024-11-25T12:15:53","modified_gmt":"2024-11-25T04:15:53","slug":"%e5%a6%82%e4%bd%95%e4%b8%bawordpress%e6%8f%92%e4%bb%b6%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e9%80%89%e9%a1%b9%e7%95%8c%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32866\/","title":{"rendered":"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169390929978042.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\u63d2\u56fe\" alt=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762<\/p>\n<p>\u5728\u5f00\u53d1WordPress\u63d2\u4ef6\u65f6\uff0c\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u662f\u521b\u5efa\u4e00\u4e2a\u53ef\u914d\u7f6e\u7684\u9009\u9879\u754c\u9762\uff0c\u4ee5\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u63d2\u4ef6\u7684\u884c\u4e3a\u3002\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6765\u8c03\u6574\u63d2\u4ef6\u7684\u8bbe\u7f6e\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u4ed6\u4eec\u7684\u4f7f\u7528\u4e60\u60ef\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u83dc\u5355\u9875\u9762\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u5728WordPress\u540e\u53f0\u627e\u5230\u6211\u4eec\u7684\u63d2\u4ef6\u9009\u9879\u754c\u9762\u3002\u5728\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n<pre>function custom_plugin_menu() {\n  add_menu_page(\n    '\u63d2\u4ef6\u9009\u9879\u754c\u9762', \/\/ \u9875\u9762\u6807\u9898\n    '\u63d2\u4ef6\u9009\u9879', \/\/ \u83dc\u5355\u6807\u9898\n    'manage_options', \/\/ \u7528\u6237\u6743\u9650\uff0c\u53ef\u9009\n    'custom-plugin-options', \/\/ \u754c\u9762\u6807\u8bc6\u7b26\n    'custom_plugin_options_page', \/\/ \u56de\u8c03\u51fd\u6570\n    'dashicons-admin-generic' \/\/ \u83dc\u5355\u56fe\u6807\uff0c\u53ef\u9009\n  );\n}\nadd_action('admin_menu', 'custom_plugin_menu');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u4f7f\u7528\u4e86add_menu_page\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u83dc\u5355\u9875\u9762\u3002\u5176\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u9875\u9762\u6807\u9898\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u83dc\u5355\u6807\u9898\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u7528\u6237\u6743\u9650\uff08\u53ef\u9009\uff0c\u8fd9\u91cc\u8bbe\u7f6e\u4e3amanage_options\u4ee5\u5141\u8bb8\u7ba1\u7406\u5458\u8bbf\u95ee\uff09\uff0c\u7b2c\u56db\u4e2a\u53c2\u6570\u4e3a\u754c\u9762\u6807\u8bc6\u7b26\uff0c\u7b2c\u4e94\u4e2a\u53c2\u6570\u4e3a\u56de\u8c03\u51fd\u6570\uff0c\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u4e3a\u83dc\u5355\u56fe\u6807\uff08\u53ef\u9009\uff09\u3002<\/p>\n<p>\u521b\u5efa\u83dc\u5355\u9875\u9762\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u56de\u8c03\u51fd\u6570custom_plugin_options_page\u4e2d\u7f16\u5199\u9009\u9879\u754c\u9762\u7684HTML\u4ee3\u7801\uff0c\u4ee5\u53ca\u5904\u7406\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre>function custom_plugin_options_page() {\n  if (isset($_POST['custom_plugin_submit'])) {\n    \/\/ \u4fdd\u5b58\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\n    update_option('custom_plugin_option', $_POST['custom_plugin_option']);\n    echo '&lt;div id=\"message\" class=\"updated notice is-dismissible\"&gt;\n      &lt;p&gt;\u9009\u9879\u5df2\u4fdd\u5b58&lt;\/p&gt;\n      &lt;button type=\"button\" class=\"notice-dismiss\"&gt;\n        &lt;span class=\"screen-reader-text\"&gt;\u5ffd\u7565\u6b64\u901a\u77e5\u3002&lt;\/span&gt;\n      &lt;\/button&gt;\n    &lt;\/div&gt;';\n  }\n  \n  $custom_plugin_option = get_option('custom_plugin_option');\n  \n  echo '&lt;div class=\"wrap\"&gt;\n    &lt;h1&gt;\u63d2\u4ef6\u9009\u9879\u754c\u9762&lt;\/h1&gt;\n    &lt;form method=\"post\" action=\"\"&gt;\n      &lt;label for=\"custom_plugin_option\"&gt;\u63d2\u4ef6\u9009\u9879\uff1a&lt;\/label&gt;\n      &lt;input type=\"text\" id=\"custom_plugin_option\" name=\"custom_plugin_option\" value=\"' . esc_attr($custom_plugin_option) . '\"&gt;&lt;p class=\"submit\"&gt;\n        &lt;input type=\"submit\" name=\"custom_plugin_submit\" class=\"button-primary\" value=\"\u4fdd\u5b58\u9009\u9879\"&gt;&lt;\/p&gt;\n    &lt;\/form&gt;\n  &lt;\/div&gt;';\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u9996\u5148\u68c0\u67e5\u662f\u5426\u6709\u8868\u5355\u63d0\u4ea4\uff08\u901a\u8fc7\u68c0\u67e5$_POST[&#8216;custom_plugin_submit&#8217;]\u662f\u5426\u5b58\u5728\uff09\uff0c\u5982\u679c\u6709\uff0c\u5219\u4fdd\u5b58\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\u5230WordPress\u7684options\u8868\u4e2d\u3002\u7136\u540e\uff0c\u4f7f\u7528get_option\u51fd\u6570\u83b7\u53d6\u5df2\u4fdd\u5b58\u7684\u9009\u9879\u503c\uff0c\u5e76\u5c06\u5176\u7528\u4e8e\u8868\u5355\u7684\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u83b7\u53d6\u7528\u6237\u5728\u9009\u9879\u754c\u9762\u4e2d\u8bbe\u7f6e\u7684\u9009\u9879\u503c\uff1a<\/p>\n<pre>$custom_plugin_option = get_option('custom_plugin_option');\necho '\u5f53\u524d\u9009\u9879\u503c\u4e3a\uff1a' . $custom_plugin_option;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u521b\u5efa\u4e86\u4e00\u4e2a\u53ef\u914d\u7f6e\u7684\u9009\u9879\u754c\u9762\uff0c\u5e76\u5c06\u7528\u6237\u7684\u9009\u62e9\u4fdd\u5b58\u5230WordPress\u4e2d\u3002\u5f53\u7136\uff0c\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u8fd8\u53ef\u4ee5\u589e\u52a0\u66f4\u591a\u9009\u9879\uff0c\u5e76\u6839\u636e\u9700\u6c42\u8fdb\u884c\u76f8\u5e94\u7684\u5904\u7406\u3002<\/p>\n<p>\u603b\u7ed3\u8d77\u6765\uff0c\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u83dc\u5355\u9875\u9762\uff0c\u7f16\u5199\u76f8\u5e94\u7684HTML\u4ee3\u7801\u548c\u5904\u7406\u8868\u5355\u6570\u636e\u7684\u56de\u8c03\u51fd\u6570\u5373\u53ef\u3002\u901a\u8fc7\u8fd9\u4e2a\u9009\u9879\u754c\u9762\uff0c\u7528\u6237\u53ef\u4ee5\u65b9\u4fbf\u5730\u81ea\u5b9a\u4e49\u63d2\u4ef6\u7684\u884c\u4e3a\uff0c\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762 \u5728\u5f00\u53d1WordPress\u63d2\u4ef6\u65f6\uff0c\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u662f\u521b\u5efa\u4e00\u4e2a\u53ef\u914d\u7f6e\u7684\u9009\u9879\u754c\u9762\uff0c\u4ee5\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u63d2\u4ef6\u7684\u884c\u4e3a\u3002\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u6765\u8c03\u6574\u63d2\u4ef6\u7684\u8bbe\u7f6e\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u4ed6\u4eec\u7684\u4f7f\u7528\u4e60\u60ef\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u521b\u5efa\u4e00\u4e2a\u9009\u9879\u754c\u9762\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u83dc\u5355\u9875\u9762\uff0c\u4ee5\u4fbf\u7528\u6237\u53ef\u4ee5\u5728WordPress\u540e\u53f0\u627e\u5230\u6211\u4eec\u7684\u63d2\u4ef6\u9009\u9879\u754c\u9762\u3002\u5728\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u7247\u6bb5\uff1a function custom_plugin_menu() { add_menu_page( &#8216;\u63d2\u4ef6\u9009\u9879\u754c\u9762&#8217;, \/\/ \u9875\u9762\u6807\u9898 &#8216;\u63d2\u4ef6\u9009\u9879&#8217;, \/\/ \u83dc\u5355\u6807\u9898 &#8216;manage_options&#8217;, \/\/ \u7528\u6237\u6743\u9650\uff0c\u53ef\u9009 &#8216;custom-plugin-options&#8217;, \/\/ \u754c\u9762\u6807\u8bc6\u7b26 &#8216;custom_plugin_options_page&#8217;, \/\/ \u56de\u8c03\u51fd\u6570 &#8216;dashicons-admin-generic&#8217; \/\/ \u83dc\u5355\u56fe\u6807\uff0c\u53ef\u9009 ); } add_action(&#8216;admin_menu&#8217;, &#8216;custom_plugin_menu&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u4ee3\u7801\u4f7f\u7528\u4e86add_menu_page\u51fd\u6570\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u83dc\u5355\u9875\u9762\u3002\u5176\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u9875\u9762\u6807\u9898\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e3a\u83dc\u5355\u6807\u9898\uff0c\u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u7528\u6237\u6743\u9650\uff08\u53ef\u9009\uff0c\u8fd9\u91cc\u8bbe\u7f6e\u4e3amanage_options\u4ee5\u5141\u8bb8\u7ba1\u7406\u5458\u8bbf\u95ee\uff09\uff0c\u7b2c\u56db\u4e2a\u53c2\u6570\u4e3a\u754c\u9762\u6807\u8bc6\u7b26\uff0c\u7b2c\u4e94\u4e2a\u53c2\u6570\u4e3a\u56de\u8c03\u51fd\u6570\uff0c\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u4e3a\u83dc\u5355\u56fe\u6807\uff08\u53ef\u9009\uff09\u3002 \u521b\u5efa\u83dc\u5355\u9875\u9762\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u56de\u8c03\u51fd\u6570custom_plugin_options_page\u4e2d\u7f16\u5199\u9009\u9879\u754c\u9762\u7684HTML\u4ee3\u7801\uff0c\u4ee5\u53ca\u5904\u7406\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a function custom_plugin_options_page() { if (isset($_POST[&#8216;custom_plugin_submit&#8217;])) { \/\/ \u4fdd\u5b58\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e update_option(&#8216;custom_plugin_option&#8217;, $_POST[&#8216;custom_plugin_option&#8217;]); echo &#8216;&lt;div id=&#8221;message&#8221; class=&#8221;updated notice is-dismissible&#8221;&gt; &lt;p&gt;\u9009\u9879\u5df2\u4fdd\u5b58&lt;\/p&gt; &lt;button type=&#8221;button&#8221; class=&#8221;notice-dismiss&#8221;&gt; &lt;span class=&#8221;screen-reader-text&#8221;&gt;\u5ffd\u7565\u6b64\u901a\u77e5\u3002&lt;\/span&gt; &lt;\/button&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-32866","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=32866"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32866\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}