Any plugin can register its own dashboard widget when WordPress is putting together content for this administrative landing page. After registering a function to be called during the dashboard setup phase, our recipe makes a call to the wp_add_dashboard_widget function to add our own element to the website when the callback is executed. The wp_add_dashboard_widget function requires three parameters that need to provide a unique identifier for the new item, a title to be displayed at the top of the widget, and a function that will be responsible for generating the widget's contents. The wp_add_dashboard_widget function also has an optional fourth parameter that can be used when the widget needs to process form data as part of the dashboard widget contents.
As can be seen in the previous screenshot, dashboard widgets are displayed using WordPress meta boxes, where any HTML code echoed by the content display function directly appears in the box.
While the display function is mostly composed of HTML code, we also make a call to the wp_count_posts utility function, which easily returns the number of posts for a given post type.
The new widget can be hidden and moved to a new location on the Dashboard, like any other built-in widget. Just like the front-facing widget plugin created earlier in this chapter, it should be noted that all the code in this plugin is in a separate file to the original book review plugin, to organize its code separately from the original plugin file created in Chapter 4, The Power of Custom Post Types.