forked from brashrebel/wptv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwptv.php
118 lines (107 loc) · 2.55 KB
/
wptv.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
Plugin Name: WPTV
Plugin URI: http://realbigplugins.com
Description: Integrates videos from WordPress.tv with the WordPress admin.
Version: 0.1
Author: Kyle Maurer
Author URI: http://kyleblog.net
License: GPL2
*/
/**
* Class wptv
*/
class wptv {
/**
* Array of all the admin screens and the tag for appropriate videos
* @var array
*/
public $places = array(
array(
'screen' => 'tools',
'tag' => 'import',
),
array(
'screen' => 'plugins',
'tag' => 'plugins'
),
array(
'screen' => 'dashboard',
'tag' => 'dashboard'
),
array(
'screen' => 'update-core',
'tag' => 'update'
),
array(
'screen' => 'widgets',
'tag' => 'widgets'
),
);
/**
* Initialize all the things
*/
public function __construct() {
add_action( 'current_screen', array( $this, 'add_help_tab' ) );
add_action( 'admin_init', array( $this, 'style' ) );
}
public function style() {
wp_register_style( 'wptv', plugins_url( 'assets/style.css', __FILE__ ), array(), '0.1' );
}
/**
* @param $tag
*
* @return array|mixed|string|WP_Error
*/
public function request( $tag ) {
$url = 'http://wordpress.tv/?wptvapi=videos.json&posts_per_page=3&tag=';
$request = wp_remote_get( $url . $tag );
$request = wp_remote_retrieve_body( $request );
$request = json_decode( $request );
return $request;
}
/**
* Creates a Videos tab in the help menu for screens included in $places
*/
public function add_help_tab() {
$screen = get_current_screen();
foreach ( $this->places as $place ) {
if ( $place['screen'] == $screen->base ) {
wp_enqueue_style( 'wptv' );
$screen->add_help_tab( array(
'id' => 'videos',
'title' => 'Videos',
'content' => '',
'callback' => array( $this, 'display' ),
)
);
}
}
}
/**
* Displays the videos inside the help menu
*/
public function display() {
$screen = get_current_screen();
foreach ( $this->places as $place ) {
if ( $place['screen'] == $screen->base ) {
$tag = $place['tag'];
$videos = $this->request( $tag );
if ( ! is_wp_error( $videos ) ) {
echo '<ul class="wptv">';
foreach ( $videos->videos as $video ) {
echo '<li>';
echo '<a href="' . $video->permalink . '" target="_BLANK">';
echo '<img src="' . $video->thumbnail . '" />';
echo '<span>' . $video->title . '</span>';
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
}
}
echo '<a class="wptv-link" href="http://wordpress.tv/tag/' . $tag . '/">See more videos</a>';
}
}
$wptv = new wptv();