Documentation
Documentation
Graphic_Data_GitHub_Updater
in package
GitHub Updater - Optimized Version
Enables WordPress plugins and themes to update from GitHub, including pre-releases. Optimized to reduce API calls and prevent GitHub rate limiting.
Table of Contents
Properties
- $cache_duration : int
- Cache duration in seconds (24 hours by default)
- $github_response : array<string|int, mixed>|null
- Stores the response from the GitHub API (latest release or commit data).
- $is_theme : bool
- Flag indicating if the current instance is for a theme.
- $plugin_data : array<string|int, mixed>|null
- Stores plugin or theme data retrieved from WordPress.
- $plugin_file : string|null
- The main plugin file path. Only used if $is_theme is false.
- $repository : string
- The GitHub repository name.
- $slug : string
- The slug of the plugin or theme.
- $subdir_path : string
- The path to the plugin/theme within the GitHub repository, if it's in a subdirectory.
- $update_checked : bool
- Flag to track if we've already checked for updates in this request
- $username : string
- The GitHub username or organization name.
Methods
- __construct() : mixed
- Constructor.
- after_install() : array<string|int, mixed>
- Post-installation hook for plugins.
- after_theme_install() : array<string|int, mixed>
- Post-installation hook for themes.
- clear_update_cache() : mixed
- Clears the update cache when plugin/theme is updated.
- plugin_info() : false|object
- Provides plugin information for the "View details" popup.
- rate_limit_notice() : mixed
- Display admin notice when rate limited
- set_plugin_properties() : mixed
- Sets plugin or theme properties using WordPress functions.
- theme_update_state() : object
- Alias for theme updates to use the same update_state logic.
- update_state() : object
- Checks for updates and modifies the update transient.
- get_download_url() : string
- Gets the download URL for the plugin or theme.
- get_repository_info() : mixed
- Retrieves repository information from GitHub API with enhanced caching.
- recursive_copy() : bool
- Helper function to recursively copy directories using WP_Filesystem.
- recursive_remove_directory() : bool
- Helper function to recursively remove a directory using WP_Filesystem.
Properties
$cache_duration
Cache duration in seconds (24 hours by default)
private
int
$cache_duration
= \DAY_IN_SECONDS
$github_response
Stores the response from the GitHub API (latest release or commit data).
private
array<string|int, mixed>|null
$github_response
$is_theme
Flag indicating if the current instance is for a theme.
private
bool
$is_theme
= \false
$plugin_data
Stores plugin or theme data retrieved from WordPress.
private
array<string|int, mixed>|null
$plugin_data
$plugin_file
The main plugin file path. Only used if $is_theme is false.
private
string|null
$plugin_file
$repository
The GitHub repository name.
private
string
$repository
$slug
The slug of the plugin or theme.
private
string
$slug
For plugins, it's plugin_basename($file). For themes, it's the theme directory name.
$subdir_path
The path to the plugin/theme within the GitHub repository, if it's in a subdirectory.
private
string
$subdir_path
$update_checked
Flag to track if we've already checked for updates in this request
private
bool
$update_checked
= \false
$username
The GitHub username or organization name.
private
string
$username
Methods
__construct()
Constructor.
public
__construct(string $file, string $github_username, string $github_repo[, bool $is_theme = false ][, string $subdir_path = '' ]) : mixed
Sets up hooks for plugin or theme updates.
Parameters
- $file : string
-
The main plugin file path or theme directory path.
- $github_username : string
-
The GitHub username or organization.
- $github_repo : string
-
The GitHub repository name.
- $is_theme : bool = false
-
Optional. True if this is a theme, false for a plugin. Default false.
- $subdir_path : string = ''
-
Optional. Path to the plugin/theme within the repository if it's in a subdirectory.
after_install()
Post-installation hook for plugins.
public
after_install(bool $response, array<string|int, mixed> $hook_extra, array<string|int, mixed> $result) : array<string|int, mixed>
Moves the plugin from the temporary download location to the correct plugin directory. Handles cases where the plugin is in a subdirectory within the repository zip. Hooked to 'upgrader_post_install'.
Parameters
- $response : bool
-
Installation response.
- $hook_extra : array<string|int, mixed>
-
Extra arguments passed to hooked filters.
- $result : array<string|int, mixed>
-
Installation result data.
Return values
array<string|int, mixed> —The (potentially modified) result data.
after_theme_install()
Post-installation hook for themes.
public
after_theme_install(bool $response, array<string|int, mixed> $hook_extra, array<string|int, mixed> $result) : array<string|int, mixed>
Moves the theme from the temporary download location to the correct theme directory. Handles cases where the theme is in a subdirectory within the repository zip. Hooked to 'upgrader_post_install'.
Parameters
- $response : bool
-
Installation response.
- $hook_extra : array<string|int, mixed>
-
Extra arguments passed to hooked filters.
- $result : array<string|int, mixed>
-
Installation result data.
Return values
array<string|int, mixed> —The (potentially modified) result data.
clear_update_cache()
Clears the update cache when plugin/theme is updated.
public
clear_update_cache(WP_Upgrader $upgrader, array<string|int, mixed> $options) : mixed
Hooked to 'upgrader_process_complete'.
Parameters
- $upgrader : WP_Upgrader
-
WP_Upgrader instance.
- $options : array<string|int, mixed>
-
Array of bulk item update data.
plugin_info()
Provides plugin information for the "View details" popup.
public
plugin_info(false|object|array<string|int, mixed> $false, string $action, object $response) : false|object
Hooked to 'plugins_api'.
Parameters
- $false : false|object|array<string|int, mixed>
-
The result object or array. Default false.
- $action : string
-
The type of information being requested from the Plugin Installation API.
- $response : object
-
An object of arguments used to solicit information about a plugin.
Return values
false|object —The plugin info object or false if not applicable.
rate_limit_notice()
Display admin notice when rate limited
public
rate_limit_notice() : mixed
set_plugin_properties()
Sets plugin or theme properties using WordPress functions.
public
set_plugin_properties() : mixed
Hooked to 'admin_init'.
theme_update_state()
Alias for theme updates to use the same update_state logic.
public
theme_update_state(object $transient) : object
Hooked to 'site_transient_update_themes'.
Parameters
- $transient : object
-
The WordPress update transient for themes.
Return values
object —The modified transient.
update_state()
Checks for updates and modifies the update transient.
public
update_state(object $transient) : object
Enhanced with better caching and rate limit handling.
Parameters
- $transient : object
-
The WordPress update transient.
Return values
object —The modified transient.
get_download_url()
Gets the download URL for the plugin or theme.
private
get_download_url() : string
Prioritizes specific release assets (graphic_data_plugin.zip or graphic_data_theme.zip), then the release's zipball_url, then a direct archive link to the default branch.
Return values
string —The download URL.
get_repository_info()
Retrieves repository information from GitHub API with enhanced caching.
private
get_repository_info() : mixed
Fetches the latest release or, if no releases, the latest commit from the default branch.
recursive_copy()
Helper function to recursively copy directories using WP_Filesystem.
private
recursive_copy(string $src, string $dst) : bool
Parameters
- $src : string
-
Source directory path.
- $dst : string
-
Destination directory path.
Return values
bool —True on success, false on failure.
recursive_remove_directory()
Helper function to recursively remove a directory using WP_Filesystem.
private
recursive_remove_directory(string $directory) : bool
Includes safety checks to prevent accidental deletion of critical directories.
Parameters
- $directory : string
-
Path to the directory to remove.
Return values
bool —True on success, false on failure or if safety checks fail.