{"id":4045,"date":"2026-06-05T19:39:15","date_gmt":"2026-06-05T11:39:15","guid":{"rendered":"https:\/\/www.yuan95.cn\/?p=4045"},"modified":"2026-06-30T23:14:10","modified_gmt":"2026-06-30T15:14:10","slug":"wordpress-%e4%bb%a3%e7%a0%81%e5%8f%8a%e6%8c%87%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/www.yuan95.cn\/?p=4045","title":{"rendered":"WordPress \u4ee3\u7801\u53ca\u6307\u4ee4"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>1\u3001WordPress \u7ba1\u7406\u5458\u90ae\u7bb1\u5730\u5740\u66f4\u6362\u64cd\u4f5c\uff0c\u53bb\u6570\u636e\u5e93\u6267\u884c\u6307\u4ee4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE wp_options\nSET option_value = '\u4f60\u7684\u90ae\u7bb1@gmail.com'\nWHERE option_name = 'admin_email';\n\nDELETE FROM wp_options\nWHERE option_name = 'new_admin_email';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2\u3001WordPress\u65b0\u4e0a\u4f20\u56fe\u7247\u4e2d\u6587\u6587\u4ef6\u540d\u81ea\u52a8\u8f6c\u62fc\u97f3\u82f1\u6587<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4e0b\u9762\u4ee3\u7801\u5230\u4e3b\u9898\u6587\u4ef6\u4e2d functions.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u65b0\u4e0a\u4f20\u56fe\u7247\uff1a\u4e2d\u6587\u6587\u4ef6\u540d\u81ea\u52a8\u8f6c\u62fc\u97f3\/\u82f1\u6587 URL\nadd_filter( 'sanitize_file_name', function ( $filename, $filename_raw ) {\n\n    $ext  = strtolower( pathinfo( $filename_raw, PATHINFO_EXTENSION ) );\n    $name = pathinfo( $filename_raw, PATHINFO_FILENAME );\n\n    \/\/ \u9700\u8981\u670d\u52a1\u5668\u5f00\u542f PHP intl \u6269\u5c55\n    if ( function_exists( 'transliterator_transliterate' ) ) {\n        $name = transliterator_transliterate(\n            'Any-Latin; Latin-ASCII; &#91;:Nonspacing Mark:] Remove; Lower()',\n            $name\n        );\n    } else {\n        \/\/ \u5982\u679c\u670d\u52a1\u5668\u6ca1\u6709 intl \u6269\u5c55\uff0c\u5c31\u53bb\u6389\u975e\u82f1\u6587\u5b57\u7b26\n        $name = preg_replace( '\/&#91;^\\x20-\\x7E]\/u', '', $name );\n    }\n\n    $name = strtolower( $name );\n    $name = preg_replace( '\/&#91;^a-z0-9]+\/', '-', $name );\n    $name = trim( $name, '-' );\n\n    if ( $name === '' ) {\n        $name = 'image-' . substr( md5( $filename_raw . microtime() ), 0, 8 );\n    }\n\n    return $ext ? $name . '.' . $ext : $name;\n\n}, 10, 2 );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3\u3001WordPress \u7f51\u7ad9\u540e\u53f0\u589e\u52a0\u7c7b\u4f3c\u6587\u7ae0\u83dc\u5355\u7684\u4ea7\u54c1\u83dc\u5355\u4ee3\u7801<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4e0b\u9762\u4ee3\u7801\u5230\u4e3b\u9898\u6587\u4ef6\u4e2d functions.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6ce8\u518c\u201c\u4ea7\u54c1\u201d\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b + \u201c\u4ea7\u54c1\u5206\u7c7b\u201d\nadd_action('init', function () {\n\n  \/\/ 1) \u6ce8\u518c\u4ea7\u54c1\u5206\u7c7b\uff08\u4ea7\u54c1\u5206\u7c7b\uff09\n  $tax_labels = &#91;\n    'name'              =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n    'singular_name'     =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n    'search_items'      =&gt; '\u641c\u7d22\u4ea7\u54c1\u5206\u7c7b',\n    'all_items'         =&gt; '\u6240\u6709\u4ea7\u54c1\u5206\u7c7b',\n    'parent_item'       =&gt; '\u7236\u7ea7\u4ea7\u54c1\u5206\u7c7b',\n    'parent_item_colon' =&gt; '\u7236\u7ea7\u4ea7\u54c1\u5206\u7c7b\uff1a',\n    'edit_item'         =&gt; '\u7f16\u8f91\u4ea7\u54c1\u5206\u7c7b',\n    'update_item'       =&gt; '\u66f4\u65b0\u4ea7\u54c1\u5206\u7c7b',\n    'add_new_item'      =&gt; '\u65b0\u589e\u4ea7\u54c1\u5206\u7c7b',\n    'new_item_name'     =&gt; '\u65b0\u4ea7\u54c1\u5206\u7c7b\u540d\u79f0',\n    'menu_name'         =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n  ];\n\n  register_taxonomy('product_cat', &#91;'product'], &#91;\n    'hierarchical'      =&gt; true,            \/\/ true = \u7c7b\u4f3c\u5206\u7c7b\uff1bfalse = \u7c7b\u4f3c\u6807\u7b7e\n    'labels'            =&gt; $tax_labels,\n    'show_ui'           =&gt; true,\n    'show_admin_column' =&gt; true,\n    'rewrite' =&gt; &#91;'slug' =&gt; 'products', 'with_front' =&gt; false],\n    'show_in_rest'      =&gt; true,            \/\/ Gutenberg\/REST \u652f\u6301\n  ]);\n\n  \/\/ 2) \u6ce8\u518c\u4ea7\u54c1\uff08\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\uff09\n  $labels = &#91;\n    'name'                  =&gt; '\u4ea7\u54c1',\n    'singular_name'         =&gt; '\u4ea7\u54c1',\n    'menu_name'             =&gt; '\u4ea7\u54c1',\n    'name_admin_bar'        =&gt; '\u4ea7\u54c1',\n    'add_new'               =&gt; '\u65b0\u589e\u4ea7\u54c1',\n    'add_new_item'          =&gt; '\u65b0\u589e\u4ea7\u54c1',\n    'new_item'              =&gt; '\u65b0\u4ea7\u54c1',\n    'edit_item'             =&gt; '\u7f16\u8f91\u4ea7\u54c1',\n    'view_item'             =&gt; '\u67e5\u770b\u4ea7\u54c1',\n    'all_items'             =&gt; '\u6240\u6709\u4ea7\u54c1',\n    'search_items'          =&gt; '\u641c\u7d22\u4ea7\u54c1',\n    'not_found'             =&gt; '\u672a\u627e\u5230\u4ea7\u54c1',\n    'not_found_in_trash'    =&gt; '\u56de\u6536\u7ad9\u4e2d\u672a\u627e\u5230\u4ea7\u54c1',\n  ];\n\n  register_post_type('product', &#91;\n    'labels'             =&gt; $labels,\n    'public'             =&gt; true,                   \/\/ \u524d\u53f0\u53ef\u8bbf\u95ee\n    'show_ui'            =&gt; true,                   \/\/ \u540e\u53f0\u663e\u793a\n    'show_in_menu'       =&gt; true,                   \/\/ \u751f\u6210\u9876\u7ea7\u201c\u4ea7\u54c1\u201d\u83dc\u5355\n    'menu_position'      =&gt; 5,                      \/\/ \u83dc\u5355\u4f4d\u7f6e\uff08\u53ef\u6539\uff09\n    'menu_icon'          =&gt; 'dashicons-cart',       \/\/ \u56fe\u6807\uff08\u53ef\u6539\uff09\n    'supports'           =&gt; &#91;'title','editor','thumbnail','excerpt'],\n    'has_archive'        =&gt; true,\n    'rewrite'            =&gt; &#91;'slug' =&gt; 'product'],\n    'taxonomies'         =&gt; &#91;'product_cat'],        \/\/ \u5173\u8054\u4ea7\u54c1\u5206\u7c7b\n    'show_in_rest'       =&gt; true,                   \/\/ Gutenberg\/REST \u652f\u6301\n  ]);\n\n}, 0);\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress\u540e\u53f0\u65b0\u589e\u4ea7\u54c1\u529f\u80fd\u83dc\u5355\u4ee3\u7801 <strong> <\/strong>\u4e8c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * \u6ce8\u518c\u201c\u4ea7\u54c1\u201d\u83dc\u5355\n *\/\nadd_action('init', 'zc_register_product_post_type');\n\nfunction zc_register_product_post_type() {\n\n    register_post_type('product', array(\n        'labels' =&gt; array(\n            'name'               =&gt; '\u4ea7\u54c1',\n            'singular_name'      =&gt; '\u4ea7\u54c1',\n            'menu_name'          =&gt; '\u4ea7\u54c1',\n            'all_items'          =&gt; '\u6240\u6709\u4ea7\u54c1',\n            'add_new'            =&gt; '\u65b0\u589e\u4ea7\u54c1',\n            'add_new_item'       =&gt; '\u65b0\u589e\u4ea7\u54c1',\n            'edit_item'          =&gt; '\u7f16\u8f91\u4ea7\u54c1',\n            'new_item'           =&gt; '\u65b0\u4ea7\u54c1',\n            'view_item'          =&gt; '\u67e5\u770b\u4ea7\u54c1',\n            'search_items'       =&gt; '\u641c\u7d22\u4ea7\u54c1',\n            'not_found'          =&gt; '\u6ca1\u6709\u627e\u5230\u4ea7\u54c1',\n            'not_found_in_trash' =&gt; '\u56de\u6536\u7ad9\u4e2d\u6ca1\u6709\u4ea7\u54c1',\n        ),\n        'public'        =&gt; true,\n        'show_ui'       =&gt; true,\n        'show_in_menu'  =&gt; true,\n        'menu_position' =&gt; 6,\n        'menu_icon'     =&gt; 'dashicons-cart',\n        'supports'      =&gt; array(\n            'title',\n            'editor',\n            'thumbnail',\n            'excerpt',\n            'custom-fields'\n        ),\n        'has_archive'   =&gt; true,\n        'rewrite'       =&gt; array(\n            'slug' =&gt; 'products'\n        ),\n        'show_in_rest'  =&gt; true,\n    ));\n\n    \/**\n     * \u4ea7\u54c1\u5206\u7c7b\n     *\/\n    register_taxonomy('product_category', array('product'), array(\n        'labels' =&gt; array(\n            'name'              =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n            'singular_name'     =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n            'menu_name'         =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n            'all_items'         =&gt; '\u6240\u6709\u4ea7\u54c1\u5206\u7c7b',\n            'edit_item'         =&gt; '\u7f16\u8f91\u4ea7\u54c1\u5206\u7c7b',\n            'update_item'       =&gt; '\u66f4\u65b0\u4ea7\u54c1\u5206\u7c7b',\n            'add_new_item'      =&gt; '\u65b0\u589e\u4ea7\u54c1\u5206\u7c7b',\n            'new_item_name'     =&gt; '\u65b0\u4ea7\u54c1\u5206\u7c7b\u540d\u79f0',\n            'search_items'      =&gt; '\u641c\u7d22\u4ea7\u54c1\u5206\u7c7b',\n        ),\n        'hierarchical'      =&gt; true,\n        'show_ui'           =&gt; true,\n        'show_admin_column' =&gt; true,\n        'show_in_rest'      =&gt; true,\n        'rewrite'           =&gt; array(\n            'slug' =&gt; 'product-category'\n        ),\n    ));\n\n    \/**\n     * \u4ea7\u54c1\u6807\u7b7e\n     *\/\n    register_taxonomy('product_tag', array('product'), array(\n        'labels' =&gt; array(\n            'name'                       =&gt; '\u4ea7\u54c1\u6807\u7b7e',\n            'singular_name'              =&gt; '\u4ea7\u54c1\u6807\u7b7e',\n            'menu_name'                  =&gt; '\u4ea7\u54c1\u6807\u7b7e',\n            'all_items'                  =&gt; '\u6240\u6709\u4ea7\u54c1\u6807\u7b7e',\n            'edit_item'                  =&gt; '\u7f16\u8f91\u4ea7\u54c1\u6807\u7b7e',\n            'update_item'                =&gt; '\u66f4\u65b0\u4ea7\u54c1\u6807\u7b7e',\n            'add_new_item'               =&gt; '\u65b0\u589e\u4ea7\u54c1\u6807\u7b7e',\n            'new_item_name'              =&gt; '\u65b0\u4ea7\u54c1\u6807\u7b7e\u540d\u79f0',\n            'search_items'               =&gt; '\u641c\u7d22\u4ea7\u54c1\u6807\u7b7e',\n            'popular_items'              =&gt; '\u70ed\u95e8\u4ea7\u54c1\u6807\u7b7e',\n            'separate_items_with_commas' =&gt; '\u591a\u4e2a\u6807\u7b7e\u8bf7\u7528\u82f1\u6587\u9017\u53f7\u5206\u9694',\n        ),\n        'hierarchical'      =&gt; false,\n        'show_ui'           =&gt; true,\n        'show_admin_column' =&gt; true,\n        'show_in_rest'      =&gt; true,\n        'rewrite'           =&gt; array(\n            'slug' =&gt; 'product-tag'\n        ),\n    ));\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f5c\u4e3a\u72ec\u7acb\u63d2\u4ef6\u4f7f\u7528\u3002\u65b0\u5efa\u6587\u4ef6\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/wp-content\/plugins\/custom-products\/custom-products.php<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7c98\u8d34\u4ee5\u4e0b\u5b8c\u6574\u4ee3\u7801\u540e\uff0c\u5230\u540e\u53f0\u201c\u63d2\u4ef6\u201d\u542f\u7528\u5373\u53ef\u3002\u6fc0\u6d3b\u65f6\u4f1a\u6ce8\u518c\u4ea7\u54c1\u7c7b\u578b\u548c\u5206\u7c7b\uff0c\u5e76\u5237\u65b0\u56fa\u5b9a\u94fe\u63a5\u89c4\u5219\uff1b\u505c\u7528\u65f6\u53ea\u79fb\u9664\u89c4\u5219\uff0c\u4e0d\u5220\u9664\u5df2\u5f55\u5165\u7684\u4ea7\u54c1\u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Plugin Name: \u81ea\u5b9a\u4e49\u4ea7\u54c1\u7ba1\u7406\n * Description: \u6ce8\u518c\u201c\u4ea7\u54c1\u201d\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u548c\u201c\u4ea7\u54c1\u5206\u7c7b\u201d\u5c42\u7ea7\u5206\u7c7b\u6cd5\u3002\n * Version: 1.0.0\n * Author: Your Company\n *\/\n\nif ( ! defined( 'ABSPATH' ) ) {\n\texit;\n}\n\n\/**\n * \u6ce8\u518c\u4ea7\u54c1\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\u53ca\u4ea7\u54c1\u5206\u7c7b\u3002\n *\/\nfunction mysite_register_products() {\n\n\t\/**\n\t * 1. \u6ce8\u518c\u201c\u4ea7\u54c1\u201d\u81ea\u5b9a\u4e49\u6587\u7ae0\u7c7b\u578b\n\t *\/\n\t$product_labels = array(\n\t\t'name'                  =&gt; '\u4ea7\u54c1',\n\t\t'singular_name'         =&gt; '\u4ea7\u54c1',\n\t\t'menu_name'             =&gt; '\u4ea7\u54c1',\n\t\t'name_admin_bar'        =&gt; '\u4ea7\u54c1',\n\t\t'add_new'               =&gt; '\u65b0\u589e\u4ea7\u54c1',\n\t\t'add_new_item'          =&gt; '\u65b0\u589e\u4ea7\u54c1',\n\t\t'new_item'              =&gt; '\u65b0\u4ea7\u54c1',\n\t\t'edit_item'             =&gt; '\u7f16\u8f91\u4ea7\u54c1',\n\t\t'view_item'             =&gt; '\u67e5\u770b\u4ea7\u54c1',\n\t\t'all_items'             =&gt; '\u6240\u6709\u4ea7\u54c1',\n\t\t'search_items'          =&gt; '\u641c\u7d22\u4ea7\u54c1',\n\t\t'parent_item_colon'     =&gt; '\u7236\u7ea7\u4ea7\u54c1\uff1a',\n\t\t'not_found'             =&gt; '\u672a\u627e\u5230\u4ea7\u54c1',\n\t\t'not_found_in_trash'    =&gt; '\u56de\u6536\u7ad9\u4e2d\u672a\u627e\u5230\u4ea7\u54c1',\n\t\t'featured_image'        =&gt; '\u4ea7\u54c1\u4e3b\u56fe',\n\t\t'set_featured_image'    =&gt; '\u8bbe\u7f6e\u4ea7\u54c1\u4e3b\u56fe',\n\t\t'remove_featured_image' =&gt; '\u79fb\u9664\u4ea7\u54c1\u4e3b\u56fe',\n\t\t'use_featured_image'    =&gt; '\u7528\u4f5c\u4ea7\u54c1\u4e3b\u56fe',\n\t\t'archives'              =&gt; '\u4ea7\u54c1\u5f52\u6863',\n\t\t'insert_into_item'      =&gt; '\u63d2\u5165\u5230\u4ea7\u54c1',\n\t\t'uploaded_to_this_item' =&gt; '\u4e0a\u4f20\u5230\u6b64\u4ea7\u54c1',\n\t\t'filter_items_list'     =&gt; '\u7b5b\u9009\u4ea7\u54c1\u5217\u8868',\n\t\t'items_list_navigation' =&gt; '\u4ea7\u54c1\u5217\u8868\u5bfc\u822a',\n\t\t'items_list'            =&gt; '\u4ea7\u54c1\u5217\u8868',\n\t);\n\n\tregister_post_type(\n\t\t'product',\n\t\tarray(\n\t\t\t'labels'              =&gt; $product_labels,\n\t\t\t'public'              =&gt; true,\n\t\t\t'publicly_queryable'  =&gt; true,\n\t\t\t'show_ui'             =&gt; true,\n\t\t\t'show_in_menu'        =&gt; true,\n\t\t\t'show_in_admin_bar'   =&gt; true,\n\t\t\t'show_in_nav_menus'   =&gt; true,\n\n\t\t\t'menu_position'       =&gt; 5,\n\t\t\t'menu_icon'           =&gt; 'dashicons-cart',\n\n\t\t\t'hierarchical'        =&gt; false,\n\t\t\t'capability_type'     =&gt; 'post',\n\t\t\t'map_meta_cap'        =&gt; true,\n\n\t\t\t'supports'            =&gt; array(\n\t\t\t\t'title',\n\t\t\t\t'editor',\n\t\t\t\t'thumbnail',\n\t\t\t\t'excerpt',\n\t\t\t\t'revisions',\n\t\t\t\t'custom-fields',\n\t\t\t),\n\n\t\t\t\/\/ \u4ea7\u54c1\u5f52\u6863\u9875\uff1a\/product\/\n\t\t\t'has_archive'         =&gt; 'product',\n\n\t\t\t\/\/ \u4ea7\u54c1\u8be6\u60c5\u9875\uff1a\/product\/\u4ea7\u54c1\u522b\u540d\/\n\t\t\t'rewrite'             =&gt; array(\n\t\t\t\t'slug'       =&gt; 'product',\n\t\t\t\t'with_front' =&gt; false,\n\t\t\t\t'feeds'      =&gt; true,\n\t\t\t\t'pages'      =&gt; true,\n\t\t\t),\n\n\t\t\t'query_var'           =&gt; true,\n\t\t\t'can_export'          =&gt; true,\n\t\t\t'delete_with_user'    =&gt; false,\n\n\t\t\t\/\/ Gutenberg \u4e0e REST API\n\t\t\t'show_in_rest'        =&gt; true,\n\t\t\t'rest_base'           =&gt; 'products',\n\n\t\t\t\/\/ \u5173\u8054\u4ea7\u54c1\u5206\u7c7b\n\t\t\t'taxonomies'          =&gt; array( 'product_cat' ),\n\t\t)\n\t);\n\n\t\/**\n\t * 2. \u6ce8\u518c\u201c\u4ea7\u54c1\u5206\u7c7b\u201d\n\t *\/\n\t$product_cat_labels = array(\n\t\t'name'                       =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n\t\t'singular_name'              =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n\t\t'search_items'               =&gt; '\u641c\u7d22\u4ea7\u54c1\u5206\u7c7b',\n\t\t'popular_items'              =&gt; '\u70ed\u95e8\u4ea7\u54c1\u5206\u7c7b',\n\t\t'all_items'                  =&gt; '\u6240\u6709\u4ea7\u54c1\u5206\u7c7b',\n\t\t'parent_item'                =&gt; '\u7236\u7ea7\u4ea7\u54c1\u5206\u7c7b',\n\t\t'parent_item_colon'          =&gt; '\u7236\u7ea7\u4ea7\u54c1\u5206\u7c7b\uff1a',\n\t\t'edit_item'                  =&gt; '\u7f16\u8f91\u4ea7\u54c1\u5206\u7c7b',\n\t\t'view_item'                  =&gt; '\u67e5\u770b\u4ea7\u54c1\u5206\u7c7b',\n\t\t'update_item'                =&gt; '\u66f4\u65b0\u4ea7\u54c1\u5206\u7c7b',\n\t\t'add_new_item'               =&gt; '\u65b0\u589e\u4ea7\u54c1\u5206\u7c7b',\n\t\t'new_item_name'              =&gt; '\u65b0\u4ea7\u54c1\u5206\u7c7b\u540d\u79f0',\n\t\t'separate_items_with_commas' =&gt; '\u7528\u9017\u53f7\u5206\u9694\u4ea7\u54c1\u5206\u7c7b',\n\t\t'add_or_remove_items'        =&gt; '\u6dfb\u52a0\u6216\u79fb\u9664\u4ea7\u54c1\u5206\u7c7b',\n\t\t'choose_from_most_used'      =&gt; '\u4ece\u5e38\u7528\u4ea7\u54c1\u5206\u7c7b\u4e2d\u9009\u62e9',\n\t\t'not_found'                  =&gt; '\u672a\u627e\u5230\u4ea7\u54c1\u5206\u7c7b',\n\t\t'no_terms'                   =&gt; '\u6682\u65e0\u4ea7\u54c1\u5206\u7c7b',\n\t\t'filter_by_item'             =&gt; '\u6309\u4ea7\u54c1\u5206\u7c7b\u7b5b\u9009',\n\t\t'items_list_navigation'      =&gt; '\u4ea7\u54c1\u5206\u7c7b\u5217\u8868\u5bfc\u822a',\n\t\t'items_list'                 =&gt; '\u4ea7\u54c1\u5206\u7c7b\u5217\u8868',\n\t\t'menu_name'                  =&gt; '\u4ea7\u54c1\u5206\u7c7b',\n\t);\n\n\tregister_taxonomy(\n\t\t'product_cat',\n\t\tarray( 'product' ),\n\t\tarray(\n\t\t\t'labels'             =&gt; $product_cat_labels,\n\n\t\t\t'public'             =&gt; true,\n\t\t\t'publicly_queryable' =&gt; true,\n\t\t\t'hierarchical'       =&gt; true,\n\n\t\t\t'show_ui'            =&gt; true,\n\t\t\t'show_admin_column'  =&gt; true,\n\t\t\t'show_in_nav_menus'  =&gt; true,\n\t\t\t'show_tagcloud'      =&gt; false,\n\n\t\t\t'query_var'          =&gt; true,\n\n\t\t\t\/\/ \u5206\u7c7b\u9875\uff1a\/products\/\u5206\u7c7b\u522b\u540d\/\n\t\t\t\/\/ \u5b50\u5206\u7c7b\u9875\uff1a\/products\/\u7236\u5206\u7c7b\/\u5b50\u5206\u7c7b\/\n\t\t\t'rewrite'            =&gt; array(\n\t\t\t\t'slug'         =&gt; 'products',\n\t\t\t\t'with_front'   =&gt; false,\n\t\t\t\t'hierarchical' =&gt; true,\n\t\t\t),\n\n\t\t\t\/\/ Gutenberg \u4e0e REST API\n\t\t\t'show_in_rest'       =&gt; true,\n\t\t\t'rest_base'          =&gt; 'product-categories',\n\t\t)\n\t);\n\n\t\/\/ \u786e\u4fdd\u5206\u7c7b\u6cd5\u4e0e\u4ea7\u54c1\u7c7b\u578b\u7ed1\u5b9a\u3002\n\tregister_taxonomy_for_object_type( 'product_cat', 'product' );\n}\n\nadd_action( 'init', 'mysite_register_products', 0 );\n\n\/**\n * \u63d2\u4ef6\u542f\u7528\uff1a\u6ce8\u518c\u5185\u5bb9\u7c7b\u578b\u540e\u5237\u65b0\u56fa\u5b9a\u94fe\u63a5\u3002\n *\/\nfunction mysite_products_activate() {\n\tmysite_register_products();\n\tflush_rewrite_rules();\n}\n\nregister_activation_hook( __FILE__, 'mysite_products_activate' );\n\n\/**\n * \u63d2\u4ef6\u505c\u7528\uff1a\u79fb\u9664\u5f53\u524d\u8bf7\u6c42\u4e2d\u7684\u6ce8\u518c\u89c4\u5219\u5e76\u5237\u65b0\u56fa\u5b9a\u94fe\u63a5\u3002\n * \u4e0d\u5220\u9664\u4ea7\u54c1\u3001\u5206\u7c7b\u3001\u56fe\u7247\u6216\u81ea\u5b9a\u4e49\u5b57\u6bb5\u6570\u636e\u3002\n *\/\nfunction mysite_products_deactivate() {\n\tunregister_taxonomy( 'product_cat' );\n\tunregister_post_type( 'product' );\n\n\tflush_rewrite_rules();\n}\n\nregister_deactivation_hook( __FILE__, 'mysite_products_deactivate' );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4\u3001\u9690\u85cf\u540e\u53f0\u767b\u5f55\u5165\u53e3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4e0b\u9762\u4ee3\u7801\u5230\u4e3b\u9898\u6587\u4ef6\u4e2d functions.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee3\u7801\u4e00<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \/\/\u4fdd\u62a4\u540e\u53f0\u767b\u5f55\nadd_action('login_enqueue_scripts','login_protection');  \nfunction login_protection(){\n    \/\/Location\u540e\u6539\u6210\u4f60\u7684\u7ad9\u70b9,xx\u548cxxx\u53ef\u81ea\u5b9a\u4e49\n    if($_GET&#91;'ldl'] != 'yuan95')header('Location: https:\/\/www.yuan95.cn\/');  \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u53f0\u767b\u5165\u5730\u5740\u5e94\u5f53\u662f\uff1ahttps:\/\/www.yuan95.cn\/wp-login.php?ldl=yuan95<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee3\u7801\u4e8c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ yuan95\nadd_action('login_enqueue_scripts', 'tb_wp_login_protection');\nfunction tb_wp_login_protection(){\n    if( !isset($_GET&#91;'yuan95']) ){\n        header( 'Location: ' . home_url() );\n        exit;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>yuan95<\/code>&nbsp;\u6539\u6210\u4f60\u9700\u8981\u7684\u5b57\u7b26\uff0c\u4e4b\u540e\u767b\u5f55\u7684\u5730\u5740\u4fbf\u662f\uff1a\u7f51\u7ad9\u57df\u540d\/wp-login.php?yuan95\uff0c\u6216\u8005\u662f\uff1a\u7f51\u7ad9\u57df\u540d\/wp-admin?yuan95<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e0d\u6309\u7167\u4ee5\u4e0a\u5730\u5740\u8bbf\u95ee\uff0c\u5c06\u76f4\u63a5\u8df3\u8f6c\u5230\u7f51\u7ad9\u9996\u9875\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5\u3001WordPress \u5f7b\u5e95\u5173\u95ed\u81ea\u52a8\u66f4\u65b0\u548c\u66f4\u65b0\u68c0\u67e5\u529f\u80fd<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539 wp-config.php \u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7981\u7528\u6240\u6709\u81ea\u52a8\u66f4\u65b0\ndefine('AUTOMATIC_UPDATER_DISABLED', true);\n\/\/ \u7981\u7528\u6838\u5fc3\u66f4\u65b0\ndefine('WP_AUTO_UPDATE_CORE', false);\n\/\/ \u7981\u7528\u540e\u53f0\u66f4\u65b0\u68c0\u67e5\ndefine('DISABLE_WP_CRON', true);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6\u3001WordPress \u5b8c\u5168\u7981\u7528 RSS Feed \u7684\u6700\u4f73\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee5\u4e0b\u4ee3\u7801\u5230\u4e3b\u9898\u76ee\u5f55\u4e0b\u7684 functions.php \u6587\u4ef6\u4e2d\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u79fb\u9664 feed \u94fe\u63a5\nremove_action('wp_head', 'feed_links_extra', 3);\nremove_action('wp_head', 'feed_links', 2);\n\n\/\/ \u7981\u7528 feed\nfunction tb_disable_all_feeds() {\n    wp_die('RSS feeds \u5df2\u88ab\u7981\u7528\u3002');\n}\nadd_action('do_feed', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_rdf', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_rss', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_rss2', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_atom', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_rss2_comments', 'tb_disable_all_feeds', 1);\nadd_action('do_feed_atom_comments', 'tb_disable_all_feeds', 1);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>7\u3001WordPress \u7981\u6b62\u81ea\u52a8\u88c1\u526a\u751f\u6210 \u56fe\u7247\u7684\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\uff09\u7b2c\u4e00\u6b65\uff1a\u540e\u53f0-\u8bbe\u7f6e-\u5a92\u4f53\uff0c\u7f29\u7565\u56fe\u7684\u5c3a\u5bf8\u8bbe\u7f6e\u5c3a\u5bf8\u4e3a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\uff09\u7b2c\u4e8c\u6b65\uff1a\u4e3b\u9898\u6587\u4ef6 functions.php \u4e2d\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u79fb\u9664\u591a\u4f59\u7684\u56fe\u7247\u5c3a\u5bf8\nadd_filter('intermediate_image_sizes_advanced', 'filter_image_sizes');\nfunction filter_image_sizes($sizes) {\n    if (isset($sizes&#91;'medium_large'])) {\n        unset($sizes&#91;'medium_large']);\n    }\n    if (isset($sizes&#91;'1536x1536'])) {\n        unset($sizes&#91;'1536x1536']);\n    }\n    if (isset($sizes&#91;'2048x2048'])) {\n        unset($sizes&#91;'2048x2048']);\n    }\n    return $sizes;\n}\n\n\/\/ \u7981\u6b62\u88c1\u526a -scaled \u56fe\u7247\nadd_filter('big_image_size_threshold', '__return_false');\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">PS. \u4ee5\u4e0a\u65b9\u6cd5\u4ec5\u5bf9\u8bbe\u7f6e\u540e\u4e0a\u4f20\u7684\u56fe\u7247\u6709\u6548\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>8\u3001WordPress\u4e0a\u4f20\u56fe\u7247\u6216\u6587\u4ef6\u81ea\u52a8\u91cd\u547d\u540d\u7684\u65b9\u6cd5<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5236\u4ee5\u4e0b\u4ee3\u7801\u5230\u4e3b\u9898\u7684 functions.php \u6587\u4ef6\u6700\u540e\u5373\u53ef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e00\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ WordPress\u4e0a\u4f20\u56fe\u7247\u6216\u6587\u4ef6\u81ea\u52a8\u91cd\u547d\u540d\u7684\u65b9\u6cd5\nadd_filter('sanitize_file_name', 'tbwp_new_filename', 10);\nfunction tbwp_new_filename($filename) {\n    $info = pathinfo($filename);\n    $ext = empty($info&#91;'extension']) ? '' : '.' . $info&#91;'extension'];\n    $name = basename($filename, $ext);\n    return substr(md5($name), 0, 15) . $ext;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e8c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4e0a\u4f20\u5a92\u4f53\u65f6\u81ea\u52a8\u91cd\u547d\u540d\uff0c\u907f\u514d\u4e2d\u6587\u6587\u4ef6\u540d\nadd_filter('wp_handle_upload_prefilter', 'custom_rename_uploaded_image');\n\nfunction custom_rename_uploaded_image($file) {\n    $ext = pathinfo($file&#91;'name'], PATHINFO_EXTENSION);\n\n    \/\/ \u53ea\u5904\u7406\u56fe\u7247\uff0c\u53ef\u6309\u9700\u589e\u52a0\u683c\u5f0f\n    $allowed_exts = array('jpg', 'jpeg', 'png', 'gif', 'webp', 'avif');\n\n    if (!in_array(strtolower($ext), $allowed_exts, true)) {\n        return $file;\n    }\n\n    \/\/ \u751f\u6210\u82f1\u6587\/\u6570\u5b57\u6587\u4ef6\u540d\uff1aimg-\u65f6\u95f4\u6233-\u968f\u673a\u6570.jpg\n    $new_name = 'img-' . date('Ymd-His') . '-' . wp_generate_password(6, false, false);\n\n    $file&#91;'name'] = strtolower($new_name . '.' . $ext);\n\n    return $file;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001WordPress \u7ba1\u7406\u5458\u90ae\u7bb1\u5730\u5740\u66f4\u6362\u64cd\u4f5c\uff0c\u53bb\u6570\u636e\u5e93\u6267\u884c\u6307\u4ee4 2\u3001WordPress\u65b0\u4e0a\u4f20\u56fe\u7247\u4e2d\u6587\u6587\u4ef6\u540d\u81ea\u52a8\u8f6c\u62fc\u97f3\u82f1\u6587 \u590d\u5236\u4e0b\u9762\u4ee3\u7801\u5230\u4e3b\u9898\u6587\u4ef6\u4e2d functions.php 3\u3001WordPress \u7f51\u7ad9\u540e\u53f0\u589e\u52a0\u7c7b\u4f3c\u6587\u7ae0\u83dc\u5355\u7684\u4ea7\u54c1\u83dc\u5355\u4ee3\u7801&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[133],"topic":[],"class_list":["post-4045","post","type-post","status-publish","format-standard","hentry","category-jingyan","tag-daima"],"_links":{"self":[{"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/posts\/4045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4045"}],"version-history":[{"count":16,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/posts\/4045\/revisions"}],"predecessor-version":[{"id":4100,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=\/wp\/v2\/posts\/4045\/revisions\/4100"}],"wp:attachment":[{"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4045"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yuan95.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=4045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}