WordPress Development Guide

WordPress 开发指引



curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

WP CLI 安装完后,oh-my-zsh 用户可以激活相关插件plugins=(wp-cli git [...]),获得命令行补全功能。 

常用命令 作用
wp --info
wp cli update 升级 WP CLI
wp core version 确认 WordPress 版本

安装 WordPress

# download wordpress source code in working directory
wp core download --version 5.9

# generate config file
wp config create --dbname=wp_5.9 --dbuser=root --prompt=dbpass --dbhost=HOST

wp db create

wp core install --url=wp-5.9.x.local --title="wp-5.9.x" --admin_user=root --admin_password=root --admin_email=root@wp-5.9.x.local

升级 WordPress

wp core update --version=5.9.3
wp core update-db


名称 说明
bootscore 父主题含 Bootstrap 支持,fork bootscore-child 添加网站样式制作子主题,Sass 支持


PhpStorm File Watch 配置

bootscore 自带 sass 支持,编译较慢时可配置 IDE 的 File Watch 功能,使 scss 文件更改时自动生成 css。开发机需要安装 sass 命令,数据库 options 表的 theme_mods_主题名 记录需要调整 css 生成时间戳至最大 bootscore_scss_modified_timestamp 为 9999999999。

brew install sass/sass/sass
<!-- 另存为 xml 文件可导入 PhpStorm -->
    <option name="arguments" value="-I $ProjectFileDir$/wp-content/themes/bootscore/scss main.scss:../css/main.css" />
    <option name="checkSyntaxErrors" value="true" />
    <option name="description" />
    <option name="exitCodeBehavior" value="ERROR" />
    <option name="fileExtension" value="scss" />
    <option name="immediateSync" value="true" />
    <option name="name" value="SCSS" />
    <option name="output" value="main.css:main.css.map" />
    <option name="outputFilters">
      <array />
    <option name="outputFromStdout" value="false" />
    <option name="program" value="sass" />
    <option name="runOnExternalChanges" value="true" />
    <option name="scopeName" value="Project Files" />
    <option name="trackOnlyRoot" value="true" />
    <option name="workingDir" value="$FileDir$" />
    <envs />



# 自定义菜单数据库详情
SELECT * FROM wp_posts WHERE post_type = 'nav_menu_item'



# Upstream to abstract backend connection(s) for php
upstream php {
        # server unix:/tmp/php-cgi.socket;

server {
        ## Your website name goes here.
        server_name wp-5.9.x.local;
        listen 80;

        ## Your only path reference.
        root WEB_ROOT;

        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                #The following parameter can be also included in fastcgi_params file
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
Author: njun
njun's picture
Updated: 2022/08/23