PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.3.0
Adminify – White Label, Admin Menu Editor, Login Customizer v4.3.0
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / DashboardWidget / DashboardWidget.php

DashboardWidget.php in Adminify – White Label, Admin Menu Editor, Login Customizer 4.3.0, at Inc/Modules/DashboardWidget/DashboardWidget.php

419 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PXLBSAdminify\Inc\Modules\DashboardWidget;
4
5 use PXLBSAdminify\Inc\Utils;
6 use PXLBSAdminify\Inc\Classes\Multisite_Helper;
7 use PXLBSAdminify\Inc\Modules\DashboardWidget\DashboardWidgetModel;
8
9 // no direct access allowed
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * PXLBSAdminify
16 *
17 * @package Module: Dashboard Widget
18 *
19 * @author Jewel Theme <support@jeweltheme.com>
20 */
21
22 class DashboardWidget extends DashboardWidgetModel {
23
24 public $url;
25 public $roles;
26 public $options;
27 public $current_role;
28
29 public function __construct() {
30 $this->options = ( new DashboardWidget_Setttings() )->get();
31
32 if ( is_admin() ) {
33 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
34 add_action( 'wp_dashboard_setup', [ $this, 'create_dashboard_widgets' ], 999 );
35 add_action( 'wp_network_dashboard_setup', [ $this, 'create_dashboard_widgets' ], 999 );
36
37 if ( shortcode_exists( 'elementor-template' ) ) {
38 add_action( 'wp_loaded', [ $this, 'override_elementor_shortcodes' ] );
39 }
40
41 // Welcome Panel Initialize
42 if( ! get_user_meta( get_current_user_id(), 'pxlbsadminify_dismissed_welcome_panel', true )){
43 add_action( 'admin_init', [ $this, 'welcome_init' ] );
44 }
45 add_action('admin_init', function() {
46 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change.
47 if ( isset( $_GET['welcome'] ) && '0' === sanitize_text_field( wp_unslash( $_GET['welcome'] ) ) ) {
48 update_user_meta(get_current_user_id(), 'pxlbsadminify_dismissed_welcome_panel', true);
49 }
50 });
51 }
52 }
53 /**
54 * Override elementor-template shortcode
55 */
56 public function override_elementor_shortcodes() {
57 add_shortcode( 'elementor-template', [ $this, 'override_elementor_template' ] );
58 }
59
60 public function override_elementor_template( $atts ) {
61 extract(
62 shortcode_atts(
63 [
64 'id' => '',
65 ],
66 $atts
67 )
68 );
69
70 $elementor = \Elementor\Plugin::$instance;
71 $output = '';
72 $output .= $elementor->frontend->register_styles();
73 $output .= $elementor->frontend->enqueue_styles();
74
75 $output .= $elementor->frontend->get_builder_content( $id, true );
76
77 $output .= $elementor->frontend->register_scripts();
78 $output .= $elementor->frontend->enqueue_scripts();
79
80 return $output;
81 }
82
83
84 /**
85 * Welcome Panel Initialize
86 */
87 public function welcome_init() {
88 if ( empty( $this->options['dashboard_widget_types'] ) ) {
89 return;
90 }
91
92 $option = ! empty( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '';
93
94 if ( ! empty( $option['enable_custom_welcome_dash_widget'] ) ) {
95 // Restricted for User Roles
96 // $restricted_for_dash_widget = ! empty( $option['user_roles'] ) ? $option['user_roles'] : '';
97 // if ( !Utils::restricted_for( $restricted_for_dash_widget ) ) {
98 // return;
99 // }
100 $this->render_welcome_panel_output();
101 }
102 }
103
104 /**
105 * Render Welcome Panel Content
106 *
107 * @return void
108 */
109 public function render_welcome_panel_output() {
110 remove_action( 'welcome_panel', 'wp_welcome_panel' );
111 add_action( 'welcome_panel', [ $this, 'render_welcome_panel' ] );
112
113 // custom fallback for the users who don't have
114 // enough capabilities to display welcome panel.
115 if ( ! current_user_can( 'edit_theme_options' ) ) {
116 add_action( 'admin_notices', [ $this, 'render_welcome_panel' ] );
117 }
118 }
119
120 /**
121 * Render Welcome Panel
122 *
123 * @return void
124 */
125 public function render_welcome_panel() {
126 $latest_wordpress_version = get_bloginfo( 'version' );
127
128 ?>
129 <div class="welcome-panel-content adminify-panel-content">
130 <?php if($latest_wordpress_version >= '6.2'){ ?>
131 <div class="welcome-panel-header">
132 <?php if ( current_user_can( 'edit_theme_options' ) ) { ?>
133 <a class="welcome-panel-close" href="<?php echo esc_url( admin_url( '?welcome=0' ) ); ?>"><?php esc_html_e( 'Dismiss', 'adminify' ); ?></a>
134 <?php } ?>
135 <?php $this->render_welcome_template(); ?>
136 </div>
137 <style>
138 .wp-adminify .welcome-panel{
139 background-color: #fff !important;
140 }
141 .wp-adminify #wpbody-content .adminify-panel-content{
142 margin: auto auto;
143 padding:0;
144 }
145 .wp-adminify #wpbody-content .welcome-panel-header{
146 padding: 30px !important;
147 max-width: inherit !important;
148 padding-top: 50px !important;
149 }
150 </style>
151 <?php } else{ ?>
152
153 <?php if ( current_user_can( 'edit_theme_options' ) ) { ?>
154 <a class="welcome-panel-close" href="<?php echo esc_url( admin_url( '?welcome=0' ) ); ?>"><?php esc_html_e( 'Dismiss', 'adminify' ); ?></a>
155 <?php }
156 $this->render_welcome_template();
157 } ?>
158 </div>
159
160 <?php if ( current_user_can( 'manage_options' ) ) { ?>
161 <script type="text/javascript">
162 ;
163 (function($) {
164 $(document).ready(function() {
165 $('<div id="adminify-welcome-panel" class="adminify-welcome-panel"></div>').insertBefore('#dashboard-widgets-wrap').append($('.adminify-panel-content'));
166 });
167 })(jQuery);
168 </script>
169 <?php }
170 }
171
172 public function render_welcome_template() {
173 $option = isset( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '';
174
175 if ( isset( $option['widget_template_type'] ) && ! empty( $option['widget_template_type'] ) ) {
176 $from_multisite = false;
177 $ms_helper = new Multisite_Helper();
178 $switch_blog = $from_multisite && $ms_helper->needs_to_switch_blog() ? true : false;
179
180 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
181 $elementor = \Elementor\Plugin::$instance;
182 }
183
184 $css = ''; // Initialize the CSS variable
185 $css = apply_filters('pxlbsadminify_dashboard_widgets/welcome_css', $css); // Apply the filter
186
187 echo '<style>';
188 echo Utils::kses_custom($css); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped.
189 echo '</style>';
190
191 // echo '<style>';
192 // $css = '';
193 // echo apply_filters('pxlbsadminify_dashboard_widgets/dismissible', $css);
194 // echo '</style>';
195
196
197 if ( $switch_blog ) {
198 global $pxlbsadminify_blueprint;
199 switch_to_blog( $pxlbsadminify_blueprint );
200 }
201
202 switch ( $option['widget_template_type'] ) {
203 case 'specific_page':
204 // $page_id = $option['custom_page'];
205 // if ( $page_id ) {
206 // $page = get_page( $page_id );
207 // $content = apply_filters( 'the_content', $page->post_content );
208 // $content = str_replace( ']]>', ']]&gt;', $content );
209 // echo wp_specialchars_decode( Utils::kses_custom( $content ) );
210 // }
211
212 $panel_height = !empty( $option['panel_height'] ) ? $option['panel_height'] : 600;
213
214 $link = get_permalink($option['custom_page']);
215 $link = add_query_arg('bknd', 1, $link);
216 printf('<iframe class="wp-adminify--admin-page" src="%s"></iframe>', esc_url( $link ) );
217 echo '<style>
218 .welcome-panel-header{
219 height: '. esc_attr( $panel_height ) .'px;
220 overflow: hidden;
221 }
222 #wpbody{
223 overflow:hidden;
224 }
225 #wpbody-content {
226 position: relative;
227 overflow: hidden;
228 }
229 iframe.wp-adminify--admin-page {
230 width: 100%;
231 height: 100%;
232 position: relative;
233 }
234 </style>';
235
236 break;
237
238 case 'elementor_template':
239 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
240 $template_id = $option['elementor_template_id'];
241 if ( $template_id ) {
242 $elementor->frontend->register_styles();
243 $elementor->frontend->enqueue_styles();
244
245 echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped.
246
247 $elementor->frontend->register_scripts();
248 $elementor->frontend->enqueue_scripts();
249 }
250 }
251 break;
252
253 case 'elementor_section':
254 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
255 $template_id = $option['elementor_section_id'];
256 if ( $template_id ) {
257 $elementor->frontend->register_styles();
258 $elementor->frontend->enqueue_styles();
259
260 echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped.
261
262 $elementor->frontend->register_scripts();
263 $elementor->frontend->enqueue_scripts();
264 }
265 }
266 break;
267
268 case 'elementor_widget':
269 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
270 $template_id = $option['elementor_widget_id'];
271 if ( $template_id ) {
272 $elementor->frontend->register_styles();
273 $elementor->frontend->enqueue_styles();
274
275 echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped.
276
277 $elementor->frontend->register_scripts();
278 $elementor->frontend->enqueue_scripts();
279 }
280 }
281 break;
282
283 case 'oxygen_template':
284 if ( is_plugin_active( 'oxygen/functions.php' ) ) {
285 $template_id = $option['oxygen_template_id'];
286 if ( $template_id ) {
287 echo do_shortcode( get_post_meta( $template_id, 'ct_builder_shortcodes', true ) );
288 }
289 }
290 break;
291 }
292
293 if ( $switch_blog ) {
294 restore_current_blog();
295 }
296 }
297 }
298
299 // Add Custom Dashboard Widgets
300 public function create_dashboard_widgets() {
301 $options = $this->options;
302
303 $options = ! empty( $this->options['dashboard_widget_types']['dashboard_widgets'] ) ? $this->options['dashboard_widget_types']['dashboard_widgets'] : '';
304 if ( empty( $options ) ) {
305 return;
306 }
307
308 $before_content = '';
309 $after_content = '';
310 $dash_widget_data = [];
311
312 foreach ( $options as $value ) {
313 if ( is_array( $value ) && ! empty( $value ) ) {
314
315 // Allowed User Roles. An empty list means the widget is not limited to
316 // particular roles, so it shows for everyone — that is the field's
317 // default, and without this check a newly created widget would never
318 // appear. Anything else is treated as an allow list.
319 //
320 // `continue`, not `return`: skipping one widget must not stop the rest
321 // of the list from being registered.
322 $restricted_for_dash_widget = ! empty( $value['user_roles'] ) ? $value['user_roles'] : '';
323
324 if ( ! empty( $restricted_for_dash_widget ) && ! Utils::restricted_for( $restricted_for_dash_widget ) ) {
325 continue;
326 }
327
328 $dash_widget_title = isset( $value['title'] ) ? $value['title'] : '';
329 $dash_widget_position = isset( $value['widget_pos'] ) ? $value['widget_pos'] : 'normal';
330
331 add_meta_box(
332 'adminify_widget_' . Utils::class_cleanup( $dash_widget_title ),
333 $dash_widget_title,
334 [ $this, 'render_dashboard_widget' ],
335 'dashboard',
336 $dash_widget_position,
337 'high',
338 $value
339 );
340 }
341 }
342 }
343
344
345 // Render Dashboard Widget
346 public function render_dashboard_widget( $content = '', $value = '' ) {
347 switch ( $value['args']['widget_type'] ) {
348 case 'editor':
349 echo wp_kses_post( $value['args']['dashw_type_editor'] );
350 break;
351
352 case 'icon':
353 do_action('pxlbsadminify_dashboard_widgets/render_icon', $value);
354 break;
355
356 case 'video':
357 do_action('pxlbsadminify_dashboard_widgets/render_video', $value);
358 break;
359
360 case 'shortcode':
361 do_action('pxlbsadminify_dashboard_widgets/render_shortcode', $value);
362 break;
363
364 case 'rss_feed':
365 do_action('pxlbsadminify_dashboard_widgets/render_rss_feed', $value);
366 break;
367
368 case 'script':
369 do_action('pxlbsadminify_dashboard_widgets/render_script', $value);
370 break;
371 }
372 }
373
374
375
376
377 /**
378 * Scripst / Styles
379 */
380 public function enqueue_scripts() {
381 global $pagenow;
382
383 // Load Scripts/Styles only WP Adminify Dashboard Widget
384 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change.
385 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
386 if ( ( 'admin.php' === $pagenow ) && ( 'adminify-dashboard-widgets' === $current_page ) ) {
387 $this->dashboard_widgets_admin_script();
388 }
389 }
390
391
392 // WP Adminify Dashboard Widgets Style
393 public function dashboard_widgets_admin_script() {
394 echo '<style>.wp-adminify-dashboard-widgets .adminify-container{ max-width:1200px; margin:0 auto; background: #fff;} .wp-adminify-dashboard-widgets .adminify-header-inner{padding:0;}.wp-adminify-dashboard-widgets .adminify-field-subheading{font-size:20px; padding-left:0;}.adminify-dashboard-widgets .adminify-nav,.adminify-dashboard-widgets .adminify-search,.adminify-dashboard-widgets .adminify-footer,.adminify-dashboard-widgets .adminify-reset-all,.adminify-dashboard-widgets .adminify-expand-all,.adminify-dashboard-widgets .adminify-header-left,.adminify-dashboard-widgets .adminify-reset-section,.adminify-dashboard-widgets .adminify-nav-background{display: none !important;}.adminify-dashboard-widgets .adminify-nav-normal + .adminify-content{margin-left: 0;}
395 /*
396 .wp-adminify #wpbody-content .adminify-section[data-section-id] .adminify-data-wrapper .adminify-cloneable-item .adminify-cloneable-title{ border:none !important; }
397 */
398 /* If needed for white top-bar */
399 .adminify-dashboard-widgets .adminify-header-inner {
400 background-color: #fafafa !important;
401 border-bottom: 1px solid #f5f5f5;
402 }
403 .wp-adminify-dashboard-widgets .button-primary {
404 background: var(--adminify-primary)!important;
405 transition: all 0.15s;
406 }
407 .wp-adminify-dashboard-widgets .button-primary:hover {
408 background: transparent!important;
409 color: var(--adminify-primary)!important;
410 }
411 .wp-adminify-dashboard-widgets .adminify-header .adminify-header-right{
412 display: flex;
413 align-item: center;
414 justify-content: end;
415 }
416 </style>';
417 }
418 }
419