PluginProbe
Restrict User Access – Ultimate Membership & Content Protection / 2.4
Restrict User Access – Ultimate Membership & Content Protection v2.4
trunk 1.3 2.0 2.1.3 2.2.3 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.7.1 2.8 2.8.1
restrict-user-access / admin / admin.php

admin.php in Restrict User Access – Ultimate Membership & Content Protection 2.4, at admin/admin.php

236 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Restrict User Access
4 * @author Joachim Jensen <joachim@dev.institute>
5 * @license GPLv3
6 * @copyright 2022 by Joachim Jensen
7 */
8
9 defined('ABSPATH') || exit;
10
11 abstract class RUA_Admin
12 {
13 /**
14 * Screen identifier
15 * @var string
16 */
17 protected $_screen;
18
19 public function __construct()
20 {
21 if (is_admin()) {
22 $this->add_action('admin_menu', 'add_menu', 99);
23 $this->admin_hooks();
24 } else {
25 $this->frontend_hooks();
26 }
27 }
28
29 /**
30 * Set up screen and menu if necessary
31 *
32 * @since 0.15
33 */
34 public function add_menu()
35 {
36 $this->_screen = $this->get_screen();
37 $this->add_action('load-' . $this->_screen, 'load_screen');
38 }
39
40 /**
41 * Add filters and actions for admin dashboard
42 * e.g. AJAX calls
43 *
44 * @since 0.15
45 * @return void
46 */
47 abstract public function admin_hooks();
48
49 /**
50 * Add filters and actions for frontend
51 *
52 * @since 0.15
53 * @return void
54 */
55 abstract public function frontend_hooks();
56
57 /**
58 * Get current screen
59 *
60 * @since 0.15
61 * @return string
62 */
63 abstract public function get_screen();
64
65 /**
66 * Prepare screen load
67 *
68 * @since 0.15
69 * @return void
70 */
71 abstract public function prepare_screen();
72
73 /**
74 * Authorize user for screen
75 *
76 * @since 0.15
77 * @return boolean
78 */
79 abstract public function authorize_user();
80
81 /**
82 * Register and enqueue scripts styles
83 * for screen
84 *
85 * @since 0.15
86 */
87 abstract public function add_scripts_styles();
88
89 /**
90 * Prepare plugin upgrade modal
91 *
92 * @since 0.15
93 * @return void
94 */
95 public function load_screen()
96 {
97 if (!$this->authorize_user()) {
98 wp_die(
99 '<p>' . __('You do not have access to this screen.', 'restrict-user-access') . '</p>',
100 403
101 );
102 }
103
104 $path = plugin_dir_path(__FILE__) . '../view/';
105 $view = WPCAView::make($path . '/top_bar.php', [
106 'freemius' => rua_fs()
107 ]);
108
109 add_action('in_admin_header', [$view, 'render']);
110
111 $this->prepare_screen();
112 $this->add_action('admin_enqueue_scripts', 'add_general_scripts_styles', 11);
113 }
114
115 /**
116 * Add general scripts to admin screens
117 *
118 * @since 1.2
119 */
120 public function add_general_scripts_styles()
121 {
122 $this->enqueue_style('rua/admin/style', 'style');
123 $this->add_scripts_styles();
124 }
125
126 /**
127 * @return WP_Post_Type
128 */
129 protected function get_restrict_type()
130 {
131 return get_post_type_object(RUA_App::TYPE_RESTRICT);
132 }
133
134 /**
135 * @since 1.2
136 * @param string $tag
137 * @param string $callback
138 * @param int $priority
139 * @param int $accepted_args
140 *
141 * @return void
142 */
143 protected function add_action($tag, $callback, $priority = 10, $accepted_args = 1)
144 {
145 if (is_string($callback)) {
146 $callback = [$this, $callback];
147 }
148 add_action($tag, $callback, $priority, $accepted_args);
149 }
150
151 /**
152 * @since 1.2
153 * @param string $tag
154 * @param string $callback
155 * @param int $priority
156 * @param int $accepted_args
157 *
158 * @return void
159 */
160 protected function add_filter($tag, $callback, $priority = 10, $accepted_args = 1)
161 {
162 if (is_string($callback)) {
163 $callback = [$this, $callback];
164 }
165 add_filter($tag, $callback, $priority, $accepted_args);
166 }
167
168 /**
169 * @since 1.2
170 * @param string $handle
171 * @param string $filename
172 * @param array $deps
173 * @param bool $in_footer
174 * @param string $ver
175 *
176 * @return void
177 */
178 protected function enqueue_script($handle, $filename, $deps = [], $ver = '', $in_footer = false)
179 {
180 $this->register_script($handle, $filename, $deps, $ver, $in_footer);
181 wp_enqueue_script($handle);
182 }
183
184 /**
185 * @since 1.2
186 * @param string $handle
187 * @param string $filename
188 * @param array $deps
189 * @param bool $in_footer
190 * @param string $ver
191 *
192 * @return void
193 */
194 protected function register_script($handle, $filename, $deps = [], $ver = '', $in_footer = false)
195 {
196 $suffix = '.min.js';
197 if ($ver === '') {
198 $ver = RUA_App::PLUGIN_VERSION;
199 }
200 wp_register_script($handle, plugins_url('assets/js/' . $filename . $suffix, dirname(__FILE__)), $deps, $ver, $in_footer);
201 }
202
203 /**
204 * @since 1.2
205 * @param string $handle
206 * @param string $filename
207 * @param array $deps
208 * @param string $ver
209 *
210 * @return void
211 */
212 protected function enqueue_style($handle, $filename, $deps = [], $ver = '')
213 {
214 $this->register_style($handle, $filename, $deps, $ver);
215 wp_enqueue_style($handle);
216 }
217
218 /**
219 * @since 1.2
220 * @param string $handle
221 * @param string $filename
222 * @param array $deps
223 * @param string $ver
224 *
225 * @return void
226 */
227 protected function register_style($handle, $filename, $deps = [], $ver = '')
228 {
229 $suffix = '.css';
230 if ($ver === '') {
231 $ver = RUA_App::PLUGIN_VERSION;
232 }
233 wp_enqueue_style($handle, plugins_url('assets/css/' . $filename . $suffix, dirname(__FILE__)), $deps, $ver);
234 }
235 }
236