PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.3.2
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.3.2
4.3.2 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 All 165 releases
adminify / Inc / Modules / DashboardWidget / DashboardWidget.php

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

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