-
Notifications
You must be signed in to change notification settings - Fork 2
/
newspack-plugin-update-checker.php
66 lines (58 loc) · 2.16 KB
/
newspack-plugin-update-checker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Plugin Name: Newspack Plugin Update Checker
* Description: Keep tabs on updates to Newspack plugins that are only available on Github
* Version: 0.1.0
* Author: Adam Schweigert, Media Toybox
* Author URI: https://mediatoybox.com
* License: GPL2
*
* @package Newspack-Plugin-Update-Checker
*/
defined( 'ABSPATH' ) || exit;
// Load the update checker library https://github.com/YahnisElsts/plugin-update-checker.
require_once 'vendor/plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
// Automattic github org url.
define( 'A8C_GH_URL', 'https://github.com/Automattic/' );
if ( ! function_exists( 'npuc_newspack_plugin_update' ) ) {
/**
* Loop through the plugins, make sure they exist, run the update checker.
*/
function npuc_newspack_plugin_update() {
// The most commonly used Newspack plugins that are not in the wp.org directory.
$newspack_plugin_list = array(
'newspack-plugin',
'newspack-ads',
'newspack-blocks',
'newspack-popups',
'newspack-listings',
'newsspack-sponsors',
'newspack-media-partners',
'newspack-rss-enhancements',
'newspack-supporters',
);
apply_filters( 'npuc_newspack_plugin_list', $newspack_plugin_list );
foreach ( $newspack_plugin_list as $plugin_slug ) {
if ( 'newspack-plugin' === $plugin_slug ) {
// The main Newspack plugin uses newspack.php instead of newspack-plugin.php.
$plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/newspack.php';
} else {
$plugin_file = WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_slug . '.php';
}
// Github repo URL for the plugin.
$github_url = A8C_GH_URL . $plugin_slug;
// Check to make sure this particular plugin file exists before we check for updates.
if ( file_exists( $plugin_file ) ) {
$npuc_update_checker = PucFactory::buildUpdateChecker(
$github_url,
$plugin_file,
$plugin_slug,
);
// Newspack uses composer to build releases so we need to use the zip file from the latest release instead of the stable branch.
$npuc_update_checker->getVcsApi()->enableReleaseAssets();
}
}
}
}
add_action( 'plugins_loaded', 'npuc_newspack_plugin_update' );