wp_lib_dash_page - roberts-sandbox/create-repo GitHub Wiki
###Description
This action hook allows developers to add their own Library Dashboard pages or overwrite default pages with their own. If there's a specific URL you want to define content for then use wp_lib_dash_page_$my_page, where $my_page is the name of your page.
###Context
To access the Library Dashboard users must be at the minimum a librarian and thus logged in as a WordPress user.
###Parameters
$ajax_page
The instance of WP-Librarian's Dashboard page loading class WP_LIB_AJAX_PAGE. Access to this is necessary to render the Dashboard page when finished, or call an error if one occurs.
$page_name
The name of the requested Dashboard page. In the URL example.com/wp-admin/edit.php?post_type=wp_lib_items&page=dashboard&dash_page=view-items the $page_name would be 'view-items'.
###Example
If you wanted to block access to all Dashboard pages is a user's ID was odd, you could use the following code:
add_filter('wp_lib_dash_page', 'restrict_odd_users', 10, 2);
function restrict_odd_users(WP_LIB_AJAX_PAGE $ajax_page, $page_name) {
// The ID of the current WordPress user
$user_id = get_current_user_id();
// If the user's ID is odd, replaces Dash page with custom page
if ($user_id % 2 !== 0) {
$page_content = array(
array(
'type' => 'paras',
'content' => 'Ah ah ah, you didn\'t say the magic word!'
)
);
// This appears as an HTML header at the top of the Dash page
$page_title = 'No Odd Users allowed';
// This forms part of the browser tab's name, it's generally a good idea to keep this short
$tab_title = 'Access Denied';
// Renders page as JSON then stops execution, sending the result to JavaScript on the Dashboard
$ajax_page->sendPage($page_title, $tab_title, $page_content);
}
}
Then, if you visit any Dashboard page and your user ID isn't even, you'll be greeted with this message:

But if you visit a Dash page and your user ID is an even number you'll see the regular page.
###See Also
wp_lib_dash_page_ wp_lib_dash_action wp_lib_dash_action_ wp_lib_dash_api wp_lib_dash_api_