< All Topics
Print

Developer Hooks

Filter Hooks

All filter hooks are renamed for Git Updater v10. There will be deprecations. A new setting in Git Updater Settings tab will log these errors to the debug.log.

There are 2 added filter hooks specifically for developers wanting to distribute private themes/plugins to clients without the client having to interact with the Settings page.

The first allows the developer to set certain option(s) excluding access tokens for a specific plugin or theme. The anonymous function must return key/value pairs where the key is the option name or plugin/theme repo slug and the value is the token.

The following keys are examples for the 'gu_set_options' hook.

array(
    'my-repo-slug'               => 'my-repo-slug_access_token', //for private GitHub or any GitLab repositories
    'my-other-repo-slug'         => 'my-repo-slug_pseudo_token', //for private Bitbucket repositories 
    'current_branch_my-repo-slug => 'master',
);

The filter hook gu_hide_settings will simply make the Settings page unavailable.

add_filter( 'gu_hide_settings', '__return_true' );

There is a hook to bypass the WP-Cron API calls and return to the traditional method of sequentially polling APIs during the page load. It is also useful to help debug API calls or if your WP-Cron is having problems. Add the following hook to enable.

add_filter( 'gu_disable_wpcron', '__return_true' );

A filter hook into API::exit_no_update() so that the user can always check for a new update via the following hook.

add_filter( 'gu_always_fetch_update', '__return_true' );

There is a hook to bypass the wp_remote_get calls for repo meta, readme.txt, and changelogs. These data provide for a richer experience in View details. If you are running Git Updater at scale you will certain get more performance by omitting these API calls. Add the following hook to enable. This is likely less relevant with the transition to using WP-Cron for API calls.

add_filter( 'gu_run_at_scale', '__return_true' );

A filter hook github_updater_add_admin_pages to add additional pages to where Git Updater runs.

This filters the parameter $admin_pages whose default is the following and should return a merged array.

This filter was deprecated in v9.1.0.

$admin_pages = [
            'plugins.php',
            'plugin-install.php',
            'themes.php',
            'theme-install.php',
            'update-core.php',
            'update.php',
            'options-general.php',
            'options.php',
            'settings.php',
            'edit.php',
        ];

The filter hook gu_add_settings_tabs filters the main parameter $tabs and allows the addition of other tabs to the Git Updater Settings page. This is how the Install Plugin, Install Theme, and Remote Management tabs are added. It should return a merged array.

The filter hook gu_add_settings_subtabs filters the main Git Updater subtab to allow for API subtabs. It should return a merged array.

The filter hook gu_add_repo_setting_field provides a hook to add in specific settings for each supported API. It should return an array.

The filter hook gu_number_rollbacks provides a hook to add the minimum number of tags for rollback in branch switching. Default is 1. This value is not modifiable when using release assets. It should return an integer.

The filter hook gu_save_redirect provides for a way to redirect back to the calling subtab during a save event. It should return a merged array.

The filter hook gu_override_dot_org provides a method of returning an array of plugin/theme data to override dot org. It should return an array.

add_filter( 'gu_override_dot_org', function( $overrides ) {
    return array_merge( $overrides, [ 
        'the-events-calendar-category-colors/the-events-calendar-category-colors.php', //plugin format
        'my-popular-theme' // theme slug
    ] );
});

The filter hook gu_ignore_dot_org provides a method of not returning updates from the official repository and will only return updates from the git host, ie GitHub. It should return a boolean. The default value is false. This means that updates to the primary branch will be served from the official repository. This is not a specific override.

The filter hook gu_api_domain provides a method to change the default Updates API domain from api.wordpress.org to something else. The return value is a string for the Updates API domain.

The filter hook gu_post_construct_download_link allows the developer to specify a ZipFile URL to be used as a rollback package. It passes the $repo and rollback tag, which is a branch name or tag, and returns a download link.

The filter hook gu_remote_is_newer allows the developer to utilize their own version comparison. It passes the $newer variable, a boolean, and the $repo which is an object containing the repository data. You must return a boolean.

add_filter( 'gu_remote_is_newer', function( $newer, $repo ) {
    return $newer;
}, 10, 2 );

The filter hook gu_repo_cache_timeout allows for a per repository override of the default cache timeout of 12 hours. It passes $timeout (a Unix timestamp), $id (the data identifier), $response (the data to be stored), and $repo (the repo name or null). The filter should return the $timeout.

Action Hooks

The action hook gu_refresh_transients is used to enter into the Refresh Cache path. It would be used in the following manner.

add_action( 'gu_refresh_transients', 'my_function_when_transients_are_deleted' );

The action hook gu_install_settings_fields provides for a hook to add fields for the Install Plugins and Install Themes API specific dropdown menu.

The action hook gu_pre_rest_process_request allows for an action to occur within Rest_Update::process_request().

The action hook gu_post_rest_process_request allows for an action to occur just before the termination of Rest_Update::process_request().

The action hook gu_add_admin_page adds data to a designated Settings page.

The action hook gu_add_settings adds data to API specific settings pages.

The action hook gu_update_settings adds ability to save options in add-in classes.

Table of Contents