*/ class DashboardWidget extends DashboardWidgetModel { public $url; public $roles; public $options; public $current_role; public function __construct() { $this->options = ( new DashboardWidget_Setttings() )->get(); if ( is_admin() ) { add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'wp_dashboard_setup', [ $this, 'create_dashboard_widgets' ], 999 ); add_action( 'wp_network_dashboard_setup', [ $this, 'create_dashboard_widgets' ], 999 ); if ( shortcode_exists( 'elementor-template' ) ) { add_action( 'wp_loaded', [ $this, 'override_elementor_shortcodes' ] ); } // Welcome Panel Initialize if( ! get_user_meta( get_current_user_id(), 'pxlbsadminify_dismissed_welcome_panel', true )){ add_action( 'admin_init', [ $this, 'welcome_init' ] ); } add_action('admin_init', function() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. if ( isset( $_GET['welcome'] ) && '0' === sanitize_text_field( wp_unslash( $_GET['welcome'] ) ) ) { update_user_meta(get_current_user_id(), 'pxlbsadminify_dismissed_welcome_panel', true); } }); } } /** * Override elementor-template shortcode */ public function override_elementor_shortcodes() { add_shortcode( 'elementor-template', [ $this, 'override_elementor_template' ] ); } public function override_elementor_template( $atts ) { extract( shortcode_atts( [ 'id' => '', ], $atts ) ); $elementor = \Elementor\Plugin::$instance; $output = ''; $output .= $elementor->frontend->register_styles(); $output .= $elementor->frontend->enqueue_styles(); $output .= $elementor->frontend->get_builder_content( $id, true ); $output .= $elementor->frontend->register_scripts(); $output .= $elementor->frontend->enqueue_scripts(); return $output; } /** * Welcome Panel Initialize */ public function welcome_init() { if ( empty( $this->options['dashboard_widget_types'] ) ) { return; } $option = ! empty( $this->options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : ''; if ( ! empty( $option['enable_custom_welcome_dash_widget'] ) ) { // Restricted for User Roles // $restricted_for_dash_widget = ! empty( $option['user_roles'] ) ? $option['user_roles'] : ''; // if ( !Utils::restricted_for( $restricted_for_dash_widget ) ) { // return; // } $this->render_welcome_panel_output(); } } /** * Render Welcome Panel Content * * @return void */ public function render_welcome_panel_output() { remove_action( 'welcome_panel', 'wp_welcome_panel' ); add_action( 'welcome_panel', [ $this, 'render_welcome_panel' ] ); // custom fallback for the users who don't have // enough capabilities to display welcome panel. if ( ! current_user_can( 'edit_theme_options' ) ) { add_action( 'admin_notices', [ $this, 'render_welcome_panel' ] ); } } /** * Render Welcome Panel * * @return void */ public function render_welcome_panel() { $latest_wordpress_version = get_bloginfo( 'version' ); ?>
options['dashboard_widget_types']['welcome_dash_widget'] ) ? $this->options['dashboard_widget_types']['welcome_dash_widget'] : ''; if ( isset( $option['widget_template_type'] ) && ! empty( $option['widget_template_type'] ) ) { $from_multisite = false; $ms_helper = new Multisite_Helper(); $switch_blog = $from_multisite && $ms_helper->needs_to_switch_blog() ? true : false; if ( is_plugin_active( 'elementor/elementor.php' ) ) { $elementor = \Elementor\Plugin::$instance; } $css = ''; // Initialize the CSS variable $css = apply_filters('pxlbsadminify_dashboard_widgets/welcome_css', $css); // Apply the filter echo ''; // echo ''; if ( $switch_blog ) { global $pxlbsadminify_blueprint; switch_to_blog( $pxlbsadminify_blueprint ); } switch ( $option['widget_template_type'] ) { case 'specific_page': // $page_id = $option['custom_page']; // if ( $page_id ) { // $page = get_page( $page_id ); // $content = apply_filters( 'the_content', $page->post_content ); // $content = str_replace( ']]>', ']]>', $content ); // echo wp_specialchars_decode( Utils::kses_custom( $content ) ); // } $panel_height = !empty( $option['panel_height'] ) ? $option['panel_height'] : 600; $link = get_permalink($option['custom_page']); $link = add_query_arg('bknd', 1, $link); printf('', esc_url( $link ) ); echo ''; break; case 'elementor_template': if ( is_plugin_active( 'elementor/elementor.php' ) ) { $template_id = $option['elementor_template_id']; if ( $template_id ) { $elementor->frontend->register_styles(); $elementor->frontend->enqueue_styles(); echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped. $elementor->frontend->register_scripts(); $elementor->frontend->enqueue_scripts(); } } break; case 'elementor_section': if ( is_plugin_active( 'elementor/elementor.php' ) ) { $template_id = $option['elementor_section_id']; if ( $template_id ) { $elementor->frontend->register_styles(); $elementor->frontend->enqueue_styles(); echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped. $elementor->frontend->register_scripts(); $elementor->frontend->enqueue_scripts(); } } break; case 'elementor_widget': if ( is_plugin_active( 'elementor/elementor.php' ) ) { $template_id = $option['elementor_widget_id']; if ( $template_id ) { $elementor->frontend->register_styles(); $elementor->frontend->enqueue_styles(); echo Utils::kses_custom( $elementor->frontend->get_builder_content( $template_id, true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_custom() is a wp_kses() wrapper; output already escaped. $elementor->frontend->register_scripts(); $elementor->frontend->enqueue_scripts(); } } break; case 'oxygen_template': if ( is_plugin_active( 'oxygen/functions.php' ) ) { $template_id = $option['oxygen_template_id']; if ( $template_id ) { echo do_shortcode( get_post_meta( $template_id, 'ct_builder_shortcodes', true ) ); } } break; } if ( $switch_blog ) { restore_current_blog(); } } } // Add Custom Dashboard Widgets public function create_dashboard_widgets() { $options = $this->options; $options = ! empty( $this->options['dashboard_widget_types']['dashboard_widgets'] ) ? $this->options['dashboard_widget_types']['dashboard_widgets'] : ''; if ( empty( $options ) ) { return; } $before_content = ''; $after_content = ''; $dash_widget_data = []; foreach ( $options as $value ) { if ( is_array( $value ) && ! empty( $value ) ) { // Restricted for User Roles $restricted_for_dash_widget = ! empty( $value['user_roles'] ) ? $value['user_roles'] : ''; if ( ! Utils::restricted_for( $restricted_for_dash_widget ) ) { return; } $dash_widget_title = isset( $value['title'] ) ? $value['title'] : ''; $dash_widget_position = isset( $value['widget_pos'] ) ? $value['widget_pos'] : 'normal'; add_meta_box( 'adminify_widget_' . Utils::class_cleanup( $dash_widget_title ), $dash_widget_title, [ $this, 'render_dashboard_widget' ], 'dashboard', $dash_widget_position, 'high', $value ); } } } // Render Dashboard Widget public function render_dashboard_widget( $content = '', $value = '' ) { switch ( $value['args']['widget_type'] ) { case 'editor': echo wp_kses_post( $value['args']['dashw_type_editor'] ); break; case 'icon': do_action('pxlbsadminify_dashboard_widgets/render_icon', $value); break; case 'video': do_action('pxlbsadminify_dashboard_widgets/render_video', $value); break; case 'shortcode': do_action('pxlbsadminify_dashboard_widgets/render_shortcode', $value); break; case 'rss_feed': do_action('pxlbsadminify_dashboard_widgets/render_rss_feed', $value); break; case 'script': do_action('pxlbsadminify_dashboard_widgets/render_script', $value); break; } } /** * Scripst / Styles */ public function enqueue_scripts() { global $pagenow; // Load Scripts/Styles only WP Adminify Dashboard Widget // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; if ( ( 'admin.php' === $pagenow ) && ( 'adminify-dashboard-widgets' === $current_page ) ) { $this->dashboard_widgets_admin_script(); } } // WP Adminify Dashboard Widgets Style public function dashboard_widgets_admin_script() { echo ''; } }