{"id":32920,"date":"2024-11-25T15:10:20","date_gmt":"2024-11-25T07:10:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32920\/"},"modified":"2024-11-25T15:10:20","modified_gmt":"2024-11-25T07:10:20","slug":"%e5%a6%82%e4%bd%95%e4%b8%bawordpress%e6%8f%92%e4%bb%b6%e6%b7%bb%e5%8a%a0%e6%bb%9a%e5%8a%a8%e5%85%ac%e5%91%8a%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32920\/","title":{"rendered":"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169398641282793.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\u63d2\u56fe\" alt=\"\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd<\/p>\n<p>WordPress\u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u6709\u8bb8\u591a\u63d2\u4ef6\u53ef\u4f9b\u7528\u6237\u9009\u62e9\u4ee5\u589e\u52a0\u7f51\u7ad9\u7684\u529f\u80fd\u548c\u5438\u5f15\u529b\u3002\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\u3002\u8fd9\u6837\u7684\u529f\u80fd\u53ef\u4ee5\u8ba9\u7f51\u7ad9\u7ba1\u7406\u5458\u5728\u7f51\u7ad9\u7684\u9876\u90e8\u6216\u5e95\u90e8\u663e\u793a\u4e00\u6761\u6eda\u52a8\u7684\u516c\u544a\uff0c\u4ee5\u4fbf\u5411\u8bbf\u95ee\u8005\u4f20\u8fbe\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n<p>\u7b2c\u4e00\u6b65\u662f\u5728\u6211\u4eec\u7684\u63d2\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u8bbe\u7f6e\u9875\u9762\uff0c\u5728\u8be5\u9875\u9762\u4e0a\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u548c\u7ba1\u7406\u6211\u4eec\u7684\u6eda\u52a8\u516c\u544a\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528WordPress\u63d0\u4f9b\u7684Settings API\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\u3002<\/p>\n<pre>\/\/ \u5728\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\n\n\/\/ \u6dfb\u52a0\u4e00\u4e2a\u83dc\u5355\u9009\u9879\u5230WordPress\u540e\u53f0\u7684\u8bbe\u7f6e\u83dc\u5355\u4e2d\nfunction custom_plugin_settings_menu() {\n    add_options_page(\n        '\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e',\n        '\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e',\n        'manage_options',\n        'custom_plugin_settings',\n        'custom_plugin_settings_callback'\n    );\n}\nadd_action('admin_menu', 'custom_plugin_settings_menu');\n\n\/\/ \u5c55\u793a\u8bbe\u7f6e\u9875\u9762\u5185\u5bb9\nfunction custom_plugin_settings_callback() {\n    \/\/ \u68c0\u67e5\u7528\u6237\u6743\u9650\n    if (!current_user_can('manage_options')) {\n        wp_die('\u60a8\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\u6b64\u9875\u9762\uff01');\n    }\n\n    \/\/ \u68c0\u67e5\u5e76\u66f4\u65b0\u8bbe\u7f6e\n    if (isset($_POST['custom_plugin_notice'])) {\n        update_option('custom_plugin_notice', sanitize_text_field($_POST['custom_plugin_notice']));\n    }\n\n    \/\/ \u663e\u793a\u8bbe\u7f6e\u9875\u9762\u5185\u5bb9\n    $notice = get_option('custom_plugin_notice');\n    ?&amp;gt;\n    &lt;div class=\"wrap\"&gt;\n        &lt;h1&gt;\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e&lt;\/h1&gt;\n        &lt;form method=\"post\" action=\"\"&gt;\n            &lt;label for=\"custom_plugin_notice\"&gt;\u6eda\u52a8\u516c\u544a\u5185\u5bb9\uff1a&lt;\/label&gt;\n            &lt;input type=\"text\" name=\"custom_plugin_notice\" id=\"custom_plugin_notice\" value=\"&amp;lt;?php echo esc_attr($notice); ?&amp;gt;\" size=\"50\"&gt;&lt;input type=\"submit\" name=\"submit\" id=\"submit\" class=\"button button-primary\" value=\"\u4fdd\u5b58\u8bbe\u7f6e\"&gt;\n&lt;\/form&gt;\n    &lt;\/div&gt;\n    &lt;?php }<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u5728WordPress\u540e\u53f0\u7684\u8bbe\u7f6e\u83dc\u5355\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201c\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e\u201d\u7684\u5b50\u83dc\u5355\u9879\u3002\u70b9\u51fb\u8fd9\u4e2a\u5b50\u83dc\u5355\u9879\u5c06\u4f1a\u8df3\u8f6c\u5230\u6211\u4eec\u7684\u8bbe\u7f6e\u9875\u9762\uff0c\u53ef\u4ee5\u5728\u9875\u9762\u4e0a\u6dfb\u52a0\u548c\u4fdd\u5b58\u6eda\u52a8\u516c\u544a\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684custom_plugin_notice\u662f\u6211\u4eec\u6eda\u52a8\u516c\u544a\u7684\u8bbe\u7f6e\u9879\u3002\u6211\u4eec\u53ef\u4ee5\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u8fd9\u4e2a\u503c\uff0c\u5e76\u5728\u524d\u53f0\u663e\u793a\u6eda\u52a8\u516c\u544a\u3002<\/p>\n<pre>\/\/ \u5728\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\n\n\/\/ \u5728\u7f51\u7ad9\u524d\u53f0\u663e\u793a\u516c\u544a\nfunction custom_plugin_display_notice() {\n    $notice = get_option('custom_plugin_notice');\n    ?&amp;gt;\n    &lt;div class=\"custom-plugin-notice\"&gt;\n        &lt;marquee behavior=\"scroll\" direction=\"left\"&gt;&lt;?php echo esc_html($notice); ?&gt;&lt;\/marquee&gt;\n&lt;\/div&gt;\n    &lt;?php }\nadd_action('wp_footer', 'custom_plugin_display_notice');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u5728\u7f51\u7ad9\u7684\u5e95\u90e8\u6dfb\u52a0\u4e00\u4e2acustom-plugin-notice\u7c7b\u7684div\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u6eda\u52a8\u7684marquee\u5143\u7d20\uff0c\u5185\u5bb9\u662f\u6211\u4eec\u5728\u8bbe\u7f6e\u9875\u9762\u4e2d\u8bbe\u7f6e\u7684\u6eda\u52a8\u516c\u544a\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u81ea\u5b9a\u4e49CSS\u6837\u5f0f\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u7684\u6eda\u52a8\u516c\u544a\u529f\u80fd\u5df2\u7ecf\u5b8c\u6210\u3002\u53ea\u9700\u5b89\u88c5\u548c\u6fc0\u6d3b\u6211\u4eec\u7684\u63d2\u4ef6\uff0c\u7136\u540e\u901a\u8fc7\u540e\u53f0\u8bbe\u7f6e\u9875\u6dfb\u52a0\u548c\u7ba1\u7406\u6eda\u52a8\u516c\u544a\u7684\u5185\u5bb9\u5373\u53ef\u3002<\/p>\n<p>\u603b\u7ed3\u4e00\u4e0b\uff0c\u5728\u672c\u6587\u4e2d\u6211\u4eec\u5b66\u4e60\u4e86\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\u3002\u6211\u4eec\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u8bbe\u7f6e\u9875\u9762\u6765\u8ba9\u7528\u6237\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\uff0c\u5e76\u4f7f\u7528Settings API\u6765\u4fdd\u5b58\u8bbe\u7f6e\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528wp_footer\u94a9\u5b50\u5728\u7f51\u7ad9\u524d\u53f0\u663e\u793a\u6eda\u52a8\u516c\u544a\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u6269\u5c55\u4f60\u7684WordPress\u63d2\u4ef6\u529f\u80fd\uff0c\u589e\u52a0\u7f51\u7ad9\u7684\u5438\u5f15\u529b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\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\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd WordPress\u4f5c\u4e3a\u4e00\u79cd\u5e7f\u6cdb\u4f7f\u7528\u7684\u5185\u5bb9\u7ba1\u7406\u7cfb\u7edf\uff0c\u6709\u8bb8\u591a\u63d2\u4ef6\u53ef\u4f9b\u7528\u6237\u9009\u62e9\u4ee5\u589e\u52a0\u7f51\u7ad9\u7684\u529f\u80fd\u548c\u5438\u5f15\u529b\u3002\u4eca\u5929\uff0c\u6211\u4eec\u5c06\u8ba8\u8bba\u5982\u4f55\u4e3aWordPress\u63d2\u4ef6\u6dfb\u52a0\u6eda\u52a8\u516c\u544a\u529f\u80fd\u3002\u8fd9\u6837\u7684\u529f\u80fd\u53ef\u4ee5\u8ba9\u7f51\u7ad9\u7ba1\u7406\u5458\u5728\u7f51\u7ad9\u7684\u9876\u90e8\u6216\u5e95\u90e8\u663e\u793a\u4e00\u6761\u6eda\u52a8\u7684\u516c\u544a\uff0c\u4ee5\u4fbf\u5411\u8bbf\u95ee\u8005\u4f20\u8fbe\u91cd\u8981\u4fe1\u606f\u3002 \u7b2c\u4e00\u6b65\u662f\u5728\u6211\u4eec\u7684\u63d2\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2a\u8bbe\u7f6e\u9875\u9762\uff0c\u5728\u8be5\u9875\u9762\u4e0a\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u548c\u7ba1\u7406\u6211\u4eec\u7684\u6eda\u52a8\u516c\u544a\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528WordPress\u63d0\u4f9b\u7684Settings API\u6765\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1\u3002 \/\/ \u5728\u63d2\u4ef6\u7684\u4e3b\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801 \/\/ \u6dfb\u52a0\u4e00\u4e2a\u83dc\u5355\u9009\u9879\u5230WordPress\u540e\u53f0\u7684\u8bbe\u7f6e\u83dc\u5355\u4e2d function custom_plugin_settings_menu() { add_options_page( &#8216;\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e&#8217;, &#8216;\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e&#8217;, &#8216;manage_options&#8217;, &#8216;custom_plugin_settings&#8217;, &#8216;custom_plugin_settings_callback&#8217; ); } add_action(&#8216;admin_menu&#8217;, &#8216;custom_plugin_settings_menu&#8217;); \/\/ \u5c55\u793a\u8bbe\u7f6e\u9875\u9762\u5185\u5bb9 function custom_plugin_settings_callback() { \/\/ \u68c0\u67e5\u7528\u6237\u6743\u9650 if (!current_user_can(&#8216;manage_options&#8217;)) { wp_die(&#8216;\u60a8\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\u6b64\u9875\u9762\uff01&#8217;); } \/\/ \u68c0\u67e5\u5e76\u66f4\u65b0\u8bbe\u7f6e if (isset($_POST[&#8216;custom_plugin_notice&#8217;])) { update_option(&#8216;custom_plugin_notice&#8217;, sanitize_text_field($_POST[&#8216;custom_plugin_notice&#8217;])); } \/\/ \u663e\u793a\u8bbe\u7f6e\u9875\u9762\u5185\u5bb9 $notice = get_option(&#8216;custom_plugin_notice&#8217;); ?&amp;gt; &lt;div class=&#8221;wrap&#8221;&gt; &lt;h1&gt;\u81ea\u5b9a\u4e49\u63d2\u4ef6\u8bbe\u7f6e&lt;\/h1&gt; &lt;form method=&#8221;post&#8221; action=&#8221;&#8221;&gt; &lt;label for=&#8221;custom_plugin_notice&#8221;&gt;\u6eda\u52a8\u516c\u544a\u5185\u5bb9\uff1a&lt;\/label&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-32920","post","type-post","status-publish","format-standard","hentry","category-cms"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32920","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=32920"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32920\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}