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

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