-
Notifications
You must be signed in to change notification settings - Fork 3
/
bbpvotes-admin.php
111 lines (73 loc) · 2.96 KB
/
bbpvotes-admin.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
<?php
class bbP_Votes_Admin {
private $column_name_score = 'bbpvotes_score';
function __construct() {
self::setup_globals();
self::includes();
self::setup_actions();
}
function setup_globals() {
}
function includes(){
require( bbpvotes()->plugin_dir . 'bbpvotes-settings.php');
}
function setup_actions(){
add_action('bbp_init', array($this, 'handle_post_columns') );
add_filter( 'plugin_action_links_' . bbpvotes()->basename, array($this, 'plugin_bottom_links')); //bottom links
//add_action( 'admin_enqueue_scripts', array( $this, 'scripts_styles' ) );
}
function plugin_bottom_links($links){
$links[] = sprintf('<a target="_blank" href="%s">%s</a>',bbpvotes()->donate_link,__('Donate','bbppu'));//donate
if (current_user_can('manage_options')) {
$settings_page_url = add_query_arg(
array(
'page'=>bbP_Votes_Settings::$menu_slug
),
get_admin_url(null, 'options-general.php')
);
$links[] = sprintf('<a href="%s">%s</a>',esc_url($settings_page_url),__('Settings'));
}
return $links;
}
//TO FIX NOT WORKING
function handle_post_columns(){
foreach ( (array)bbpvotes_get_enabled_post_types() as $post_type ){
add_filter("manage_".$post_type."_posts_columns", array(&$this,'post_column_register'), 5);
add_action("manage_".$post_type."_posts_custom_column" , array(&$this,'post_column_content'), 10, 2 );
add_filter("manage_edit-".$post_type."_sortable_columns", array(&$this,'post_column_sortable') );
}
}
/*
* Scripts for backend
*/
public function scripts_styles($hook) {
if( ( !in_array(get_post_type(),bbpvotes_get_enabled_post_types()) ) && ($hook != 'playlist_page_bbpvotes-options') ) return;
wp_enqueue_style( 'bbpvotes-admin', bbpvotes()->plugin_url .'_inc/css/admin.css', array(), bbpvotes()->version );
}
function post_column_register($defaults){
//split at title
$before = array();
$after = array();
$after[$this->column_name_score] = __('Score','bbpvotes');
$defaults = array_merge($before,$defaults,$after);
return $defaults;
}
function post_column_content($column_name, $post_id){
$output = '';
switch ($column_name){
//score
case $this->column_name_score:
if ($score = bbpvotes_get_votes_score_for_post($post_id)){
$output = $score;
}
break;
}
echo $output;
}
function post_column_sortable( $columns ){
$columns[ $this->column_name_score ] = __('Score','bbpvotes');
return $columns;
}
}
new bbP_Votes_Admin();
?>