Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Whats_New | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
5.05 | |
0.00% |
0 / 1 |
| init | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| register | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
4.05 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * What My Jetpack publishes on the What's new surface it hosts. |
| 4 | * |
| 5 | * @package automattic/my-jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\My_Jetpack; |
| 9 | |
| 10 | use function Automattic\Jetpack\Announcements\get_announcements_from_feed; |
| 11 | use function Automattic\Jetpack\Announcements\register_announcement; |
| 12 | |
| 13 | /** |
| 14 | * Publishes the recent posts of Jetpack.com as announcements of My Jetpack. |
| 15 | */ |
| 16 | class Whats_New { |
| 17 | |
| 18 | /** |
| 19 | * Channel the My Jetpack page subscribes to, and the first half of the ids My Jetpack registers. |
| 20 | */ |
| 21 | const CHANNEL = 'my-jetpack'; |
| 22 | |
| 23 | /** |
| 24 | * How old a post may be to count as news, in seconds. |
| 25 | */ |
| 26 | const MAX_AGE = 30 * DAY_IN_SECONDS; |
| 27 | |
| 28 | /** |
| 29 | * Hook the registrant. |
| 30 | * |
| 31 | * @return void |
| 32 | */ |
| 33 | public static function init() { |
| 34 | add_action( 'jetpack_register_announcements', array( __CLASS__, 'register' ) ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Register the recent posts of Jetpack.com, while the flag is on. |
| 39 | * |
| 40 | * @return void |
| 41 | */ |
| 42 | public static function register() { |
| 43 | if ( ! Initializer::is_whats_new_enabled() ) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // Another plugin may load an older copy of the package first. |
| 48 | if ( ! function_exists( 'Automattic\\Jetpack\\Announcements\\get_announcements_from_feed' ) ) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | $announcements = get_announcements_from_feed( REST_Blog_Posts::FEED_URL, self::CHANNEL, array( 'max_age' => self::MAX_AGE ) ); |
| 53 | |
| 54 | foreach ( $announcements as $announcement ) { |
| 55 | register_announcement( $announcement['id'], $announcement['args'] + array( 'channels' => array( self::CHANNEL ) ) ); |
| 56 | } |
| 57 | } |
| 58 | } |