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

352 lines 13.5 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 // no direct access allowed
9 if ( !defined( 'ABSPATH' ) ) {
10 exit;
11 }
12 /**
13 * WPAdminify
14 *
15 * @package Module: Dashboard Widget
16 *
17 * @author Jewel Theme <support@jeweltheme.com>
18 */
19 class DashboardWidget extends DashboardWidgetModel {
20 public $url;
21
22 public $roles;
23
24 public $options;
25
26 public $current_role;
27
28 public function __construct() {
29 $this->options = ( new DashboardWidget_Setttings() )->get();
30 if ( is_admin() ) {
31 add_action( 'admin_enqueue_scripts', [$this, 'jltwp_adminify_enqueue_scripts'] );
32 add_action( 'wp_dashboard_setup', [$this, 'create_dashboard_widgets'], 999 );
33 add_action( 'wp_network_dashboard_setup', [$this, 'create_dashboard_widgets'], 999 );
34 if ( shortcode_exists( 'elementor-template' ) ) {
35 add_action( 'wp_loaded', [$this, 'override_elementor_shortcodes'] );
36 }
37 // Welcome Panel Initialize
38 add_action( 'admin_init', [$this, 'jltwp_adminify_welcome_init'] );
39 }
40 }
41
42 /**
43 * Override elementor-template shortcode
44 */
45 public function override_elementor_shortcodes() {
46 add_shortcode( 'elementor-template', [$this, 'override_elementor_template'] );
47 }
48
49 public function override_elementor_template( $atts ) {
50 extract( shortcode_atts( [
51 'id' => '',
52 ], $atts ) );
53 $elementor = \Elementor\Plugin::$instance;
54 $output = '';
55 $output .= $elementor->frontend->register_styles();
56 $output .= $elementor->frontend->enqueue_styles();
57 $output .= $elementor->frontend->get_builder_content( $id, true );
58 $output .= $elementor->frontend->register_scripts();
59 $output .= $elementor->frontend->enqueue_scripts();
60 return $output;
61 }
62
63 /**
64 * Welcome Panel Initialize
65 */
66 public function jltwp_adminify_welcome_init() {
67 if ( empty( $this->options['dashboard_widget_types'] ) ) {
68 return;
69 }
70 $option = ( !empty( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '' );
71 if ( !empty( $option['enable_custom_welcome_dash_widget'] ) ) {
72 // Restricted for User Roles
73 $restricted_for_dash_widget = ( !empty( $option['user_roles'] ) ? $option['user_roles'] : '' );
74 if ( Utils::restricted_for( $restricted_for_dash_widget ) ) {
75 return;
76 }
77 $this->render_welcome_panel_output();
78 }
79 }
80
81 /**
82 * Render Welcome Panel Content
83 *
84 * @return void
85 */
86 public function render_welcome_panel_output() {
87 remove_action( 'welcome_panel', 'wp_welcome_panel' );
88 add_action( 'welcome_panel', [$this, 'render_welcome_panel'] );
89 // custom fallback for the users who don't have
90 // enough capabilities to display welcome panel.
91 if ( !current_user_can( 'edit_theme_options' ) ) {
92 add_action( 'admin_notices', [$this, 'render_welcome_panel'] );
93 }
94 }
95
96 /**
97 * Render Welcome Panel
98 *
99 * @return void
100 */
101 public function render_welcome_panel() {
102 $latest_wordpress_version = get_bloginfo( 'version' );
103 ?>
104 <div class="welcome-panel-content adminify-panel-content">
105 <?php
106 if ( $latest_wordpress_version >= '6.2' ) {
107 ?>
108 <div class="welcome-panel-header">
109 <?php
110 $this->render_welcome_template();
111 ?>
112 </div>
113 <style>
114 .wp-adminify .welcome-panel{
115 background-color: #fff !important;
116 }
117 .wp-adminify #wpbody-content .adminify-panel-content{
118 margin: auto auto;
119 padding: 50px 100px;
120 }
121 .wp-adminify #wpbody-content .welcome-panel-header{
122 padding: 30px !important;
123 max-width: inherit !important;
124 }
125 </style>
126 <?php
127 } else {
128 ?>
129
130 <?php
131 if ( !current_user_can( 'edit_theme_options' ) ) {
132 ?>
133 <a class="welcome-panel-close" href="<?php
134 echo esc_url( admin_url( 'welcome=0' ) );
135 ?>"><?php
136 esc_html_e( 'Dismiss' );
137 ?></a>
138 <?php
139 }
140 $this->render_welcome_template();
141 }
142 ?>
143 </div>
144
145 <?php
146 if ( !current_user_can( 'edit_theme_options' ) ) {
147 ?>
148 <script type="text/javascript">
149 ;
150 (function($) {
151 $(document).ready(function() {
152 $('<div id="adminify-welcome-panel" class="adminify-welcome-panel"></div>').insertBefore('#dashboard-widgets-wrap').append($('.adminify-panel-content'));
153 });
154 })(jQuery);
155 </script>
156 <?php
157 }
158 }
159
160 public function render_welcome_template() {
161 $option = ( isset( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '' );
162 if ( isset( $option['widget_template_type'] ) && !empty( $option['widget_template_type'] ) ) {
163 $from_multisite = false;
164 $ms_helper = new Multisite_Helper();
165 $switch_blog = ( $from_multisite && $ms_helper->needs_to_switch_blog() ? true : false );
166 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
167 $elementor = \Elementor\Plugin::$instance;
168 }
169 echo '<style>';
170 $css = '';
171 // $css .= '.welcome-panel-content{max-width:95%;}';
172 $css .= str_replace( [
173 "\r\n",
174 "\n",
175 "\r\t",
176 "\t",
177 "\r"
178 ], '', $css );
179 $css .= preg_replace( '/\\s+/', ' ', $css );
180 echo Utils::wp_kses_custom( $css );
181 echo '</style>';
182 if ( $switch_blog ) {
183 global $blueprint;
184 switch_to_blog( $blueprint );
185 }
186 switch ( $option['widget_template_type'] ) {
187 case 'specific_page':
188 // $page_id = $option['custom_page'];
189 // if ( $page_id ) {
190 // $page = get_page( $page_id );
191 // $content = apply_filters( 'the_content', $page->post_content );
192 // $content = str_replace( ']]>', ']]&gt;', $content );
193 // echo wp_specialchars_decode( Utils::wp_kses_custom( $content ) );
194 // }
195 $panel_height = ( !empty( $option['panel_height'] ) ? $option['panel_height'] : 600 );
196 $link = get_permalink( $option['custom_page'] );
197 $link = add_query_arg( 'bknd', 1, $link );
198 printf( '<iframe class="wp-adminify--admin-page" src="%s"></iframe>', esc_url( $link ) );
199 echo '<style>
200 .wp-adminify .welcome-panel-header{
201 height: ' . $panel_height . 'px;
202 overflow: hidden;
203 }
204 .wp-adminify #wpbody{
205 overflow:hidden;
206 }
207 .wp-adminify #wpbody-content {
208 position: relative;
209 overflow: hidden;
210 }
211 iframe.wp-adminify--admin-page {
212 width: 100%;
213 height: 100%;
214 position: relative;
215 }
216 #wpcontent {
217 padding-left: 0;
218 }
219 .wrap {
220 margin: 0;
221 }
222 </style>';
223 break;
224 case 'elementor_template':
225 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
226 $template_id = $option['elementor_template_id'];
227 if ( $template_id ) {
228 $elementor->frontend->register_styles();
229 $elementor->frontend->enqueue_styles();
230 echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) );
231 $elementor->frontend->register_scripts();
232 $elementor->frontend->enqueue_scripts();
233 }
234 }
235 break;
236 case 'elementor_section':
237 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
238 $template_id = $option['elementor_section_id'];
239 if ( $template_id ) {
240 $elementor->frontend->register_styles();
241 $elementor->frontend->enqueue_styles();
242 echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) );
243 $elementor->frontend->register_scripts();
244 $elementor->frontend->enqueue_scripts();
245 }
246 }
247 break;
248 case 'elementor_widget':
249 if ( is_plugin_active( 'elementor/elementor.php' ) ) {
250 $template_id = $option['elementor_widget_id'];
251 if ( $template_id ) {
252 $elementor->frontend->register_styles();
253 $elementor->frontend->enqueue_styles();
254 echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) );
255 $elementor->frontend->register_scripts();
256 $elementor->frontend->enqueue_scripts();
257 }
258 }
259 break;
260 case 'oxygen_template':
261 if ( is_plugin_active( 'oxygen/functions.php' ) ) {
262 $template_id = $option['oxygen_template_id'];
263 if ( $template_id ) {
264 echo do_shortcode( get_post_meta( $template_id, 'ct_builder_shortcodes', true ) );
265 }
266 }
267 break;
268 }
269 if ( $switch_blog ) {
270 restore_current_blog();
271 }
272 }
273 }
274
275 // Add Custom Dashboard Widgets
276 public function create_dashboard_widgets() {
277 $options = $this->options;
278 $options = ( !empty( $this->options['dashboard_widget_types']['dashboard_widgets'] ) ? $this->options['dashboard_widget_types']['dashboard_widgets'] : '' );
279 if ( empty( $options ) ) {
280 return;
281 }
282 $before_content = '';
283 $after_content = '';
284 $dash_widget_data = [];
285 foreach ( $options as $value ) {
286 if ( is_array( $value ) && !empty( $value ) ) {
287 // Restricted for User Roles
288 $restricted_for_dash_widget = ( !empty( $value['user_roles'] ) ? $value['user_roles'] : '' );
289 if ( !Utils::restricted_for( $restricted_for_dash_widget ) ) {
290 return;
291 }
292 $dash_widget_title = ( isset( $value['title'] ) ? $value['title'] : '' );
293 $dash_widget_position = ( isset( $value['widget_pos'] ) ? $value['widget_pos'] : 'normal' );
294 add_meta_box(
295 'adminify_widget_' . Utils::jltwp_adminify_class_cleanup( $dash_widget_title ),
296 $dash_widget_title,
297 [$this, 'render_dashboard_widget'],
298 'dashboard',
299 $dash_widget_position,
300 'high',
301 $value
302 );
303 }
304 }
305 }
306
307 // Render Dashboard Widget
308 public function render_dashboard_widget( $content = '', $value = '' ) {
309 switch ( $value['args']['widget_type'] ) {
310 case 'editor':
311 echo wp_kses_post( $value['args']['dashw_type_editor'] );
312 break;
313 case 'icon':
314 break;
315 case 'video':
316 break;
317 case 'shortcode':
318 break;
319 case 'rss_feed':
320 break;
321 case 'script':
322 break;
323 }
324 }
325
326 /**
327 * Scripst / Styles
328 */
329 public function jltwp_adminify_enqueue_scripts() {
330 global $pagenow;
331 // Load Scripts/Styles only WP Adminify Dashboard Widget
332 if ( 'admin.php' === $pagenow && 'adminify-dashboard-widgets' === $_GET['page'] ) {
333 $this->dashboard_widgets_admin_script();
334 }
335 }
336
337 // WP Adminify Dashboard Widgets Style
338 public function dashboard_widgets_admin_script() {
339 echo '<style>.wp-adminify-dashboard-widgets .adminify-container{ max-width:60%; margin:0 auto;} .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;}
340 /*
341 .wp-adminify #wpbody-content .adminify-section[data-section-id] .adminify-data-wrapper .adminify-cloneable-item .adminify-cloneable-title{ border:none !important; }
342 */
343 /* If needed for white top-bar */
344 .adminify-dashboard-widgets .adminify-header-inner {
345 background-color: #fafafa !important;
346 border-bottom: 1px solid #f5f5f5;
347 }
348 </style>';
349 }
350
351 }
352