Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
n/a
0 / 0
Automattic\Jetpack\Announcements\register_announcement
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Automattic\Jetpack\Announcements\get_announcements_from_feed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Public helpers of the Jetpack Announcements package.
4 *
5 * @package automattic/jetpack-announcements
6 */
7
8namespace Automattic\Jetpack\Announcements;
9
10/**
11 * Registers an announcement. Call it on the `jetpack_register_announcements` action.
12 *
13 * @since 0.1.0
14 *
15 * @param string $id   Namespaced id, `vendor/slug`.
16 * @param array  $args {
17 *     The announcement. Every value is sanitized.
18 *
19 *     @type string   $date       When it was published. Parsed as GMT unless it carries an offset.
20 *     @type string   $title      Plain text.
21 *     @type string[] $channels   The channels it is published to, such as `premium-analytics` or `premium-analytics/main`.
22 *     @type string   $excerpt    Optional. Plain text, one or two sentences.
23 *     @type string   $content    Optional. HTML, as a post allows it, without styles, classes or ids.
24 *     @type array    $media      Optional. `type` (`image` or `video`), `url` (http or https) and `alt`.
25 *     @type string   $link       Optional. URL of the full article, http or https.
26 *     @type string   $capability Optional. Hides the announcement from users without it.
27 * }
28 * @return array|false The registered announcement, or false when it is refused.
29 */
30function register_announcement( $id, $args ) {
31    return Announcement_Registry::get_instance()->register( $id, $args );
32}
33
34/**
35 * Reads a feed and returns its items as announcements, for a registrant to register.
36 *
37 * Read with `fetch_feed()`, which keeps a feed for 12 hours. A feed that fails is left alone for an hour.
38 * Nothing is registered: which items to publish, and to which channels, is the registrant's choice.
39 *
40 * @since $$next-version$$
41 *
42 * @param string $url    URL of the feed, RSS or Atom.
43 * @param string $vendor First half of the id of each announcement, such as `my-plugin`.
44 * @param array  $args   {
45 *     Optional. Settings of the read.
46 *
47 *     @type int      $max_age How old an item may be, in seconds. Older ones are left out. Default no limit.
48 *     @type string[] $query   Arguments to ask the feed with, by name, added to its URL. Default none.
49 * }
50 * @return array[] {
51 *     One entry per item that has a title, a date and a link. Empty when the feed fails.
52 *
53 *     @type string   $id         `vendor/hash`. The same for an item on every read.
54 *     @type array    $args       `date`, `title`, `excerpt`, `link` and `media`, for `register_announcement()`. Never HTML.
55 *     @type string[] $categories The labels the feed gives the item, categories and tags alike.
56 * }
57 */
58function get_announcements_from_feed( $url, $vendor, $args = array() ) {
59    return Feed_Announcements::get( $url, $vendor, $args );
60}