| 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 |
{ |
| 21 |
public $url ; |
| 22 |
public $roles ; |
| 23 |
public $options ; |
| 24 |
public $current_role ; |
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
$this->options = ( new DashboardWidget_Setttings() )->get(); |
| 28 |
$this->url = WP_ADMINIFY_URL . 'Inc/Modules/DashboardWidget'; |
| 29 |
|
| 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_loaded', [ $this, 'override_elementor_shortcodes' ] ); |
| 34 |
// Welcome Panel Initialize |
| 35 |
add_action( 'admin_init', [ $this, 'jltwp_adminify_welcome_init' ] ); |
| 36 |
} |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Override elementor-template shortcode |
| 42 |
*/ |
| 43 |
public function override_elementor_shortcodes() |
| 44 |
{ |
| 45 |
if ( is_admin() && shortcode_exists( 'elementor-template' ) ) { |
| 46 |
add_shortcode( 'elementor-template', [ $this, 'override_elementor_template' ] ); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
public function override_elementor_template( $atts ) |
| 51 |
{ |
| 52 |
extract( shortcode_atts( [ |
| 53 |
'id' => '', |
| 54 |
], $atts ) ); |
| 55 |
$elementor = \Elementor\Plugin::$instance; |
| 56 |
$output = ''; |
| 57 |
$output .= $elementor->frontend->register_styles(); |
| 58 |
$output .= $elementor->frontend->enqueue_styles(); |
| 59 |
$output .= $elementor->frontend->get_builder_content( $id, true ); |
| 60 |
$output .= $elementor->frontend->register_scripts(); |
| 61 |
$output .= $elementor->frontend->enqueue_scripts(); |
| 62 |
return $output; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Welcome Panel Initialize |
| 67 |
*/ |
| 68 |
public function jltwp_adminify_welcome_init() |
| 69 |
{ |
| 70 |
if ( empty($this->options['dashboard_widget_types']) ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
$option = ( !empty($this->options['dashboard_widget_types']['welcome_dash_widget']) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '' ); |
| 74 |
if ( !empty($option['enable_custom_welcome_dash_widget']) ) { |
| 75 |
|
| 76 |
if ( !empty($option['widget_template_type']) ) { |
| 77 |
// Restricted for User Roles |
| 78 |
$restricted_for_dash_widget = ( !empty($option['user_roles']) ? $option['user_roles'] : '' ); |
| 79 |
if ( !Utils::restricted_for( $restricted_for_dash_widget ) ) { |
| 80 |
return; |
| 81 |
} |
| 82 |
$this->render_welcome_panel_output(); |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Render Welcome Panel Content |
| 90 |
* |
| 91 |
* @return void |
| 92 |
*/ |
| 93 |
public function render_welcome_panel_output() |
| 94 |
{ |
| 95 |
remove_action( 'welcome_panel', 'wp_welcome_panel' ); |
| 96 |
add_action( 'welcome_panel', [ $this, 'render_welcome_panel' ] ); |
| 97 |
// custom fallback for the users who don't have |
| 98 |
// enough capabilities to display welcome panel. |
| 99 |
if ( !current_user_can( 'edit_theme_options' ) ) { |
| 100 |
add_action( 'admin_notices', [ $this, 'render_welcome_panel' ] ); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Render Welcome Panel |
| 106 |
* |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
public function render_welcome_panel() |
| 110 |
{ |
| 111 |
$latest_wordpress_version = get_bloginfo( 'version' ); |
| 112 |
?> |
| 113 |
<div class="welcome-panel-content adminify-panel-content"> |
| 114 |
<?php |
| 115 |
|
| 116 |
if ( $latest_wordpress_version >= '6.2' ) { |
| 117 |
?> |
| 118 |
<div class="welcome-panel-header"> |
| 119 |
<div class="welcome-panel-header-image"> |
| 120 |
<svg preserveAspectRatio="xMidYMin slice" viewBox="0 0 1232 240" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"> |
| 121 |
<g clip-path="url(#a)"> |
| 122 |
<path class="curve" d="M1430.91 497.569c63.48-63.482 112.65-137.548 146.13-220.1 32.34-79.71 48.73-163.936 48.73-250.299 0-86.362-16.39-170.588-48.73-250.298-33.48-82.573-82.65-156.618-146.13-220.1-63.48-63.482-137.55-112.651-220.1-146.135-79.71-32.336-163.94-48.725-250.301-48.725-86.363 0-170.589 16.389-250.299 48.725-82.573 33.484-156.618 82.653-220.1 146.135-63.481 63.482-112.65 137.547-146.135 220.1C311.64-143.418 295.25-59.192 295.25 27.19c0 86.383 16.39 170.589 48.725 250.299 33.485 82.573 82.654 156.618 146.135 220.1a683.438 683.438 0 0 0 14.475 14.031l85.576-85.577a560.502 560.502 0 0 1-14.535-13.99C472.814 309.24 416.206 172.56 416.206 27.17c0-145.389 56.608-282.069 159.42-384.882 102.813-102.813 239.494-159.42 384.883-159.42 145.391 0 282.071 56.607 384.881 159.42 102.81 102.813 159.42 239.493 159.42 384.882 0 145.39-56.61 282.07-159.42 384.883L861.587 895.857H747.545l540.815-540.815c87.57-87.572 135.81-204.013 135.81-327.851 0-123.84-48.22-240.28-135.81-327.852-87.57-87.572-204.01-135.814-327.851-135.814-123.839 0-240.28 48.222-327.852 135.814C545.085-213.069 496.844-96.648 496.844 27.19c0 123.839 48.221 240.28 135.813 327.852 4.758 4.758 9.636 9.374 14.575 13.93l85.637-85.637c-5.019-4.475-9.938-9.072-14.696-13.829-133.616-133.616-133.616-351.035 0-484.671 133.616-133.616 351.037-133.616 484.667 0 64.74 64.731 100.38 150.792 100.38 242.335 0 91.544-35.64 177.604-100.38 242.336L576.493 895.857H462.452l683.378-683.362c102.19-102.188 102.19-268.442 0-370.629-49.49-49.492-115.31-76.767-185.301-76.767-69.993 0-135.814 27.255-185.305 76.767-49.491 49.491-76.767 115.311-76.767 185.304 0 69.994 27.256 135.814 76.767 185.305a262.783 262.783 0 0 0 14.797 13.708l86.02-86.02a143.305 143.305 0 0 1-15.281-13.224c-26.65-26.651-41.326-62.09-41.326-99.789 0-37.698 14.676-73.138 41.326-99.789 26.651-26.65 62.091-41.326 99.789-41.326s73.141 14.676 99.791 41.326c55.01 55.015 55.01 144.543 0 199.578L295.29 891.986v124.804h1330.52V895.837h-593.13l398.27-398.268h-.04ZM-1234.11-301.729c-82.74 82.734-146.8 179.217-190.43 286.787-42.11 103.881-63.46 213.608-63.46 326.178s21.35 222.297 63.48 326.158c43.63 107.571 107.69 204.053 190.43 286.787 82.73 82.739 179.21 146.799 286.784 190.429 103.861 42.11 213.608 63.48 326.158 63.48 112.55 0 222.297-21.35 326.158-63.48 107.57-43.63 204.053-107.69 286.787-190.429 82.734-82.734 146.8-179.216 190.425-286.787 42.113-103.861 63.482-213.608 63.482-326.158 0-112.549-21.349-222.297-63.482-326.158C138.597-122.492 74.531-218.975-8.203-301.709c-53.382-53.382-112.711-99.063-177.08-136.519l-88.963 88.963c66.284 34.815 126.883 79.448 180.527 133.092C47.155-75.299 124.748 112.021 124.748 311.256c0 199.235-77.593 386.556-218.467 527.43-140.873 140.873-328.194 218.464-527.429 218.464-199.235 0-386.552-77.591-527.432-218.464-140.87-140.874-218.46-328.195-218.46-527.43 0-199.235 77.59-386.555 218.46-527.429L-484.77-880h-171.052l-578.288 578.271Z" fill="#213FD4"></path> |
| 123 |
<path class="curve" d="M85.415-880H-85.637L-949.02-16.635c-87.569 87.572-135.809 204.012-135.809 327.851s48.22 240.28 135.809 327.852c87.572 87.572 204.012 135.813 327.851 135.813s240.3-48.241 327.852-135.813c87.572-87.572 135.813-204.013 135.813-327.852 0-123.839-48.221-240.28-135.813-327.872-55.701-55.68-123.073-95.434-196.574-117.025L-593.209-30.364c81 6.491 156.275 41.145 214.375 99.245 64.731 64.731 100.373 150.792 100.373 242.335 0 91.544-35.642 177.604-100.373 242.336-64.732 64.731-150.792 100.373-242.336 100.373-91.544 0-177.604-35.642-242.335-100.373-64.732-64.732-100.374-150.792-100.374-242.336 0-91.543 35.642-177.604 100.374-242.335L85.415-880Z" fill="#213FD4"></path> |
| 124 |
<path class="dot" d="M961 40c16.569 0 30-13.431 30-30 0-16.569-13.431-30-30-30-16.569 0-30 13.431-30 30 0 16.569 13.431 30 30 30Z" fill="#33F078"></path> |
| 125 |
</g> |
| 126 |
<defs> |
| 127 |
<clipPath id="a"> |
| 128 |
<path fill="#fff" d="M0 0h1232v240H0z"></path> |
| 129 |
</clipPath> |
| 130 |
</defs> |
| 131 |
</svg> |
| 132 |
</div> |
| 133 |
<?php |
| 134 |
$this->render_welcome_template(); |
| 135 |
?> |
| 136 |
</div> |
| 137 |
<?php |
| 138 |
} else { |
| 139 |
?> |
| 140 |
|
| 141 |
<?php |
| 142 |
|
| 143 |
if ( !current_user_can( 'edit_theme_options' ) ) { |
| 144 |
?> |
| 145 |
<a class="welcome-panel-close" href="<?php |
| 146 |
echo esc_url( admin_url( 'welcome=0' ) ) ; |
| 147 |
?>"><?php |
| 148 |
esc_html_e( 'Dismiss' ); |
| 149 |
?></a> |
| 150 |
<?php |
| 151 |
} |
| 152 |
|
| 153 |
?> |
| 154 |
|
| 155 |
<?php |
| 156 |
$this->render_welcome_template(); |
| 157 |
?> |
| 158 |
<?php |
| 159 |
} |
| 160 |
|
| 161 |
?> |
| 162 |
</div> |
| 163 |
|
| 164 |
<?php |
| 165 |
if ( !current_user_can( 'edit_theme_options' ) ) { |
| 166 |
?> |
| 167 |
<script type="text/javascript"> |
| 168 |
; |
| 169 |
(function($) { |
| 170 |
$(document).ready(function() { |
| 171 |
$('<div id="adminify-welcome-panel" class="adminify-welcome-panel"></div>').insertBefore('#dashboard-widgets-wrap').append($('.adminify-panel-content')); |
| 172 |
}); |
| 173 |
})(jQuery); |
| 174 |
</script> |
| 175 |
<?php |
| 176 |
} |
| 177 |
?> |
| 178 |
<?php |
| 179 |
} |
| 180 |
|
| 181 |
public function render_welcome_template() |
| 182 |
{ |
| 183 |
$option = ( isset( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : '' ); |
| 184 |
|
| 185 |
if ( isset( $option['widget_template_type'] ) && !empty($option['widget_template_type']) ) { |
| 186 |
$from_multisite = false; |
| 187 |
$ms_helper = new Multisite_Helper(); |
| 188 |
$switch_blog = ( $from_multisite && $ms_helper->needs_to_switch_blog() ? true : false ); |
| 189 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 190 |
$elementor = \Elementor\Plugin::$instance; |
| 191 |
} |
| 192 |
echo '<style>' ; |
| 193 |
$css = ''; |
| 194 |
// $css .= '.welcome-panel-content{max-width:95%;}'; |
| 195 |
$css = str_replace( [ |
| 196 |
"\r\n", |
| 197 |
"\n", |
| 198 |
"\r\t", |
| 199 |
"\t", |
| 200 |
"\r" |
| 201 |
], '', $css ); |
| 202 |
$css = preg_replace( '/\\s+/', ' ', $css ); |
| 203 |
echo Utils::wp_kses_custom( $css ) ; |
| 204 |
echo '</style>' ; |
| 205 |
|
| 206 |
if ( $switch_blog ) { |
| 207 |
global $blueprint ; |
| 208 |
switch_to_blog( $blueprint ); |
| 209 |
} |
| 210 |
|
| 211 |
switch ( $option['widget_template_type'] ) { |
| 212 |
case 'specific_page': |
| 213 |
$page_id = $option['custom_page']; |
| 214 |
|
| 215 |
if ( $page_id ) { |
| 216 |
$page = get_page( $page_id ); |
| 217 |
$content = apply_filters( 'the_content', $page->post_content ); |
| 218 |
$content = str_replace( ']]>', ']]>', $content ); |
| 219 |
echo wp_kses_post( $content ) ; |
| 220 |
} |
| 221 |
|
| 222 |
break; |
| 223 |
case 'elementor_template': |
| 224 |
|
| 225 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 226 |
$template_id = $option['elementor_template_id']; |
| 227 |
|
| 228 |
if ( $template_id ) { |
| 229 |
$elementor->frontend->register_styles(); |
| 230 |
$elementor->frontend->enqueue_styles(); |
| 231 |
echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ) ; |
| 232 |
$elementor->frontend->register_scripts(); |
| 233 |
$elementor->frontend->enqueue_scripts(); |
| 234 |
} |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
break; |
| 239 |
case 'elementor_section': |
| 240 |
|
| 241 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 242 |
$template_id = $option['elementor_section_id']; |
| 243 |
|
| 244 |
if ( $template_id ) { |
| 245 |
$elementor->frontend->register_styles(); |
| 246 |
$elementor->frontend->enqueue_styles(); |
| 247 |
echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ) ; |
| 248 |
$elementor->frontend->register_scripts(); |
| 249 |
$elementor->frontend->enqueue_scripts(); |
| 250 |
} |
| 251 |
|
| 252 |
} |
| 253 |
|
| 254 |
break; |
| 255 |
case 'elementor_widget': |
| 256 |
|
| 257 |
if ( is_plugin_active( 'elementor/elementor.php' ) ) { |
| 258 |
$template_id = $option['elementor_widget_id']; |
| 259 |
|
| 260 |
if ( $template_id ) { |
| 261 |
$elementor->frontend->register_styles(); |
| 262 |
$elementor->frontend->enqueue_styles(); |
| 263 |
echo Utils::wp_kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ) ; |
| 264 |
$elementor->frontend->register_scripts(); |
| 265 |
$elementor->frontend->enqueue_scripts(); |
| 266 |
} |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
break; |
| 271 |
case 'oxygen_template': |
| 272 |
|
| 273 |
if ( is_plugin_active( 'oxygen/functions.php' ) ) { |
| 274 |
$template_id = $option['oxygen_template_id']; |
| 275 |
if ( $template_id ) { |
| 276 |
echo do_shortcode( get_post_meta( $template_id, 'ct_builder_shortcodes', true ) ) ; |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
break; |
| 281 |
} |
| 282 |
if ( $switch_blog ) { |
| 283 |
restore_current_blog(); |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
} |
| 288 |
|
| 289 |
// Add Custom Dashboard Widgets |
| 290 |
public function create_dashboard_widgets() |
| 291 |
{ |
| 292 |
$options = $this->options; |
| 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 |
$before_content = ''; |
| 298 |
$after_content = ''; |
| 299 |
$dash_widget_data = []; |
| 300 |
foreach ( $options as $value ) { |
| 301 |
|
| 302 |
if ( is_array( $value ) && !empty($value) ) { |
| 303 |
// Restricted for User Roles |
| 304 |
$restricted_for_dash_widget = ( !empty($value['user_roles']) ? $value['user_roles'] : '' ); |
| 305 |
if ( !Utils::restricted_for( $restricted_for_dash_widget ) ) { |
| 306 |
return; |
| 307 |
} |
| 308 |
$dash_widget_title = ( isset( $value['title'] ) ? $value['title'] : '' ); |
| 309 |
$dash_widget_position = ( isset( $value['widget_pos'] ) ? $value['widget_pos'] : 'normal' ); |
| 310 |
add_meta_box( |
| 311 |
'adminify_widget_' . Utils::jltwp_adminify_class_cleanup( $dash_widget_title ), |
| 312 |
$dash_widget_title, |
| 313 |
[ $this, 'render_dashboard_widget' ], |
| 314 |
'dashboard', |
| 315 |
$dash_widget_position, |
| 316 |
'high', |
| 317 |
$value |
| 318 |
); |
| 319 |
} |
| 320 |
|
| 321 |
} |
| 322 |
} |
| 323 |
|
| 324 |
// Render Dashboard Widget |
| 325 |
public function render_dashboard_widget( $content = '', $value = '' ) |
| 326 |
{ |
| 327 |
switch ( $value['args']['widget_type'] ) { |
| 328 |
case 'editor': |
| 329 |
echo wp_kses_post( $value['args']['dashw_type_editor'] ) ; |
| 330 |
break; |
| 331 |
case 'icon': |
| 332 |
break; |
| 333 |
case 'video': |
| 334 |
break; |
| 335 |
case 'shortcode': |
| 336 |
break; |
| 337 |
case 'rss_feed': |
| 338 |
break; |
| 339 |
case 'script': |
| 340 |
break; |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/** |
| 345 |
* Scripst / Styles |
| 346 |
*/ |
| 347 |
public function jltwp_adminify_enqueue_scripts() |
| 348 |
{ |
| 349 |
global $pagenow ; |
| 350 |
// Load Scripts/Styles only WP Adminify Dashboard Widget |
| 351 |
if ( 'admin.php' === $pagenow && 'adminify-dashboard-widgets' === $_GET['page'] ) { |
| 352 |
$this->dashboard_widgets_admin_script(); |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
// WP Adminify Dashboard Widgets Style |
| 357 |
public function dashboard_widgets_admin_script() |
| 358 |
{ |
| 359 |
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;} |
| 360 |
/* |
| 361 |
.wp-adminify #wpbody-content .adminify-section[data-section-id] .adminify-data-wrapper .adminify-cloneable-item .adminify-cloneable-title{ border:none !important; } |
| 362 |
*/ |
| 363 |
/* If needed for white top-bar */ |
| 364 |
.adminify-dashboard-widgets .adminify-header-inner { |
| 365 |
background-color: #fafafa !important; |
| 366 |
border-bottom: 1px solid #f5f5f5; |
| 367 |
} |
| 368 |
</style>' ; |
| 369 |
} |
| 370 |
|
| 371 |
} |