/
AddActionsAndFilters_ViewAdminPage.php
148 lines (125 loc) · 5.32 KB
/
AddActionsAndFilters_ViewAdminPage.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
<?php
/*
"Add Shortcodes, Actions and Filters" Copyright (C) 2013-2023 Michael Simpson (email : michael.d.simpson@gmail.com)
This file is part of Add Actions and Filters for WordPress.
Add Actions and Filters is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Add Actions and Filters is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Contact Form to Database Extension.
If not, see <http://www.gnu.org/licenses/>.
*/
require_once('AddActionsAndFilters_AdminPageActions.php');
class AddActionsAndFilters_ViewAdminPage
{
/**
* @var AddActionsAndFilters_Plugin
*/
var $plugin;
/**
* @var AddActionsAndFilters_CodeListTable
*/
var $table;
/**
* Sets Admin page screen options
*/
public static function addAdminPageScreenOptions()
{
require_once('AddActionsAndFilters_DataModelConfig.php');
$option = 'per_page';
$args = array(
'label' => 'Code Items',
'default' => AddActionsAndFilters_DataModelConfig::PER_PAGE_DEFAULT,
'option' => AddActionsAndFilters_DataModelConfig::PER_PAGE_OPTION
);
add_screen_option($option, $args);
}
// set-screen-option callback - does not work
// public static function setScreenOptionCallback($status, $option, $value)
// {
// // http://chrismarslender.com/2012/01/26/wordpress-screen-options-tutorial/
// if (AddActionsAndFilters_DataModelConfig::PER_PAGE_OPTION == $option) {
// return $value;
// }
// return $status;
// }
// Work-around for the above callback not working
public static function setScreenOptionCallback($option, $value)
{
if (AddActionsAndFilters_DataModelConfig::PER_PAGE_OPTION == $option) {
$userId = get_current_user_id();
if ($userId != 0) {
update_user_option($userId, $option, $value);
}
}
}
public static function addHelpTab()
{
$screen = get_current_screen();
$screen->add_help_tab(array(
'id' => 'AddActionsAndFilters_help',
'title' => __('Help'),
'content' =>
'<a href="https://codex.wordpress.org/Shortcode_API" target="_blank">Shortcode</a></br>
<a href="https://codex.wordpress.org/Function_Reference/add_action" target="_blank">add_action</a></br>
<a href="https://codex.wordpress.org/Function_Reference/add_filter" target="_blank">add_filter</a>',
//'callback' => $callback
));
}
public function __construct(&$plugin, &$table)
{
$this->plugin = $plugin;
$this->table = $table;
}
public function display()
{
require_once('AddActionsAndFilters_AdminViewUrlBuilder.php');
$urlBuilder = new AddActionsAndFilters_AdminViewUrlBuilder();
$cleanUrl = $urlBuilder->buildUrl(); // no action value in it
echo '<div class="wrap">';
// Header
$adminUrl = get_admin_url() . 'admin.php?page=';
printf('<table width="%s"><tbody><tr><td><a href="%s"><img src="%s"/></a></td><td align="right"><span style="white-space: nowrap;"><a href="%s"><img src="%s"/></a><a href="%s"><img src="%s"/></a></span></td></tr></tbody></table>',
'100%',
$cleanUrl,
$this->plugin->getPluginFileUrl('img/admin-banner.png'),
$adminUrl . $this->plugin->getImportExportSlug(),
$this->plugin->getPluginFileUrl('img/import-export.png'),
$adminUrl . $this->plugin->getSettingsSlug(),
$this->plugin->getPluginFileUrl('img/settings.png')
);
printf('<table><tbody><tr><td></td></tr></tbody></table>');
$actions = new AddActionsAndFilters_AdminPageActions();
printf('<a href="%s%s%s%s%s" class="page-title-action">%s</a>',
get_admin_url(),
'admin.php?page=',
$this->plugin->getAdminPageSlug(),
'&action=',
$actions->getEditKey(),
__('Add New'));
// Table Styles
echo '<style type="text/css">';
echo '.wp-list-table .column-id { width: 7%; }';
echo '.wp-list-table .column-enabled { width: 10%; }';
echo '.wp-list-table .column-shortcode { width: 7%; }';
echo '.wp-list-table .column-name { width: 25%; }';
echo '.wp-list-table .column-capability { width: 20%; }';
echo '.wp-list-table .column-description { width: 31%; }';
echo '.wp-list-table .item-inactive { font-style: italic; opacity: 0.6; filter: alpha(opacity = 60); /* MSIE */ }';
echo '</style>';
// Form for bulk actions
printf('<form action="%s" method="post">', $cleanUrl);
// Search box
$this->table->search_box('search', 'search_id');
// Code table
$this->table->display();
// Closing Tags
echo '</form>';
echo '</div>';
}
}