PluginProbe
Video Dashboard / 1.0
Video Dashboard v1.0
trunk 1.0 1.1 1.1.1 1.2.0 1.2.1 1.2.1.1 2.0.0
video-dashboard / video-dashboard.php

video-dashboard.php in Video Dashboard 1.0, at video-dashboard.php

122 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Video Dashboard
4 Plugin URI: http://brianjohnsondesign.com/wordpress-plugins/video-dashboard
5 Description: A plugin to display embeddable media into the WordPress dashboard
6 Version: 1.0
7 Author: Brian Johnson
8 Author URI: http://brianjohnsondesign.com
9 License: GPLv2 or later
10 */
11
12
13 /* Global Variables */
14
15 $vdb_prefix = 'vdb_';
16 $vdb_plugin_name = 'Video Dashboard';
17 $vdb_options = get_option('vdb_settings');
18
19 /*Includes*/
20
21 include('includes/admin-page.php');
22
23
24
25
26 add_action('wp_dashboard_setup', 'vdb_dashboard'); //Run plugin when dashboard is loaded
27 register_activation_hook( __FILE__, 'vdb_set_up_options' ); //Run function to load default values
28
29 function vdb_set_up_options(){ //Function to load default values
30 add_option('vdb_settings', array('minimum_role' => 'administrator', 'youtube_number' => '10'));
31 }
32
33
34 function vdb_load_scripts($hook) { //Register our stylesheet
35
36 if( $hook != 'index.php' ) //Only if it's in the admin area
37 return;
38
39 wp_register_style( 'vdb-style', plugins_url('includes/video-dashboard.css', __FILE__) );
40 wp_enqueue_style( 'vdb-style' );
41 }
42 add_action('admin_enqueue_scripts', 'vdb_load_scripts');
43
44
45
46 function vdb_dashboard() { //Display Videos
47
48 $vdb_options = get_option('vdb_settings');
49
50 //Specify which roles have permissions, given the minimum value
51 if ($vdb_options['minimum_role'] == 'subscriber') {$roles = array('subscriber', 'contributor', 'author', 'editor');}
52 if ($vdb_options['minimum_role'] == 'contributor') {$roles = array('contributor', 'author', 'editor');}
53 if ($vdb_options['minimum_role'] == 'author') {$roles = array('author', 'editor');}
54 if ($vdb_options['minimum_role'] == 'editor') {$roles = array('editor');}
55 if ($vdb_options['minimum_role'] == 'administrator') {$roles = array('administrator');}
56
57 //Check role
58 $in_role = vdb_check_user_role($roles);
59
60 //Load dashboard widget if they are an acceptable role
61 if ($in_role) {
62 wp_add_dashboard_widget('vdb_youtube_videos', 'YouTube Videos', 'vdb_display_youtube'); //Add YouTube Videos
63 } else {
64 // User not in role, do nothing
65 }
66 }
67
68 //Function to check user role
69 function vdb_check_user_role($roles,$user_id=NULL) {
70 if ($user_id)
71 $user = get_userdata($user_id);
72 else
73 $user = wp_get_current_user();
74
75 if (empty($user))
76 return FALSE;
77
78 if (!in_array('administrator',$roles)) //Add admins even if they aren't specified
79 $roles[] = 'administrator';
80
81 foreach ($user->roles as $role) {
82 if (in_array($role,$roles)) {
83 return TRUE;
84 }
85 }
86 return FALSE;
87 }
88
89
90
91 function vdb_display_youtube() {
92
93 global $vdb_options;
94
95 echo '<div class="wrap"></div>';
96
97 for ($i = 1; $i <= $vdb_options['youtube_number']; $i++) { //Loop through the number of videos
98
99 if ($vdb_options['youtube_id' . $i] != NULL) { //Make sure there is something entered in the field, otherwise do nothing with it
100 $youtube_location = $vdb_options['youtube_id' . $i];
101
102 if (strpos($youtube_location,'v=') !== false) { //If it's the full url
103 $url = $youtube_location;
104 parse_str( parse_url( $youtube_location, PHP_URL_QUERY ), $my_array_of_vars ); //Strip the video ID from the URL
105 $video_id = $my_array_of_vars['v'];
106 }
107 else {
108 $video_id = $youtube_location; //Otherwise it must be the video ID, just display that
109 }
110
111 if (strlen($video_id) != '11') {echo '<p>Error: Video #' . $i . " does not appear to be a valid YouTube video ID or URL.</p>";} //Make sure it's a valid 11-character string
112 else {
113 ?>
114
115 <div class="video-container"><iframe src="//www.youtube.com/embed/<?php echo $video_id; ?>" frameborder="0" allowfullscreen></iframe></div>
116
117 <?php
118 }
119 } ;} //End the Loop
120 }
121
122