PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.2.21
Adminify – White Label, Admin Menu Editor, Login Customizer v4.2.21
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.2.21, at Inc/Modules/DashboardWidget/DashboardWidget.php

413 lines 13.3 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 // Restricted for User Roles
316 $restricted_for_dash_widget = ! empty( $value['user_roles'] ) ? $value['user_roles'] : '';
317
318 if ( ! Utils::restricted_for( $restricted_for_dash_widget ) ) {
319 return;
320 }
321
322 $dash_widget_title = isset( $value['title'] ) ? $value['title'] : '';
323 $dash_widget_position = isset( $value['widget_pos'] ) ? $value['widget_pos'] : 'normal';
324
325 add_meta_box(
326 'adminify_widget_' . Utils::class_cleanup( $dash_widget_title ),
327 $dash_widget_title,
328 [ $this, 'render_dashboard_widget' ],
329 'dashboard',
330 $dash_widget_position,
331 'high',
332 $value
333 );
334 }
335 }
336 }
337
338
339 // Render Dashboard Widget
340 public function render_dashboard_widget( $content = '', $value = '' ) {
341 switch ( $value['args']['widget_type'] ) {
342 case 'editor':
343 echo wp_kses_post( $value['args']['dashw_type_editor'] );
344 break;
345
346 case 'icon':
347 do_action('pxlbsadminify_dashboard_widgets/render_icon', $value);
348 break;
349
350 case 'video':
351 do_action('pxlbsadminify_dashboard_widgets/render_video', $value);
352 break;
353
354 case 'shortcode':
355 do_action('pxlbsadminify_dashboard_widgets/render_shortcode', $value);
356 break;
357
358 case 'rss_feed':
359 do_action('pxlbsadminify_dashboard_widgets/render_rss_feed', $value);
360 break;
361
362 case 'script':
363 do_action('pxlbsadminify_dashboard_widgets/render_script', $value);
364 break;
365 }
366 }
367
368
369
370
371 /**
372 * Scripst / Styles
373 */
374 public function enqueue_scripts() {
375 global $pagenow;
376
377 // Load Scripts/Styles only WP Adminify Dashboard Widget
378 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change.
379 $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
380 if ( ( 'admin.php' === $pagenow ) && ( 'adminify-dashboard-widgets' === $current_page ) ) {
381 $this->dashboard_widgets_admin_script();
382 }
383 }
384
385
386 // WP Adminify Dashboard Widgets Style
387 public function dashboard_widgets_admin_script() {
388 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;}
389 /*
390 .wp-adminify #wpbody-content .adminify-section[data-section-id] .adminify-data-wrapper .adminify-cloneable-item .adminify-cloneable-title{ border:none !important; }
391 */
392 /* If needed for white top-bar */
393 .adminify-dashboard-widgets .adminify-header-inner {
394 background-color: #fafafa !important;
395 border-bottom: 1px solid #f5f5f5;
396 }
397 .wp-adminify-dashboard-widgets .button-primary {
398 background: var(--adminify-primary)!important;
399 transition: all 0.15s;
400 }
401 .wp-adminify-dashboard-widgets .button-primary:hover {
402 background: transparent!important;
403 color: var(--adminify-primary)!important;
404 }
405 .wp-adminify-dashboard-widgets .adminify-header .adminify-header-right{
406 display: flex;
407 align-item: center;
408 justify-content: end;
409 }
410 </style>';
411 }
412 }
413