API Documentation - Juzt Deploy
API Documentation - Juzt Deploy
Plugin Structure Overview
wp-versions-themes-plugins/
├── wp-version-themes-plugins.php # Main plugin file
├── includes/
│ ├── class-admin-interface.php # Admin interface handler
│ ├── class-ajax-handlers.php # AJAX request handlers
│ ├── class-repo-manager.php # Repository management core
│ ├── class-oauth-service.php # OAuth authentication service
│ ├── class-git-interface.php # Git abstraction interface
│ ├── class-git-cli.php # Git CLI implementation
│ ├── class-git-api.php # GitHub API implementation
│ ├── class-github-api.php # GitHub API wrapper
│ └── class-progress-tracker.php # Progress tracking system
├── assets/
│ ├── css/admin.css # Admin styles
│ └── js/admin.js # Admin JavaScript
Methods
get_instance()
Purpose: Get singleton instance
Returns: WP_Versions_Themes_Plugins instance
__construct()
Purpose: Private constructor for Singleton
Access: private
init()
Purpose: Initialize plugin hooks and dependencies
Hooks:
init - Load textdomain
admin_menu - Add admin menu
admin_enqueue_scripts - Enqueue admin assets
setup_theme - Handle theme preview
wp_ajax_wpvtp_exit_preview - AJAX exit preview
wpvtp_auto_commit - Handle auto commits
maybe_run_migration()
Purpose: Check and run database migrations if needed
Hook: admin_init
update_database_structure()
Purpose: Update database tables structure
Tables: Creates github_repos and wpvtp_commits_queue
migrate_repo_data()
Purpose: Migrate old repository data to new structure
Action: Updates folder_name from local_path
handle_middleware_callback()
Purpose: Handle OAuth callback from middleware
Parameters: Processes session_token and refresh_token
load_plugin_textdomain()
Purpose: Load plugin translations
Hook: init
add_admin_menu()
Purpose: Add plugin to WordPress admin menu
Hook: admin_menu
enqueue_admin_scripts($hook)
Purpose: Enqueue admin CSS and JS
Parameters:
- $hook - Current admin page
Hook: admin_enqueue_scripts
admin_page()
Purpose: Render main admin page
Uses: WPVTP_Admin_Interface
handle_theme_preview()
Purpose: Handle theme preview functionality
Hook: setup_theme
apply_theme_preview($theme_handle)
Purpose: Apply filters for theme preview
Parameters:
- $theme_handle - Theme directory name
add_preview_bar()
Purpose: Add preview bar to frontend
Hook: wp_footer
activate()
Purpose: Plugin activation hook
Actions: Database setup, directory creation
deactivate()
Purpose: Plugin deactivation hook
Actions: Cleanup sessions and scheduled tasks
ajax_exit_preview()
Purpose: AJAX handler for exiting preview
Hook: wp_ajax_wpvtp_exit_preview
Admin Interface: class-admin-interface.php
Class: WPVTP_Admin_Interface
Purpose: Handles all admin interface rendering
Properties
php
private $repo_manager; // Repository manager instance
private $oauth_service; // OAuth service instance
private $current_page; // Current admin page/tab
Methods
__construct()
Purpose: Initialize dependencies
Includes: class-repo-manager.php, class-oauth-service.php
render_admin_page()
Purpose: Render main admin page with tabs
Tabs: dashboard, install, commits_queue, settings
render_git_warning()
- Purpose: Render Git not available warning
render_navigation_tabs()
- Purpose: Render tab navigation
render_dashboard_page()
- Purpose: Render dashboard with repo statistics and list
render_install_page()
- Purpose: Render repository installation wizard
render_settings_page()
- Purpose: Render settings page with OAuth and Git mode config
render_commits_queue_page()
- Purpose: Render commits queue management
render_api_mode_warning()
- Purpose: Show API mode information notice
AJAX Handlers: class-ajax-handlers.php
Class: WPVTP_AJAX_Handlers
Purpose: Handle all AJAX requests
Properties
php
private $oauth_service; // OAuth service instance
private $repo_manager; // Repository manager instance
Methods
__construct()
- Purpose: Register all AJAX hooks
retry_commit()
Purpose: Retry failed commit from queue
AJAX: wp_ajax_wpvtp_retry_commit
delete_commit()
Purpose: Delete commit from queue
AJAX: wp_ajax_wpvtp_delete_commit
get_organizations()
Purpose: Get user organizations and installations
AJAX: wp_ajax_wpvtp_get_organizations
get_repositories()
Purpose: Get repositories for selected organization
AJAX: wp_ajax_wpvtp_get_repositories
get_branches()
Purpose: Get branches for selected repository
AJAX: wp_ajax_wpvtp_get_branches
clone_repository()
Purpose: Clone repository from GitHub
AJAX: wp_ajax_wpvtp_clone_repository
update_repository()
Purpose: Update existing repository
AJAX: wp_ajax_wpvtp_update_repository
switch_branch()
Purpose: Switch repository branch
AJAX: wp_ajax_wpvtp_switch_branch
remove_repository()
Purpose: Remove repository
AJAX: wp_ajax_wpvtp_remove_repository
ajax_disconnect_github()
Purpose: Disconnect from GitHub
AJAX: wp_ajax_wpvtp_disconnect_github
download_wp_content()
Purpose: Create wp-content backup ZIP
AJAX: wp_ajax_wpvtp_download_wp_content
serve_zip_file()
Purpose: Serve ZIP file for download
AJAX: wp_ajax_wpvtp_serve_zip
get_progress()
Purpose: Get progress for ongoing operation
AJAX: wp_ajax_wpvtp_get_progress
Repository Manager: class-repo-manager.php
Class: WPVTP_Repo_Manager
Purpose: Core repository management operations
Properties
php
private $table_name; // Database table name for repos
Methods
__construct()
- Purpose: Initialize and register hooks
handle_queue_commit_action($theme_path, $commit_message)
Purpose: Handle queue commit action
Hook: wpvtp_queue_commit
handle_queue_commit_filter($result, $theme_path, $commit_message,
$file_path)
Purpose: Filter for queue commit
Hook: wpvtp_queue_commit
is_git_available()
Purpose: Check if Git CLI is available
Returns: bool
get_git_version()
Purpose: Get installed Git version
Returns: string|false
detect_git_mode()
Purpose: Detect available Git mode (CLI/API)
Returns: 'cli'|'api'
get_git_mode()
Purpose: Get current Git mode
Returns: 'cli'|'api'
get_git_instance()
Purpose: Get Git implementation instance
Returns: WPVTP_Git_CLI|WPVTP_Git_API
generate_folder_handle($repo_name, $branch)
Purpose: Generate safe folder name
Parameters:
$repo_name - Repository name
$branch - Branch name
Returns: string
resolve_local_path($folder_name, $type)
Purpose: Resolve absolute path from folder name
Parameters:
$folder_name - Folder name
$type - 'theme' or 'plugin'
Returns: string
get_relative_path($absolute_path, $type)
Purpose: Get folder name from absolute path
Parameters:
$absolute_path - Full path
$type - 'theme' or 'plugin'
Returns: string
migrate_old_paths()
Purpose: Migrate old absolute paths to folder names
Returns: array Migration results
clone_repository($repo_url, $branch, $type, $repo_name,
$custom_name, $access_token, $job_id)
Purpose: Clone repository from GitHub
Parameters:
$repo_url - GitHub repository URL
$branch - Branch to clone
$type - 'theme' or 'plugin'
$repo_name - Repository name
$custom_name - Custom display name
$access_token - GitHub access token
$job_id - Progress tracking ID
Returns: array Operation result
update_repository($identifier, $access_token, $job_id)
Purpose: Update existing repository
Parameters:
$identifier - Repository identifier
$access_token - GitHub access token
$job_id - Progress tracking ID
Returns: array Operation result
switch_branch($identifier, $new_branch, $job_id)
Purpose: Switch repository branch
Parameters:
$identifier - Repository identifier
$new_branch - New branch name
$job_id - Progress tracking ID
Returns: array Operation result
get_current_branch($identifier)
Purpose: Get current branch of repository
Parameters: $identifier - Repository identifier
Returns: string|false
get_repo_by_identifier($identifier)
Purpose: Get repository info by identifier
Parameters: $identifier - Folder name or local path
Returns: array|false
get_installed_repos()
Purpose: Get all installed repositories
Returns: array List of repositories
remove_repository($identifier)
Purpose: Remove repository completely
Parameters: $identifier - Repository identifier
Returns: array Operation result
update_theme_name($theme_path, $theme_name, $branch)
Purpose: Update theme name in style.css
Parameters:
$theme_path - Theme directory path
$theme_name - New theme name
$branch - Branch name for suffix
Returns: bool Success
update_plugin_name($plugin_path, $plugin_name, $original_repo_name)
Purpose: Update plugin name in main file
Parameters:
$plugin_path - Plugin directory path
$plugin_name - New plugin name
$original_repo_name - Original repo name
Returns: bool Success
find_main_plugin_file($plugin_path, $repo_name)
Purpose: Find main plugin file
Parameters:
$plugin_path - Plugin directory path
$repo_name - Repository name
Returns: string|false
save_repo_to_database($repo_name, $repo_url, $folder_name, $branch,
$type)
Purpose: Save repository to database
Parameters: Repository data
Returns: bool Success
update_repo_timestamp($folder_name, $type)
Purpose: Update repository last update timestamp
Parameters:
$folder_name - Folder name
$type - 'theme' or 'plugin'
Returns: bool Success
update_repo_branch($folder_name, $type, $branch)
Purpose: Update repository branch in database
Parameters:
$folder_name - Folder name
$type - 'theme' or 'plugin'
$branch - New branch
Returns: bool Success
remove_directory($dir)
Purpose: Recursively remove directory
Parameters: $dir - Directory path
Returns: bool Success
get_repo_stats()
Purpose: Get repository statistics
Returns: array Statistics
commit_and_push_changes($identifier, $message, $file_path)
Purpose: Commit and push changes
Parameters:
$identifier - Repository identifier
$message - Commit message
$file_path - Specific file path
Returns: array Operation result
queue_commit($theme_path, $commit_message, $file_path)
Purpose: Add commit to queue
Parameters:
$theme_path - Theme/repository path
$commit_message - Commit message
$file_path - File to commit
Returns: array Operation result
configure_push_authentication($repo_path)
Purpose: Configure Git credentials for push
Parameters: $repo_path - Repository path
Returns: bool Success
process_commit_queue_item($commit_id)
Purpose: Process commit from queue
Parameters: $commit_id - Commit ID
Returns: array Operation result
create_wp_content_zip($zip_name)
Purpose: Create wp-content backup ZIP
Parameters: $zip_name - ZIP file name
Returns: array Operation result
add_directory_to_zip($zip, $source_path, $zip_path)
Purpose: Add directory to ZIP recursively
Parameters:
$zip - ZipArchive instance
$source_path - Source directory
$zip_path - Path in ZIP
OAuth Service: class-oauth-service.php
Class: WPVTP_OAuth_Service
Purpose: Handle OAuth authentication with middleware
Properties
php
private $session_token; // Current session token
private $refresh_token; // Refresh token
Constants
php
const OAUTH_SERVICE_URL =
'https://github-app-api-production.up.railway.app\';
Methods
__construct()
- Purpose: Initialize tokens and schedule refresh
get_authorization_url()
Purpose: Get GitHub OAuth authorization URL
Returns: string Authorization URL
make_request($endpoint, $method, $data)
Purpose: Make request to middleware service
Parameters:
$endpoint - API endpoint
$method - HTTP method
$data - Request data
Returns: array Response
refresh_access_token()
Purpose: Refresh access token using refresh token
Returns: array Operation result
get_user_info()
Purpose: Get authenticated user information
Returns: array User data
get_all_repositories()
Purpose: Get all accessible repositories (including installations)
Returns: array Repositories data
get_installations()
Purpose: Get GitHub App installations
Returns: array Installations data
get_installation_repositories($installation_id)
Purpose: Get repositories for specific installation
Parameters: $installation_id - Installation ID
Returns: array Repositories
get_repositories($owner, $type)
Purpose: Get repositories for owner
Parameters:
$owner - Owner username
$type - 'user' or 'org'
Returns: array Repositories
get_branches($owner, $repo)
Purpose: Get branches for repository
Parameters:
$owner - Repository owner
$repo - Repository name
Returns: array Branches
get_repository($owner, $repo)
Purpose: Get specific repository information
Parameters:
$owner - Repository owner
$repo - Repository name
Returns: array Repository data
clear_cache()
Purpose: Clear middleware cache
Returns: array Operation result
disconnect()
Purpose: Disconnect from GitHub
Returns: array Operation result
is_connected()
Purpose: Check if connected to GitHub
Returns: bool
get_connected_user()
Purpose: Get connected user information
Returns: array|null User data
flatten_repositories($all_repos_response)
Purpose: Convert nested repositories to flat array
Parameters: $all_repos_response - Nested response
Returns: array Flat repositories list
get_repositories_by_owner()
Purpose: Get repositories grouped by owner
Returns: array Grouped repositories
handle_oauth_callback()
Purpose: Handle OAuth callback
Hook: Processes callback parameters
auto_refresh_token_if_needed()
Purpose: Auto-refresh token if needed
Hook: Scheduled task
Git Interface: class-git-interface.php
Abstract Class: WPVTP_Git_Interface
Purpose: Abstract interface for Git operations
Abstract Methods
is_available()
Purpose: Check if implementation is available
Returns: bool
clone_repository($repo_url, $branch, $destination, $access_token)
Purpose: Clone repository
Parameters:
$repo_url - Repository URL
$branch - Branch to clone
$destination - Destination path
$access_token - GitHub access token
Returns: array Operation result
update_repository($repo_path, $access_token)
Purpose: Update repository (pull)
Parameters:
$repo_path - Repository path
$access_token - GitHub access token
Returns: array Operation result
switch_branch($repo_path, $new_branch, $access_token)
Purpose: Switch branch
Parameters:
$repo_path - Repository path
$new_branch - New branch
$access_token - GitHub access token
Returns: array Operation result
get_current_branch($repo_path)
Purpose: Get current branch
Parameters: $repo_path - Repository path
Returns: string|false
commit_and_push($repo_path, $file_path, $commit_message,
$access_token)
Purpose: Commit and push changes
Parameters:
$repo_path - Repository path
$file_path - File to commit
$commit_message - Commit message
$access_token - GitHub access token
Returns: array Operation result
Git CLI Implementation: class-git-cli.php
Class: WPVTP_Git_CLI extends WPVTP_Git_Interface
Purpose: Git operations using command line interface
Methods
is_available()
Purpose: Check if Git CLI is available
Returns: bool
clone_repository($repo_url, $branch, $destination, $access_token)
Purpose: Clone using git clone command
Returns: array Operation result
update_repository($repo_path, $access_token)
Purpose: Update using git pull
Returns: array Operation result
switch_branch($repo_path, $new_branch, $access_token)
Purpose: Switch branch using git checkout
Returns: array Operation result
get_current_branch($repo_path)
Purpose: Get current branch using git branch
Returns: string|false
commit_and_push($repo_path, $file_path, $commit_message,
$access_token)
Purpose: Commit and push using git commands
Returns: array Operation result
configure_remote_token($repo_path, $access_token)
Purpose: Configure Git remote with token
Parameters:
$repo_path - Repository path
$access_token - GitHub token
Git API Implementation: class-git-api.php
Class: WPVTP_Git_API extends WPVTP_Git_Interface
Purpose: Git operations using GitHub API
Methods
is_available()
Purpose: API is always available
Returns: true
clone_repository($repo_url, $branch, $destination, $access_token)
Purpose: Clone using GitHub ZIP download
Returns: array Operation result
update_repository($repo_path, $access_token)
Purpose: Update by re-downloading repository
Returns: array Operation result
switch_branch($repo_path, $new_branch, $access_token)
Purpose: Switch branch by re-cloning
Returns: array Operation result
get_current_branch($repo_path)
Purpose: Get branch from metadata
Returns: string|false
commit_and_push($repo_path, $file_path, $commit_message,
$access_token)
Purpose: Commit using GitHub API
Returns: array Operation result
save_repo_metadata($repo_path, $owner, $repo, $branch)
Purpose: Save repository metadata
Parameters: Repository information
get_repo_metadata($repo_path)
Purpose: Get repository metadata
Parameters: $repo_path - Repository path
Returns: array|false Metadata
Progress Tracker: class-progress-tracker.php
Class: WPVTP_Progress_Tracker
Purpose: Track progress of long-running operations
Properties
php
private $job_id; // Unique job identifier
Methods
__construct($job_id)
Purpose: Initialize with job ID
Parameters: $job_id - Job identifier
get_job_id()
Purpose: Get job ID
Returns: string
update($step, $message, $progress)
Purpose: Update progress
Parameters:
$step - Current step
$message - Progress message
$progress - Progress percentage
complete($message)
Purpose: Mark job as completed
Parameters: $message - Completion message
error($message)
Purpose: Mark job as errored
Parameters: $message - Error message
static get_progress($job_id)
Purpose: Get progress for job
Parameters: $job_id - Job identifier
Returns: array|false Progress data
cleanup()
- Purpose: Clean up progress data
GitHub API Wrapper: class-github-api.php
Class: WPVTP_GitHub_API
Purpose: GitHub API wrapper using OAuth service
Properties
php
private $oauth_service; // OAuth service instance
Methods
__construct()
- Purpose: Initialize OAuth service
is_authenticated()
Purpose: Check if authenticated
Returns: bool
get_user()
Purpose: Get authenticated user
Returns: array User data
get_organizations()
Purpose: Get user organizations
Returns: array Organizations
get_repositories($owner, $type, $per_page, $page)
Purpose: Get repositories for owner
Returns: array Repositories
get_repository($owner, $repo)
Purpose: Get specific repository
Returns: array Repository data
get_branches($owner, $repo)
Purpose: Get repository branches
Returns: array Branches
get_default_branch($owner, $repo)
Purpose: Get default branch
Returns: array Branch data
detect_repo_type($owner, $repo, $branch)
Purpose: Detect repository type
Returns: array Type detection result
get_rate_limit_info()
Purpose: Get rate limit information
Returns: array Rate limit data
clear_token()
Purpose: Clear authentication token
Returns: array Operation result
validate_token()
Purpose: Validate current token
Returns: array Validation result
Assets Documentation
CSS: assets/css/admin.css
Purpose: Admin interface styling
Key Sections:
CSS variables for consistent theming
Layout styles for main admin interface
Dashboard statistics and cards
Installation wizard steps
Progress bars and loading states
Modal windows and notifications
Responsive design for mobile
JavaScript: assets/js/admin.js
Purpose: Admin interface interactivity
Key Functions:
initializeWizard() - Setup installation wizard
loadOrganizations() - Load GitHub organizations
loadRepositories(owner, type) - Load repositories
loadBranches(owner, repo) - Load branches
installRepository() - Handle repository installation
updateRepository(localPath, button) - Update repository
switchBranch(localPath, newBranch) - Switch branch
removeRepository(localPath) - Remove repository
startProgressTracking(jobId, onComplete, onError, customContainer) -
Progress tracking
showNotification(message, type) - Show notifications
showModal(title, content, onOpen) - Modal management
This comprehensive documentation covers all major classes, methods, and
their purposes within the Juzt Deploy plugin ecosystem.