Hooks

WP Repo Releases provides several WordPress hooks, that allows you to customize the plugin’s behavior.

Wachrutz\WpRepoReleases\release_list

Receives and returns a list of releases. You can use this to add additional filter logic for which release gets displayed or to change release details like download links.

See The Release Class for more information about $release.

add_filter('Wachrutz\WpRepoReleases\release_list', function($all_releases) {
	$filtered_releases = [];

	foreach ($all_releases as $release) {
		if (strpos($release->get_title(), 'v') {
			$filtered_releases[] = $release;
		}
	}

	return $filtered_releases;
}, 10, 2);

Wachrutz\WpRepoReleases\css_class_name

Can be used to alter CSS classes used by the plugin. Used CSS class names are:

  • empty: Used for the container when no release has been found.
  • container: Used for the container around the list of releases.
  • release: Used for each release item.
add_filter('Wachrutz\WpRepoReleases\css_class_name', function($class_name, $default_class_name) {
	return 'my-css-prefix-' . $class_name;
}, 10, 2);

Wachrutz\WpRepoReleases\get_cache_ttl

Allows you to change the TTL of the internal cache. Increasing this value will decrease the amount of requests made to Bitbucket or Github but will make updates of the shown releases slower and vice versa. The default value is 300 seconds (5 minutes). If the returned value is smaller or equal to 0, the cache gets disabled.

add_filter('Wachrutz\WpRepoReleases\get_cache_ttl', function($ttl, $cache_key) {
	// Reduce the cache lifetime to 1 minute
	return 60;
}, 10, 2);

Wachrutz\WpRepoReleases\before_render_container

Called before the container gets rendered. Can be used to insert HTML before the list of releases.

Please notice: The html code you return from this hook will not be escaped. You need to take care of escaping all untrusted input at your own.

add_filter('Wachrutz\WpRepoReleases\before_render_container', function($html) {
	$html .= '<p>My banner goes here</p>';
	return $html;
});

Wachrutz\WpRepoReleases\before_render_item

Called before each item gets rendered. Can be used to insert HTML before each release.

See The Release Class for more information about $release.

Please notice: The html code you return from this hook will not be escaped. You need to take care of escaping all untrusted input at your own.

add_filter('Wachrutz\WpRepoReleases\before_render_container', function($html, $release) {
	if (stristr($release->get_release_notes(), 'major release')) {
		$html .= '<strong>Major release</strong>';
	}

	return $html;
}, 10, 2);

Wachrutz\WpRepoReleases\after_render_item

Called after each item gets rendered. Can be used to insert HTML after each release.

See The Release Class for more information about $release.

Please notice: The html code you return from this hook will not be escaped. You need to take care of escaping all untrusted input at your own.

add_filter('Wachrutz\WpRepoReleases\after_render_item', function($html, $release) {
	$html .= '<div><a href="' . esc_attr($release->get_download_url()) . '">Another download link</a></div>';
	return $html;
}, 10, 2);

Wachrutz\WpRepoReleases\after_render_container

Called after the container gets rendered. Can be used to insert HTML after the list of releases.

See The Release Class for more information about $all_releases.

Please notice: The html code you return from this hook will not be escaped. You need to take care of escaping all untrusted input at your own.

add_filter('Wachrutz\WpRepoReleases\after_render_container', function($html, $all_releases) {
	$html .= '<p>Found ' . esc_html(count($all_releases)) . ' releases</p>';
	return $html;
}, 10, 2);

The Release Class

Whenever releases are passed into hooks, the class Wachrutz\WpRepoReleases\Release is used. The class offers an interface to get information about fetched release data. It can also be used to alter release information in the later rendering process.

class Release {
	// Returns the title of the release
	public function get_title(): string;

	// Returns the date and time of the publishing date
	public function get_published(): \DateTime;

	// Returns the URL of the release description page
	public function get_link(): string;

	// Returns the release notes
	public function get_release_notes(): string;

	// Returns the used download URL. This is usually the URL of the first release artifact
	public function get_download_url(): string;

	// Returns an array containing all available download URLs of this release as strings
	public function get_alt_download_urls(): array;

	// Sets the title of the release
	public function set_title(string $title): void;

	// Sets the date and time of the publishing date
	public function set_published(\DateTime $published): void;

	// Sets the URL of the release description page
	public function set_link(string $link): void;

	// Sets the release notes
	public function set_release_notes(string $release_notes): void;

	// Sets the used download URL
	public function set_download_url(string $download_url): void;
}
Scroll to Top