{"id":4789,"date":"2025-10-23T16:56:00","date_gmt":"2025-10-23T08:56:00","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/?p=4789"},"modified":"2025-10-23T16:56:00","modified_gmt":"2025-10-23T08:56:00","slug":"wordpress-dist%e6%96%87%e4%bb%b6%e5%a4%b9%e5%a4%8d%e5%88%b6%e5%8a%9f%e8%83%bd%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/4789.html","title":{"rendered":"WordPress dist\u6587\u4ef6\u5939\u590d\u5236\u529f\u80fd\u5b9e\u73b0"},"content":{"rendered":"<p>\u6211\u5c06\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e2a\u5b8c\u6574\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u7528\u4e8e\u5728WordPress\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d\u5b9e\u73b0\u590d\u5236dist\u6587\u4ef6\u5939\u53ca\u5176\u6240\u6709\u6587\u4ef6\u7684\u529f\u80fd\u3002<\/p><h2 class=\"wp-block-heading\">\u8bbe\u8ba1\u601d\u8def<\/h2><ul class=\"wp-block-list\">\n<li>\u521b\u5efa\u6587\u4ef6\u590d\u5236\u529f\u80fd\u7684PHP\u5b9e\u73b0<\/li>\n\n\n\n<li>\u6dfb\u52a0\u7ba1\u7406\u754c\u9762\u4ee5\u4fbf\u4e8e\u64cd\u4f5c<\/li>\n\n\n\n<li>\u5b9e\u73b0\u72b6\u6001\u53cd\u9988\u548c\u9519\u8bef\u5904\u7406<\/li>\n\n\n\n<li>\u786e\u4fdd\u64cd\u4f5c\u5b89\u5168\u6027<\/li>\n<\/ul><p>\u4e0b\u9762\u662f\u5b8c\u6574\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p><pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Plugin Name: Dist\u6587\u4ef6\u5939\u590d\u5236\u5de5\u5177\n * Description: \u5c06WordPress\u7684dist\u6587\u4ef6\u5939\u590d\u5236\u5230\u6307\u5b9a\u4f4d\u7f6e\n * Version: 1.0\n * Author: \u60a8\u7684\u540d\u79f0\n *\/\n\n\/\/ \u9632\u6b62\u76f4\u63a5\u8bbf\u95ee\nif (!defined('ABSPATH')) {\n    exit;\n}\n\n\/\/ \u521b\u5efa\u7ba1\u7406\u83dc\u5355\nfunction dist_copy_admin_menu() {\n    add_management_page(\n        'Dist\u6587\u4ef6\u5939\u590d\u5236\u5de5\u5177',\n        'Dist\u590d\u5236\u5de5\u5177',\n        'manage_options',\n        'dist-copy-tool',\n        'dist_copy_admin_page'\n    );\n}\nadd_action('admin_menu', 'dist_copy_admin_menu');\n\n\/\/ \u7ba1\u7406\u9875\u9762\nfunction dist_copy_admin_page() {\n    ?&gt;\n    &lt;div class=\"wrap\"&gt;\n        &lt;h1&gt;WordPress dist\u6587\u4ef6\u5939\u590d\u5236\u5de5\u5177&lt;\/h1&gt;\n\n        &lt;?php\n        \/\/ \u5904\u7406\u590d\u5236\u64cd\u4f5c\n        if (isset($_POST['copy_dist']) &amp;&amp; check_admin_referer('dist_copy_action')) {\n            $source = isset($_POST['source_path']) ? sanitize_text_field($_POST['source_path']) : '';\n            $target = isset($_POST['target_path']) ? sanitize_text_field($_POST['target_path']) : '';\n\n            if (empty($source) || empty($target)) {\n                echo '&lt;div class=\"notice notice-error\"&gt;&lt;p&gt;\u8bf7\u586b\u5199\u6e90\u8def\u5f84\u548c\u76ee\u6807\u8def\u5f84&lt;\/p&gt;&lt;\/div&gt;';\n            } else {\n                $result = copy_dist_folder($source, $target);\n                if ($result['success']) {\n                    echo '&lt;div class=\"notice notice-success\"&gt;&lt;p&gt;' . $result['message'] . '&lt;\/p&gt;&lt;\/div&gt;';\n                } else {\n                    echo '&lt;div class=\"notice notice-error\"&gt;&lt;p&gt;' . $result['message'] . '&lt;\/p&gt;&lt;\/div&gt;';\n                }\n            }\n        }\n        ?&gt;\n\n        &lt;div style=\"display: flex; margin-top: 20px;\"&gt;\n            &lt;div style=\"flex: 1; padding: 20px; background: #f6f7f7; border-radius: 5px; margin-right: 20px;\"&gt;\n                &lt;h2&gt;\u590d\u5236\u8bbe\u7f6e&lt;\/h2&gt;\n                &lt;form method=\"post\"&gt;\n                    &lt;?php wp_nonce_field('dist_copy_action'); ?&gt;\n                    &lt;table class=\"form-table\"&gt;\n                        &lt;tr&gt;\n                            &lt;th scope=\"row\"&gt;&lt;label for=\"source_path\"&gt;\u6e90\u6587\u4ef6\u5939\u8def\u5f84&lt;\/label&gt;&lt;\/th&gt;\n                            &lt;td&gt;\n                                &lt;input type=\"text\" name=\"source_path\" id=\"source_path\" value=\"&lt;?php echo esc_attr(ABSPATH . 'wp-includes\/css\/dist\/'); ?&gt;\" class=\"regular-text\"&gt;\n                                &lt;p class=\"description\"&gt;WordPress dist\u6587\u4ef6\u5939\u7684\u5b8c\u6574\u8def\u5f84&lt;\/p&gt;\n                            &lt;\/td&gt;\n                        &lt;\/tr&gt;\n                        &lt;tr&gt;\n                            &lt;th scope=\"row\"&gt;&lt;label for=\"target_path\"&gt;\u76ee\u6807\u6587\u4ef6\u5939\u8def\u5f84&lt;\/label&gt;&lt;\/th&gt;\n                            &lt;td&gt;\n                                &lt;input type=\"text\" name=\"target_path\" id=\"target_path\" value=\"&lt;?php echo esc_attr(ABSPATH . 'skin\/wpcss\/'); ?&gt;\" class=\"regular-text\"&gt;\n                                &lt;p class=\"description\"&gt;\u8981\u5c06dist\u6587\u4ef6\u5939\u590d\u5236\u5230\u7684\u76ee\u6807\u4f4d\u7f6e&lt;\/p&gt;\n                            &lt;\/td&gt;\n                        &lt;\/tr&gt;\n                    &lt;\/table&gt;\n                    &lt;p class=\"submit\"&gt;\n                        &lt;input type=\"submit\" name=\"copy_dist\" class=\"button button-primary\" value=\"\u5f00\u59cb\u590d\u5236\u6587\u4ef6\u5939\"&gt;\n                    &lt;\/p&gt;\n                &lt;\/form&gt;\n\n                &lt;div style=\"margin-top: 30px; background: #fff; padding: 15px; border-radius: 5px;\"&gt;\n                    &lt;h3&gt;\u8bf4\u660e&lt;\/h3&gt;\n                    &lt;p&gt;\u6b64\u5de5\u5177\u5c06\u9012\u5f52\u590d\u5236WordPress\u7684dist\u6587\u4ef6\u5939\u53ca\u5176\u6240\u6709\u5185\u5bb9\u5230\u6307\u5b9a\u4f4d\u7f6e\u3002&lt;\/p&gt;\n                    &lt;p&gt;&lt;strong&gt;\u6ce8\u610f\uff1a&lt;\/strong&gt;\u786e\u4fdd\u76ee\u6807\u6587\u4ef6\u5939\u5b58\u5728\u4e14\u6709\u5199\u5165\u6743\u9650\u3002&lt;\/p&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n\n            &lt;div style=\"flex: 1; padding: 20px; background: #f6f7f7; border-radius: 5px;\"&gt;\n                &lt;h2&gt;\u64cd\u4f5c\u65e5\u5fd7&lt;\/h2&gt;\n                &lt;div style=\"background: #2d3748; color: #e2e8f0; padding: 15px; border-radius: 5px; height: 300px; overflow-y: auto; font-family: monospace;\"&gt;\n                    &lt;?php\n                    $log = get_option('dist_copy_log', []);\n                    if (!empty($log)) {\n                        foreach ($log as $entry) {\n                            $class = '';\n                            if (strpos($entry, '\u6210\u529f') !== false) {\n                                $class = 'style=\"color: #68d391;\"';\n                            } elseif (strpos($entry, '\u5931\u8d25') !== false || strpos($entry, '\u9519\u8bef') !== false) {\n                                $class = 'style=\"color: #fc8181;\"';\n                            } elseif (strpos($entry, '\u8b66\u544a') !== false) {\n                                $class = 'style=\"color: #f6e05e;\"';\n                            } else {\n                                $class = 'style=\"color: #63b3ed;\"';\n                            }\n                            echo '&lt;div ' . $class . '&gt;' . esc_html($entry) . '&lt;\/div&gt;';\n                        }\n                    } else {\n                        echo '&lt;div style=\"color: #63b3ed;\"&gt;\u6682\u65e0\u65e5\u5fd7\u8bb0\u5f55&lt;\/div&gt;';\n                    }\n                    ?&gt;\n                &lt;\/div&gt;\n\n                &lt;div style=\"margin-top: 20px; background: #fff; padding: 15px; border-radius: 5px;\"&gt;\n                    &lt;h3&gt;\u6587\u4ef6\u5939\u7ed3\u6784\u793a\u4f8b&lt;\/h3&gt;\n                    &lt;div style=\"font-family: monospace;\"&gt;\n                        &lt;div&gt;\ud83d\udcc2 dist&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 20px;\"&gt;\ud83d\udcc2 block-library&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 40px;\"&gt;\ud83d\udcc4 style.min.css&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 40px;\"&gt;\ud83d\udcc4 theme.min.css&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 20px;\"&gt;\ud83d\udcc2 components&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 40px;\"&gt;\ud83d\udcc4 style.min.css&lt;\/div&gt;\n                        &lt;div style=\"margin-left: 20px;\"&gt;\ud83d\udcc4 package.json&lt;\/div&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/div&gt;\n        &lt;\/div&gt;\n    &lt;\/div&gt;\n\n    &lt;style&gt;\n        .wrap h1 {\n            color: #2d3748;\n            margin-bottom: 20px;\n        }\n        .form-table th {\n            width: 200px;\n        }\n        .regular-text {\n            width: 100%;\n            max-width: 400px;\n        }\n    &lt;\/style&gt;\n    &lt;?php\n}\n\n\/\/ \u9012\u5f52\u590d\u5236\u6587\u4ef6\u5939\u51fd\u6570\nfunction copy_dist_folder($source, $target) {\n    \/\/ \u6dfb\u52a0\u65e5\u5fd7\n    add_dist_log('\u5f00\u59cb\u590d\u5236: ' . $source . ' -&gt; ' . $target);\n\n    \/\/ \u68c0\u67e5\u6e90\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\n    if (!is_dir($source)) {\n        $message = '\u9519\u8bef\uff1a\u6e90\u6587\u4ef6\u5939\u4e0d\u5b58\u5728';\n        add_dist_log($message);\n        return ['success' =&gt; false, 'message' =&gt; $message];\n    }\n\n    \/\/ \u68c0\u67e5\u76ee\u6807\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u521b\u5efa\n    if (!is_dir($target)) {\n        if (!wp_mkdir_p($target)) {\n            $message = '\u9519\u8bef\uff1a\u65e0\u6cd5\u521b\u5efa\u76ee\u6807\u6587\u4ef6\u5939';\n            add_dist_log($message);\n            return ['success' =&gt; false, 'message' =&gt; $message];\n        }\n        add_dist_log('\u521b\u5efa\u76ee\u6807\u76ee\u5f55: ' . $target);\n    }\n\n    \/\/ \u6253\u5f00\u6e90\u76ee\u5f55\n    $dir = opendir($source);\n\n    \/\/ \u904d\u5386\u6e90\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\n    while (($file = readdir($dir)) !== false) {\n        if ($file != '.' &amp;&amp; $file != '..') {\n            $srcFile = $source . '\/' . $file;\n            $tarFile = $target . '\/' . $file;\n\n            if (is_dir($srcFile)) {\n                \/\/ \u5982\u679c\u662f\u6587\u4ef6\u5939\uff0c\u9012\u5f52\u590d\u5236\n                $result = copy_dist_folder($srcFile, $tarFile);\n                if (!$result['success']) {\n                    closedir($dir);\n                    return $result;\n                }\n            } else {\n                \/\/ \u5982\u679c\u662f\u6587\u4ef6\uff0c\u590d\u5236\u6587\u4ef6\n                if (!copy($srcFile, $tarFile)) {\n                    $message = '\u9519\u8bef\uff1a\u65e0\u6cd5\u590d\u5236\u6587\u4ef6 ' . $file;\n                    add_dist_log($message);\n                    closedir($dir);\n                    return ['success' =&gt; false, 'message' =&gt; $message];\n                }\n                add_dist_log('\u590d\u5236\u6587\u4ef6: ' . $file);\n            }\n        }\n    }\n\n    \/\/ \u5173\u95ed\u76ee\u5f55\n    closedir($dir);\n\n    $message = '\u6210\u529f\u590d\u5236\u6574\u4e2adist\u6587\u4ef6\u5939';\n    add_dist_log($message);\n    return ['success' =&gt; true, 'message' =&gt; $message];\n}\n\n\/\/ \u6dfb\u52a0\u65e5\u5fd7\u51fd\u6570\nfunction add_dist_log($message) {\n    $log = get_option('dist_copy_log', []);\n    $timestamp = current_time('mysql');\n    $log[] = '[' . $timestamp . '] ' . $message;\n\n    \/\/ \u9650\u5236\u65e5\u5fd7\u6570\u91cf\uff0c\u6700\u591a\u4fdd\u5b5850\u6761\n    if (count($log) &gt; 50) {\n        $log = array_slice($log, -50);\n    }\n\n    update_option('dist_copy_log', $log);\n}\n\n\/\/ \u5728\u63d2\u4ef6\u6fc0\u6d3b\u65f6\u521b\u5efa\u5fc5\u8981\u7684\u6587\u4ef6\u5939\nfunction dist_copy_activation() {\n    $target_path = ABSPATH . 'skin\/wpcss\/';\n    if (!is_dir($target_path)) {\n        wp_mkdir_p($target_path);\n    }\n}\nregister_activation_hook(__FILE__, 'dist_copy_activation');\n\n\/\/ \u6dfb\u52a0\u8bbe\u7f6e\u94fe\u63a5\nfunction dist_copy_plugin_action_links($links) {\n    $settings_link = '&lt;a href=\"' . admin_url('tools.php?page=dist-copy-tool') . '\"&gt;\u8bbe\u7f6e&lt;\/a&gt;';\n    array_unshift($links, $settings_link);\n    return $links;\n}\nadd_filter('plugin_action_links_' . plugin_basename(__FILE__), 'dist_copy_plugin_action_links');<\/code><\/pre><h2 class=\"wp-block-heading\">\u4f7f\u7528\u8bf4\u660e<\/h2><ol class=\"wp-block-list\">\n<li>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u4e3aPHP\u6587\u4ef6\uff08\u4f8b\u5982<code>dist-copy-tool.php<\/code>\uff09\u5e76\u4e0a\u4f20\u5230\u60a8\u7684WordPress\u63d2\u4ef6\u76ee\u5f55<\/li>\n\n\n\n<li>\u5728WordPress\u540e\u53f0\u6fc0\u6d3b\u63d2\u4ef6<\/li>\n\n\n\n<li>\u8bbf\u95ee&#8221;\u5de5\u5177&#8221; -&gt; &#8220;Dist\u590d\u5236\u5de5\u5177&#8221;\u6765\u4f7f\u7528\u8be5\u529f\u80fd<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u529f\u80fd\u8bf4\u660e<\/h2><p>\u8fd9\u4e2a\u5b9e\u73b0\u5305\u62ec\u4ee5\u4e0b\u529f\u80fd\uff1a<\/p><ol class=\"wp-block-list\">\n<li><strong>\u7ba1\u7406\u754c\u9762<\/strong>\uff1a\u5728WordPress\u540e\u53f0\u63d0\u4f9b\u76f4\u89c2\u7684\u64cd\u4f5c\u754c\u9762<\/li>\n\n\n\n<li><strong>\u8def\u5f84\u914d\u7f6e<\/strong>\uff1a\u53ef\u4ee5\u8bbe\u7f6e\u6e90\u8def\u5f84\u548c\u76ee\u6807\u8def\u5f84<\/li>\n\n\n\n<li><strong>\u9012\u5f52\u590d\u5236<\/strong>\uff1a\u5b8c\u6574\u590d\u5236dist\u6587\u4ef6\u5939\u53ca\u5176\u6240\u6709\u5b50\u6587\u4ef6\u5939\u548c\u6587\u4ef6<\/li>\n\n\n\n<li><strong>\u64cd\u4f5c\u65e5\u5fd7<\/strong>\uff1a\u8bb0\u5f55\u6240\u6709\u64cd\u4f5c\u72b6\u6001\u548c\u7ed3\u679c<\/li>\n\n\n\n<li><strong>\u9519\u8bef\u5904\u7406<\/strong>\uff1a\u63d0\u4f9b\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u53cd\u9988<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u4f7f\u7528WordPress\u7684\u5b89\u5168\u51fd\u6570\u548c\u975eces<\/li>\n<\/ol><h2 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h2><ol class=\"wp-block-list\">\n<li>\u786e\u4fdd\u76ee\u6807\u6587\u4ef6\u5939\u6709\u9002\u5f53\u7684\u5199\u5165\u6743\u9650<\/li>\n\n\n\n<li>\u5982\u679cdist\u6587\u4ef6\u5939\u5f88\u5927\uff0c\u590d\u5236\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u8f83\u957f\u65f6\u95f4<\/li>\n\n\n\n<li>\u5728\u67d0\u4e9b\u4e3b\u673a\u73af\u5883\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u589e\u52a0PHP\u7684\u6267\u884c\u65f6\u95f4\u9650\u5236<\/li>\n<\/ol><p>\u8fd9\u4e2a\u5b9e\u73b0\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u529f\u80fd\uff0c\u540c\u65f6\u4fdd\u6301\u4e86\u4ee3\u7801\u7684\u5b89\u5168\u6027\u548c\u53ef\u9760\u6027\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\u6e90\u8def\u5f84\u548c\u76ee\u6807\u8def\u5f84\u7684\u9ed8\u8ba4\u503c\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u6211\u5c06\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e2a\u5b8c\u6574\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u7528\u4e8e\u5728WordPress\u4e3b\u9898\u7684functions.php\u6587\u4ef6\u4e2d\u5b9e\u73b0\u590d\u5236dist\u6587\u4ef6\u5939\u53ca\u5176\u6240\u6709\u6587\u4ef6\u7684\u529f\u80fd\u3002 \u8bbe\u8ba1\u601d\u8def \u4e0b\u9762\u662f\u5b8c\u6574\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a \u4f7f\u7528\u8bf4\u660e \u529f\u80fd\u8bf4\u660e \u8fd9\u4e2a\u5b9e\u73b0\u5305\u62ec\u4ee5\u4e0b\u529f\u80fd\uff1a \u6ce8\u610f\u4e8b\u9879 \u8fd9\u4e2a\u5b9e\u73b0\u63d0\u4f9b\u4e86\u5b8c\u6574\u7684\u529f\u80fd\uff0c\u540c\u65f6\u4fdd\u6301\u4e86\u4ee3\u7801\u7684\u5b89\u5168\u6027\u548c\u53ef\u9760\u6027\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\u6e90\u8def\u5f84\u548c\u76ee\u6807\u8def\u5f84\u7684..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3185],"tags":[],"tuisongtax":[],"class_list":["post-4789","post","type-post","status-publish","format-standard","hentry","category-cjtj"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/4789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=4789"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/4789\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=4789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=4789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=4789"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=4789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}