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

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