-
Notifications
You must be signed in to change notification settings - Fork 1
/
log-deprecated-notices-extender.php
87 lines (72 loc) · 2.59 KB
/
log-deprecated-notices-extender.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
<?php
/*
* Plugin Name: Log Deprecated Notices Extender
* Plugin URI: http://jkudish.com/log-deprecated-notices-extender/
* Description: WordPress plugin that extends Andrew Nacin's Log Deprecated Notices to show a link in the WP 3.3+ Toolbar.
* Version: 0.1.2
* Author: Joachim Kudish
* Author URI: http://jkudish.com
* License: GPLv2 or later
*/
/**
* @package Deprecated_Log_Extender
* @author Joachim Kudish <[email protected]>
* @link http://jkudish.com
*
* credit to: Andrew Nacin (Log Deprecated Notices)
*
* @todo make notices show up in the Debug Bar
* @todo show error messages if Log Deprecated Notices isn't installed
* @todo show error messages if WP 3.3 isn't installed
*/
// Don't load directly
if ( !defined('ABSPATH') ) { die('-1'); }
if (!class_exists( 'Deprecated_Log_Extender' ) ) :
class Deprecated_Log_Extender {
public $count;
public $title;
/**
* class constructors, where we hook the other stuff
* @return void
*/
public function __construct() {
add_action('admin_bar_menu', array( &$this, 'manageToolbar'), 1001); // run it late in the game
}
/**
* count how many of notices there are and setup the title accordingly
* @uses $wdb
* @return void
*/
public function count() {
global $wpdb;
$this->count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = %s AND post_date > %s AND post_status = %s", Deprecated_Log::pt, Deprecated_Log::$instance->options['last_viewed'], 'publish' ) );
$this->title = ( $this->count ) ? sprintf( __( 'Deprecated Calls <small>%s</small>', 'log-deprecated' ),number_format_i18n( $this->count ) ) : __( 'Deprecated Calls', 'log-deprecated' );
}
/**
* hooks into the toolbar to add our new menu item
* @param $toolbar the toolbar object
* @return void
*/
public function manageToolbar($toolbar) {
$classes = apply_filters( 'deprecated_log_extender_classses', array() );
$classes = implode( " ", $classes );
$this->count();
$toolbar->add_node( array(
'id' => 'deprecated_log_extender',
'parent' => 'top-secondary',
'title' => apply_filters( 'deprecated_log_extender_title', $this->title ),
'href' => add_query_arg( 'post_type', Deprecated_Log::pt, admin_url('edit.php') ),
'meta' => array( 'class' => $classes ),
) );
}
} // end class
/**
* make sure to init the class after Deprecated_Log has loaded
* and only in the admin
*/
add_action('admin_init', 'DeprecatedLogExtenderInit');
function DeprecatedLogExtenderInit() {
if ( class_exists('Deprecated_Log') )
new Deprecated_Log_Extender();
}
endif;