-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathshifter-github-hosting-plugin-sample.php
More file actions
78 lines (69 loc) · 1.71 KB
/
shifter-github-hosting-plugin-sample.php
File metadata and controls
78 lines (69 loc) · 1.71 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
<?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/
*/
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/';
$feed = fetch_feed( $url );
if ( is_wp_error( $feed ) ) {
return;
}
$items = $feed->get_items( 0, 10 );
$posts = [];
foreach ( $items as $item ) {
$posts[] = sprintf(
'<a href="%s" title="%s">%s</a>',
esc_url_raw( $item->get_permalink() ),
esc_attr( $item->get_title() ),
$item->get_title()
);
}
if ( empty( $posts ) ) {
return;
}
set_transient( $transient_key, $posts, HOUR_IN_SECONDS );
}
if ( empty( $posts ) ) {
return;
}
$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>
";
});