WordPress GitHub Sync 项目教程
1. 项目的目录结构及介绍
WordPress GitHub Sync 项目的目录结构如下:
wordpress-github-sync/
├── admin/
│ ├── css/
│ ├── js/
│ └── views/
├── includes/
│ ├── api/
│ ├── classes/
│ ├── compatibility/
│ └── functions/
├── languages/
├── vendor/
├── wp-github-sync.php
└── readme.txt
目录介绍:
- admin/: 包含插件的后台管理界面所需的CSS、JavaScript和视图文件。
- includes/: 包含插件的核心功能,如API接口、类定义、兼容性处理和功能函数。
- languages/: 包含插件的本地化语言文件。
- vendor/: 包含第三方依赖库。
- wp-github-sync.php: 插件的主文件,包含插件的基本信息和初始化代码。
- readme.txt: 插件的说明文档。
2. 项目的启动文件介绍
项目的启动文件是 wp-github-sync.php
。这个文件包含了插件的基本信息和初始化代码。以下是文件的部分内容:
<?php
/*
Plugin Name: WordPress GitHub Sync
Plugin URI: https://github.com/mAAdhaTTah/wordpress-github-sync
Description: A WordPress plugin to sync content with a GitHub repository (or Jekyll site).
Version: 2.0.1
Author: James DiGioia, Ben Balter
Author URI: https://github.com/mAAdhaTTah
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
// 引入必要的文件
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/includes/functions/core.php';
// 初始化插件
add_action('plugins_loaded', function () {
WordPress_GitHub_Sync::instance();
});
启动文件功能:
- 定义插件的基本信息,如名称、版本、作者等。
- 引入必要的依赖文件和核心功能文件。
- 通过
plugins_loaded
钩子初始化插件。
3. 项目的配置文件介绍
项目的配置文件主要涉及插件的后台设置页面和GitHub的Webhook设置。
后台设置页面:
在 WordPress 后台,进入 设置
-> GitHub Sync
页面,可以进行以下配置:
- GitHub Repository: 输入要同步的GitHub仓库地址。
- GitHub Token: 输入GitHub的个人访问令牌,用于授权插件访问GitHub仓库。
- Webhook URL: 显示用于GitHub的Webhook URL,用于触发内容同步。
GitHub Webhook 设置:
在GitHub仓库的 Settings
-> Webhooks
页面,添加一个新的Webhook,配置如下:
- Payload URL: 使用插件提供的Webhook URL。
- Content Type: 选择
application/json
。 - Secret: 留空或根据需要设置。
- Events: 选择
Just the push event
。
通过这些配置,插件可以实现WordPress内容与GitHub仓库的双向同步。