Add Oribi Sync plugin for syncing WordPress pages and theme files from a Git repository
- Implement encryption helpers for storing and retrieving the Personal Access Token (PAT). - Create REST API endpoints for triggering sync, checking sync status, and handling webhooks. - Develop the sync engine to fetch pages from the Git repository, create/update WordPress pages, and trash removed pages. - Add functionality for previewing and applying theme files from the repository. - Set up plugin activation and deactivation hooks to manage default options and scheduled tasks. - Implement uninstall routine to clean up plugin options and metadata from posts.
This commit is contained in:
51
oribi-tech-sync.php
Normal file
51
oribi-tech-sync.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Oribi Tech Sync
|
||||
* Description: Sync WordPress pages and theme files from a remote Git repository. Configure a repo URL + PAT, then sync on command via admin UI or REST API.
|
||||
* Version: 1.0.0
|
||||
* Author: Oribi Technology Services
|
||||
* Requires at least: 6.0
|
||||
* Requires PHP: 7.4
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
define( 'ORIBI_SYNC_VERSION', '1.0.0' );
|
||||
define( 'ORIBI_SYNC_DIR', plugin_dir_path( __FILE__ ) );
|
||||
define( 'ORIBI_SYNC_URL', plugin_dir_url( __FILE__ ) );
|
||||
define( 'ORIBI_SYNC_BASENAME', plugin_basename( __FILE__ ) );
|
||||
|
||||
// ─── Includes ─────────────────────────────────────────────────────────────────
|
||||
require_once ORIBI_SYNC_DIR . 'includes/crypto.php';
|
||||
require_once ORIBI_SYNC_DIR . 'includes/api-client.php';
|
||||
require_once ORIBI_SYNC_DIR . 'includes/sync-engine.php';
|
||||
require_once ORIBI_SYNC_DIR . 'includes/admin.php';
|
||||
require_once ORIBI_SYNC_DIR . 'includes/rest.php';
|
||||
require_once ORIBI_SYNC_DIR . 'includes/theme-preview.php';
|
||||
|
||||
// ─── Activation / Deactivation ────────────────────────────────────────────────
|
||||
register_activation_hook( __FILE__, 'oribi_sync_activate' );
|
||||
register_deactivation_hook( __FILE__, 'oribi_sync_deactivate' );
|
||||
|
||||
function oribi_sync_activate() {
|
||||
// Ensure default options exist
|
||||
add_option( 'oribi_sync_repo', '', '', 'no' );
|
||||
add_option( 'oribi_sync_branch', 'main', '', 'no' );
|
||||
add_option( 'oribi_sync_provider', '', '', 'no' );
|
||||
add_option( 'oribi_sync_pat', '', '', 'no' );
|
||||
add_option( 'oribi_sync_last_run', '', '', 'no' );
|
||||
add_option( 'oribi_sync_log', [], '', 'no' );
|
||||
}
|
||||
|
||||
function oribi_sync_deactivate() {
|
||||
wp_clear_scheduled_hook( 'oribi_sync_cron_run' );
|
||||
}
|
||||
|
||||
// ─── Uninstall (static, called by WP) ─────────────────────────────────────────
|
||||
// See uninstall.php for full cleanup.
|
||||
|
||||
// ─── Plugin action links ──────────────────────────────────────────────────────
|
||||
add_filter( 'plugin_action_links_' . ORIBI_SYNC_BASENAME, function ( $links ) {
|
||||
$links[] = '<a href="' . esc_url( admin_url( 'options-general.php?page=oribi-sync' ) ) . '">Settings</a>';
|
||||
return $links;
|
||||
} );
|
||||
Reference in New Issue
Block a user