{"id":177,"date":"2023-07-22T21:46:32","date_gmt":"2023-07-22T13:46:32","guid":{"rendered":"https:\/\/blog.n-bc.top\/?p=177"},"modified":"2023-07-22T21:46:32","modified_gmt":"2023-07-22T13:46:32","slug":"%e7%94%a8chatgpt%e4%bc%98%e5%8c%96wordpress%ef%bc%9a%e4%bb%96%e7%9c%9f%e7%9a%84%ef%bc%8c%e6%88%91%e5%93%ad%e6%ad%bb","status":"publish","type":"post","link":"https:\/\/www.n-bc.top\/?p=177","title":{"rendered":"\u7528ChatGPT\u4f18\u5316wordpress\uff1a\u4ed6\u771f\u7684\uff0c\u6211\u54ed\u6b7b"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\"><strong>\u95ee\u9898\u554a\u554a\u554a\u554a\u554a\u554a<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u7ed9\u6211\u5199\u4e00\u4e2awordpress\u63d2\u4ef6\uff0c\u5b83\u53ef\u4ee5\u4e3a\u6211\u7684\u7f51\u7ad9\u751f\u6210\u9759\u6001html\u8fdb\u884c\u8bbf\u95ee\uff0c\u540c\u65f6\u767b\u5f55\u7528\u6237\u4e0d\u4f1a\u901a\u8fc7\u7f13\u5b58\u8bbf\u95ee\uff0c\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5220\u9664\u65e7\u7684\u7f13\u5b58<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Chat GPT\u7684\u56de\u7b54<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/*\nPlugin Name: Static HTML Generator\nDescription: Generates static HTML for your website and deletes old cache periodically\nVersion: 1.0\nAuthor: Your Name\n*\/\n\n\/\/ Define constants for the plugin\ndefine( 'STATIC_HTML_GENERATOR_CACHE_DIR', WP_CONTENT_DIR . '\/cache\/static-html-generator\/' ); \/\/ Directory to store cache files\ndefine( 'STATIC_HTML_GENERATOR_CACHE_TIME', 3600 ); \/\/ Cache time in seconds, default is 1 hour\n\n\/\/ Register activation and deactivation hooks\nregister_activation_hook( __FILE__, 'static_html_generator_activate' );\nregister_deactivation_hook( __FILE__, 'static_html_generator_deactivate' );\n\n\/\/ Activate the plugin\nfunction static_html_generator_activate() {\n\/\/ Create cache directory\nif ( ! file_exists( STATIC_HTML_GENERATOR_CACHE_DIR ) ) {\nwp_mkdir_p( STATIC_HTML_GENERATOR_CACHE_DIR );\n}\n}\n\n\/\/ Deactivate the plugin\nfunction static_html_generator_deactivate() {\n\/\/ Remove cache directory and all its contents\nstatic_html_generator_rrmdir( STATIC_HTML_GENERATOR_CACHE_DIR );\n}\n\n\/\/ Remove directory and all its contents recursively\nfunction static_html_generator_rrmdir( $dir ) {\nif ( is_dir( $dir ) ) {\n$objects = scandir( $dir );\nforeach ( $objects as $object ) {\nif ( $object != '.' &amp;&amp; $object != '..' ) {\nif ( is_dir( $dir . '\/' . $object ) ) {\nstatic_html_generator_rrmdir( $dir . '\/' . $object );\n} else {\nunlink( $dir . '\/' . $object );\n}\n}\n}\nrmdir( $dir );\n}\n}\n\n\/\/ Generate static HTML for the current page\nfunction static_html_generator_generate() {\n\/\/ Check if user is logged in\nif ( is_user_logged_in() ) {\nreturn; \/\/ Do not generate static HTML for logged in users\n}\n\n\/\/ Generate cache file name\n$cache_file = STATIC_HTML_GENERATOR_CACHE_DIR . md5( get_permalink() ) . '.html';\n\n\/\/ Check if cache file exists and is not expired\nif ( file_exists( $cache_file ) &amp;&amp; ( time() - filemtime( $cache_file ) ) &lt; STATIC_HTML_GENERATOR_CACHE_TIME ) {\n\/\/ Serve cache file and exit\nreadfile( $cache_file );\nexit();\n}\n\n\/\/ Start output buffering\nob_start();\n\n\/\/ Generate HTML for the current page\nget_header();\nif ( have_posts() ) {\nwhile ( have_posts() ) {\nthe_post();\nthe_content();\n}\n}\nget_footer();\n\n\/\/ Write output buffer to cache file\nfile_put_contents( $cache_file, ob_get_contents() );\n\n\/\/ End output buffering\nob_end_flush();\n}\n\n\/\/ Hook into WordPress to generate static HTML\nadd_action( 'wp', 'static_html_generator_generate' );\n\n\/\/ Schedule a daily event to delete old cache files\nadd_action( 'static_html_generator_delete_cache', 'static_html_generator_delete_cache' );\nif ( ! wp_next_scheduled( 'static_html_generator_delete_cache' ) ) {\nwp_schedule_event( time(), 'daily', 'static_html_generator_delete_cache' );\n}\n\n\/\/ Delete old cache files\nfunction static_html_generator_delete_cache() {\n$cache_files = glob( STATIC_HTML_GENERATOR_CACHE_DIR . '*.html' );\nforeach ( $cache_files as $cache_file ) {\nif ( filemtime( $cache_file ) &lt; ( time() - STATIC_HTML_GENERATOR_CACHE_TIME ) ) {\nunlink( $cache_file );\n}\n}\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u9644\u8bed\uff1a<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u63d2\u4ef6\u7684\u529f\u80fd\u5f88\u7b80\u5355\uff0c\u5b83\u4f1a\u5728\u7528\u6237\u8bbf\u95ee\u60a8\u7684\u7f51\u7ad9\u65f6\u751f\u6210\u9759\u6001HTML\uff0c\u5e76\u5c06\u5176\u7f13\u5b58\u5230\u672c\u5730\u6587\u4ef6\u4e2d\u3002\u5982\u679c\u7528\u6237\u5df2\u767b\u5f55\uff0c\u5219\u4f1a\u8df3\u8fc7\u9759\u6001HTML\u751f\u6210\uff0c\u5e76\u76f4\u63a5\u8bbf\u95ee\u52a8\u6001\u9875\u9762\u3002\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\uff0c\u8be5\u63d2\u4ef6\u4f1a\u5220\u9664\u65e7\u7684\u7f13\u5b58\u6587\u4ef6\uff0c\u4ee5\u786e\u4fdd\u60a8\u7684\u7f51\u7ad9\u4fdd\u6301\u6700\u65b0\u72b6\u6001\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u6211\u81ea\u5df1\u5199\u5f97\u597d\u591a\u4e86\uff0c\u4e0d\u8fc7\u9700\u8981\u6839\u636e\u4e3b\u9898\u8c03\u6574\u3002\u5b83\u771f\u7684\uff0c\u6211\u54ed\u6b7b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u554a\u554a\u554a\u554a\u554a\u554a \u8bf7\u7ed9\u6211\u5199\u4e00\u4e2awordpress\u63d2\u4ef6\uff0c\u5b83\u53ef\u4ee5\u4e3a\u6211\u7684\u7f51\u7ad9\u751f\u6210\u9759\u6001html\u8fdb\u884c\u8bbf\u95ee\uff0c\u540c\u65f6\u767b\u5f55\u7528\u6237\u4e0d\u4f1a\u901a\u8fc7\u7f13\u5b58\u8bbf\u95ee\uff0c\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5220\u9664\u65e7\u7684\u7f13\u5b58 Chat GPT\u7684\u56de\u7b54 \u9644\u8bed\uff1a \u8fd9\u4e2a\u63d2\u4ef6\u7684\u529f\u80fd\u5f88\u7b80\u5355\uff0c\u5b83\u4f1a\u5728\u7528\u6237\u8bbf\u95ee\u60a8\u7684\u7f51\u7ad9\u65f6\u751f\u6210\u9759\u6001HTML\uff0c\u5e76\u5c06\u5176\u7f13\u5b58\u5230\u672c\u5730\u6587\u4ef6\u4e2d\u3002\u5982\u679c\u7528\u6237\u5df2\u767b\u5f55\uff0c\u5219\u4f1a\u8df3\u8fc7\u9759\u6001HTML\u751f\u6210\uff0c\u5e76\u76f4\u63a5\u8bbf\u95ee\u52a8\u6001\u9875\u9762\u3002\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\uff0c\u8be5\u63d2\u4ef6\u4f1a\u5220\u9664\u65e7\u7684\u7f13\u5b58\u6587\u4ef6\uff0c\u4ee5\u786e\u4fdd\u60a8\u7684\u7f51\u7ad9\u4fdd\u6301\u6700\u65b0\u72b6\u6001\u3002 \u6bd4\u6211\u81ea\u5df1\u5199\u5f97\u597d\u591a\u4e86\uff0c\u4e0d\u8fc7\u9700\u8981\u6839\u636e\u4e3b\u9898\u8c03\u6574\u3002\u5b83\u771f\u7684\uff0c\u6211\u54ed\u6b7b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-177","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/www.n-bc.top\/index.php?rest_route=\/wp\/v2\/posts\/177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.n-bc.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.n-bc.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.n-bc.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.n-bc.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=177"}],"version-history":[{"count":0,"href":"https:\/\/www.n-bc.top\/index.php?rest_route=\/wp\/v2\/posts\/177\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.n-bc.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.n-bc.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.n-bc.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}