-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshifter-github-hosting-plugin-sample.php
64 lines (60 loc) · 1.5 KB
/
shifter-github-hosting-plugin-sample.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
<?php
/*
Plugin Name: Shifter GitHub hosting plugin sample
Plugin URI: https://github.com/getshifter/shifter-github-hosting-plugin-sample/
Description: Shifter GitHub hosting plugin sample
Author: Shifter Team
Version: {release version}
Author URI: https://getshifter.io/
*/
require __DIR__ . '/vendor/autoload.php';
add_action( 'admin_notices', function() {
// get Shifter News
$transient_key = 'shifter-news-posts';
if (false === ($posts = get_transient($transient_key))) {
$url = 'https://www.getshifter.io/feed/';
$res = YuzuruS\Rss\Feed::load($url);
$posts = [];
foreach ($res['item'] as $r) {
$posts[] = sprintf(
'<a href="%s" title="%s">%s</a>',
esc_url_raw($r['link']),
esc_attr($r['title']),
$r['title']
);
}
set_transient($transient_key, $posts, HOUR_IN_SECONDS);
}
$shifter_news = $posts[ mt_rand( 0, count( $posts ) - 1 ) ];
printf(
'<p id="shifter"><span dir="ltr" lang="en">%s</span></p>',
$shifter_news
);
});
add_action( 'admin_head', function() {
echo "
<style type='text/css'>
#shifter {
float: right;
padding: 5px 10px;
margin: 0;
font-size: 12px;
line-height: 1.6666;
}
.rtl #shifter {
float: left;
}
.block-editor-page #shifter {
display: none;
}
@media screen and (max-width: 782px) {
#shifter,
.rtl #shifter {
float: none;
padding-left: 0;
padding-right: 0;
}
}
</style>
";
});