-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin-monitor.php
executable file
·186 lines (159 loc) · 6.43 KB
/
plugin-monitor.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/*
Plugin Name: Plugin Monitor
Plugin URI: https://github.com/emtiazzahid/plugin_monitor.git
Description: A Plugin To Track WordPress Plugin Unresolved Support Issues Using Ajax & WP List Table
Author: Md. Emtiaz Zahid
Author URI: https://github.com/emtiazzahid
Version: 1.0.0
*/
global $wpdb;
define('PLUG_MONITOR_PLUGIN_URL', plugin_dir_url( __FILE__ ));
define('PLUG_MONITOR_PLUGIN_PATH', plugin_dir_path( __FILE__ ));
require_once __DIR__ . '/helper-functions.php';
register_activation_hook( __FILE__, 'activate_plug_monitor_plugin_function' );
register_deactivation_hook( __FILE__, 'deactivate_plug_monitor_plugin_function' );
function activate_plug_monitor_plugin_function() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$table_name = 'wp_plugin_monitor';
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
`id` bigint(11) unsigned NOT NULL AUTO_INCREMENT,
`slug` varchar(255),
`created_at` varchar(255),
`updated_at` varchar(255),
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
function deactivate_plug_monitor_plugin_function() {
global $wpdb;
$table_name = 'wp_plugin_monitor';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query($sql);
}
function load_custom_css_js( $page ) {
wp_enqueue_style( 'my_custom_css', PLUG_MONITOR_PLUGIN_URL.'/css/style.css', false, '1.0.0' );
if ($page == 'toplevel_page_plugin-monitor'){
wp_enqueue_script( 'my_custom_script1', PLUG_MONITOR_PLUGIN_URL. '/js/custom.js' );
wp_enqueue_script( 'pm_moment_js', PLUG_MONITOR_PLUGIN_URL. '/js/moment.js' );
}
if ($page == 'plugin-monitor_page_manage-plugin'){
wp_enqueue_script( 'my_custom_script2', PLUG_MONITOR_PLUGIN_URL. '/js/manage_plugin.js' );
}
}
add_action( 'admin_enqueue_scripts', 'load_custom_css_js' );
require_once(PLUG_MONITOR_PLUGIN_PATH.'/ajax/ajax_action.php');
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('Plugin Monitor', 'Plugin Monitor', 'manage_options', 'plugin-monitor', 'my_menu_output' );
add_submenu_page('plugin-monitor', 'Plugin Monitor - New Plugins', 'New Plugin', 'manage_options', 'manage-plugin', 'new_plugin_page' );
add_submenu_page('plugin-monitor', 'Plugin Monitor - View Plugins', 'View Plugins', 'manage_options', 'view-plugin', 'my_submenu_output' );
}
function my_menu_output() {
require_once(PLUG_MONITOR_PLUGIN_PATH.'/admin-templates/index.php');
}
function new_plugin_page() {
require_once(PLUG_MONITOR_PLUGIN_PATH.'/admin-templates/new_plugin.php');
}
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class EntryListTable extends WP_List_Table {
function __construct() {
global $status, $page;
parent::__construct(array(
'singular' => 'Entry Data',
'plural' => 'Entry Datas',
));
}
function column_default($item, $column_name) {
switch($column_name){
case 'action': echo '<a href="'.admin_url('admin.php?page=manage-plugin&entryid='.$item['id']).'">Edit</a>';
}
return $item[$column_name];
}
function column_feedback_name($item) {
$actions = array( 'delete' => sprintf('<a href="?page=%s&action=delete&id=%s">%s</a>', $_REQUEST['page'], $item['id']) );
return sprintf('%s %s', $item['id'], $this->row_actions($actions) );
}
function column_cb($item) {
return sprintf( '<input type="checkbox" name="id[]" value="%s" />', $item['id'] );
}
function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'slug'=> 'Title',
'action' => 'Action'
);
return $columns;
}
function get_sortable_columns() {
$sortable_columns = array(
'slug' => array('slug', true)
);
return $sortable_columns;
}
function get_bulk_actions() {
$actions = array( 'delete' => 'Delete' );
return $actions;
}
function process_bulk_action() {
global $wpdb;
$table_name = "wp_plugin_monitor";
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['id']) ? $_REQUEST['id'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->query("DELETE FROM $table_name WHERE id IN($ids)");
}
}
}
function prepare_items() {
global $wpdb,$current_user;
$table_name = "wp_plugin_monitor";
$per_page = 10;
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array($columns, $hidden, $sortable);
$this->process_bulk_action();
$total_items = $wpdb->get_var("SELECT COUNT(id) FROM $table_name");
$paged = isset($_REQUEST['paged']) ? max(0, intval($_REQUEST['paged']) - 1) : 0;
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? $_REQUEST['orderby'] : 'id';
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'desc';
if(isset($_REQUEST['s']) && $_REQUEST['s']!='') {
$this->items = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE `slug` LIKE '%".$_REQUEST['s']."%' ORDER BY $orderby $order LIMIT %d OFFSET %d", $per_page, $paged * $per_page), ARRAY_A);
} else {
$this->items = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name ORDER BY $orderby $order LIMIT %d OFFSET %d", $per_page, $paged * $per_page), ARRAY_A);
}
$this->set_pagination_args(array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil($total_items / $per_page)
));
}
}
function my_submenu_output() {
global $wpdb;
$table = new EntryListTable();
$table->prepare_items();
$message = '';
if ('delete' === $table->current_action()) {
$message = '<div class="div_message" id="message"><p>' . sprintf('Items deleted: %d', count($_REQUEST['id'])) . '</p></div>';
}
ob_start();
?>
<div class="wrap wqmain_body">
<h3>View Entries</h3>
<?php echo $message; ?>
<form id="entry-table" method="GET">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>"/>
<?php $table->search_box( 'search', 'search_id' ); $table->display() ?>
</form>
</div>
<?php
$wq_msg = ob_get_clean();
echo $wq_msg;
}