Git กับ WordPress: จัดการ Theme และ Plugin ด้วย Version Control
WordPress Website ควรใช้ Git เพื่อจัดการ Theme และ Plugin ได้อย่างมีประสิทธิภาพ การใช้ Version Control ช่วยให้ทีมสามารถทำงานร่วมกัน ติดตามการเปลี่ยนแปลง และ Deploy Code ไปยัง Production ได้อย่างปลอดภัย
WordPress .gitignore
ไฟล์ .gitignore สำหรับ WordPress Project:
# WordPress core
wp-admin/
wp-includes/
wp-*.php
readme.html
license.txt
# Configuration
wp-config.php
wp-config-local.php
.env
# Uploads
wp-content/uploads/
wp-content/cache/
# Third-party plugins (uncomitted)
wp-content/plugins/*
!wp-content/plugins/.gitkeep
!wp-content/plugins/custom-plugin/
# Third-party themes (uncomitted)
wp-content/themes/*
!wp-content/themes/.gitkeep
!wp-content/themes/custom-theme/
# Local
node_modules/
.DS_Store
*.log
สิ่งที่ควร Commit
- Custom Theme ที่คุณพัฒนา
- Custom Plugin ที่คุณพัฒนา
- wp-config.php ท้องแบบเทมเพลต (หรือไม่ commit)
- package.json และ composer.json
- Build Scripts และ Deploy Scripts
สิ่งที่ไม่ควร Commit
- WordPress Core Files (wp-admin, wp-includes)
- wp-config.php (ไฟล์จริง)
- Uploads Directory (ไฟล์ที่อัปโหลด)
- Third-party Plugins (ที่ดาวน์โหลดจาก Repository)
- .env Files (Environment Variables)
- Database Backups
Deployment Workflow
Workflow สำหรับ Deploy WordPress Theme หรือ Plugin:
1. Clone Repository
git clone https://github.com/yourrepo/wordpress.git
2. Create Feature Branch
git checkout -b feature/new-feature
3. Make Changes
# Edit theme or plugin files
4. Commit Changes
git add .
git commit -m "Add new feature"
5. Push to Remote
git push origin feature/new-feature
6. Create Pull Request
# Review and merge on GitHub/GitLab
7. Deploy to Production
# Automatic or manual deployment via SSH
git pull origin main
Bedrock และ Trellis Approach
Bedrock เป็น Modern WordPress Boilerplate ที่ใช้ Composer สำหรับจัดการ Dependencies:
├── web/
│ ├── wp/ (WordPress core)
│ └── app/
│ ├── plugins/ (Custom plugins)
│ └── themes/ (Custom themes)
├── composer.json
├── .env.example
└── config/
└── environments/
Child Theme Development
เมื่อพัฒนา Child Theme สำหรับ WordPress:
wp-content/themes/
├── parent-theme/ # Don't edit or commit
└── custom-child-theme/
├── functions.php
├── style.css
├── template-parts/
└── assets/
├── css/
├── js/
└── images/
Best Practices
- ใช้ Semantic Versioning สำหรับ Theme และ Plugin
- เขียน README.md สำหรับการติดตั้ง
- ใช้ Git Tags สำหรับ Release Versions
- ทดสอบบน Staging Environment ก่อน Production
- เก็บ Database Schema ไว้ใน Version Control
การใช้ Git กับ WordPress ช่วยให้ Team Development มีประสิทธิภาพและปลอดภัยมากขึ้น