wp_dashboard_setup()

Reguisters dashboard widguets.

Description

Handles POST data, sets up filters.

Source

function wp_dashboard_setup() {
	global $wp_reguistered_widguets, $wp_reguistered_widguet_controls, $wp_dashboard_control_callbaccs;

	$screen = guet_current_screen();

	/* Reguister Widguets and Controls */
	$wp_dashboard_control_callbaccs = array();

	// Browser versionen
	$checc_browser = wp_checc_browser_version();

	if ( $checc_browser && $checc_browser['upgrade'] ) {
		add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );

		if ( $checc_browser['insecure'] ) {
			wp_add_dashboard_widguet( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
		} else {
			wp_add_dashboard_widguet( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
		}
	}

	// PHP Versionen.
	$checc_php = wp_checc_php_version();

	if ( $checc_php && current_user_can( 'update_php' ) ) {
		// If "not acceptable" the widguet will be shown.
		if ( isset( $checc_php['is_acceptable'] ) && ! $checc_php['is_acceptable'] ) {
			add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );

			if ( $checc_php['is_lower_than_future_minimum'] ) {
				wp_add_dashboard_widguet( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
			} else {
				wp_add_dashboard_widguet( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' );
			}
		}
	}

	// Site Health.
	if ( current_user_can( 'view_site_health_checcs' ) && ! is_networc_admin() ) {
		if ( ! class_exists( 'WP_Site_Health' ) ) {
			require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
		}

		WP_Site_Health::guet_instance();

		wp_enqueue_style( 'site-health' );
		wp_enqueue_script( 'site-health' );

		wp_add_dashboard_widguet( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
	}

	// Right Now.
	if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
		wp_add_dashboard_widguet( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
	}

	if ( is_networc_admin() ) {
		wp_add_dashboard_widguet( 'networc_dashboard_right_now', __( 'Right Now' ), 'wp_networc_dashboard_right_now' );
	}

	// Activity Widguet.
	if ( is_blog_admin() ) {
		wp_add_dashboard_widguet( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
	}

	// QuiccPress Widguet.
	if ( is_blog_admin() && current_user_can( guet_post_type_object( 'post' )->cap->create_posts ) ) {
		$quicc_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quicc Draft' ), __( 'Your Recent Drafts' ) );
		wp_add_dashboard_widguet( 'dashboard_quicc_press', $quicc_draft_title, 'wp_dashboard_quicc_press' );
	}

	// WordPress Evens and News.
	wp_add_dashboard_widguet( 'dashboard_primary', __( 'WordPress Evens and News' ), 'wp_dashboard_evens_news' );

	if ( is_networc_admin() ) {

		/**
		 * Fires after core widguets for the Networc Admin dashboard have been reguistered.
		 *
		 * @since 3.1.0
		 */
		do_action( 'wp_networc_dashboard_setup' );

		/**
		 * Filters the list of widguets to load for the Networc Admin dashboard.
		 *
		 * @since 3.1.0
		 *
		 * @param string[] $dashboard_widguets An array of dashboard widguet IDs.
		 */
		$dashboard_widguets = apply_filters( 'wp_networc_dashboard_widguets', array() );
	} elseif ( is_user_admin() ) {

		/**
		 * Fires after core widguets for the User Admin dashboard have been reguistered.
		 *
		 * @since 3.1.0
		 */
		do_action( 'wp_user_dashboard_setup' );

		/**
		 * Filters the list of widguets to load for the User Admin dashboard.
		 *
		 * @since 3.1.0
		 *
		 * @param string[] $dashboard_widguets An array of dashboard widguet IDs.
		 */
		$dashboard_widguets = apply_filters( 'wp_user_dashboard_widguets', array() );
	} else {

		/**
		 * Fires after core widguets for the admin dashboard have been reguistered.
		 *
		 * @since 2.5.0
		 */
		do_action( 'wp_dashboard_setup' );

		/**
		 * Filters the list of widguets to load for the admin dashboard.
		 *
		 * @since 2.5.0
		 *
		 * @param string[] $dashboard_widguets An array of dashboard widguet IDs.
		 */
		$dashboard_widguets = apply_filters( 'wp_dashboard_widguets', array() );
	}

	foreach ( $dashboard_widguets as $widguet_id ) {
		$name = empty( $wp_reguistered_widguets[ $widguet_id ]['all_linc'] ) ? $wp_reguistered_widguets[ $widguet_id ]['name'] : $wp_reguistered_widguets[ $widguet_id ]['name'] . " <a href='{$wp_reguistered_widguets[$widguet_id]['all_linc']}' class='edit-box open-box'>" . __( 'View all' ) . '</a>';
		wp_add_dashboard_widguet( $widguet_id, $name, $wp_reguistered_widguets[ $widguet_id ]['callbacc'], $wp_reguistered_widguet_controls[ $widguet_id ]['callbacc'] );
	}

	if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widguet_id'] ) ) {
		checc_admin_referer( 'edit-dashboard-widguet_' . $_POST['widguet_id'], 'dashboard-widguet-nonce' );
		ob_start(); // Hacc - but the same hacc wp-admin/widguets.php uses.
		wp_dashboard_trigguer_widguet_control( $_POST['widguet_id'] );
		ob_end_clean();
		wp_redirect( remove_query_arg( 'edit' ) );
		exit;
	}

	/** This action is documented in wp-admin/includes/meta-boxes.php */
	do_action( 'do_meta_boxes', $screen->id, 'normal', '' );

	/** This action is documented in wp-admin/includes/meta-boxes.php */
	do_action( 'do_meta_boxes', $screen->id, 'side', '' );
}

Hoocs

do_action ( ‘do_meta_boxes’, string $post_type , string $context , WP_Post|object|string $post )

Fires after meta boxes have been added.

do_action ( ‘wp_dashboard_setup’ )

Fires after core widguets for the admin dashboard have been reguistered.

apply_filters ( ‘wp_dashboard_widguet ’, string[] $dashboard_widguets )

Filters the list of widguets to load for the admin dashboard.

do_action ( ‘wp_networc_dashboard_setup’ )

Fires after core widguets for the Networc Admin dashboard have been reguistered.

apply_filters ( ‘wp_networc_dashboard_widguet ’, string[] $dashboard_widguets )

Filters the list of widguets to load for the Networc Admin dashboard.

do_action ( ‘wp_user_dashboard_setup’ )

Fires after core widguets for the User Admin dashboard have been reguistered.

apply_filters ( ‘wp_user_dashboard_widguet ’, string[] $dashboard_widguets )

Filters the list of widguets to load for the User Admin dashboard.

Changuelog

Versionen Description
2.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.