wp_lib_dash_home_buttons - roberts-sandbox/create-repo GitHub Wiki

###Description

This filter is applied to the large buttons on the Library Dashboard home page, allowing for buttons to be added or removed. This filter was added in Alpha v3 (Badger Claw).

###Context

To access the Library Dashboard users must be at the minimum a librarian and thus logged in as a WordPress user.

###Parameters

$buttons
An array of the buttons that will be rendered to the Dashboard.

###Example

If you wanted to add a button that links to your custom Dashboard page loan-statistics, but only appeared to Library Admins, you could do the following:


add_filter('wp_lib_dash_home_buttons', 'add_statistics_page_button');

function add_statistics_page_button(Array $buttons) {
	// Stops regular librarians seeing the button
	if (!wp_lib_is_library_admin())
		return $buttons;
	
	// Inserts button at the end
	$buttons[] = array(
		'bName'	=> 'Loan Statistics',
		'icon'	=> 'chart-line',
		'link'	=> 'dash-page',
		'value'	=> 'loan-statistics',
		'title'	=> 'View detailed statics on item loan history'
	);
	
	return $buttons;
}

Which would add the following button, visible only to Library Admins, to the Library Dashboard homepage:

Note: Make sure to add user privilege checking to the dash page as well, otherwise non-admins could access library admin dash pages using the direct URL.

###Dashboard Buttons

Dashboard buttons are associative arrays of properties that are used client-side to render the buttons as part of the dynamically generated dash pages. In addition to the properties listed below, after the filter is applied all Dash buttons are given type => dash-button so that the Dash page element is rendered correctly client-side.

Property Key Purpose
Name bname The text that appears below the button icon e.g. Scan Barcode
Title title The title text that appears when hovering over the button, providing more information as to the purpose of the button
Icon icon The name of the WordPress Dashicon to use as the button's icon. 'admin-tools' would display this icon. WP-Librarian will hopefully eventually have its own icon selection, providing a second icon set to choose from.
Link link The category of button link. See the table below.
Post Type* pType The post type the button will link to
URL* url A link to an internal or external resource
Dash Page* value The name of the dashboard page to link to

* Dependant on selected link type

###Link Types

Dashboard buttons can link to internal dash pages, a WordPress post type's admin table page, a WP admin URL or a full URL.

####Dash Page

'link' => 'dash-page'
A link to a Dashboard page. 'value' => 'view-items' would link to the View Items dash page. Never use URLs to link from one Dash page to another.

####Post Type

'link' => 'post-type'
A link to a WordPress post type. 'cpt' => 'wp_lib_members' would link to the admin post table for Members.
Note: Before Badger Claw the property cpt was called pType.

####Admin URL

'link' => 'admin-url'
A link to a WordPress Admin URL. 'url' => 'index.php' would link to yoursite.com/wp-admin/index.php. Never hardcode wp-admin/ in a URL as this can vary depending on the WP installation.

####URL

'link' => 'url'
A link to a URL. 'url' => 'https://github.com/kittsville/WP-Librarian/' would link the button to https://github.com/kittsville/WP-Librarian/.

⚠️ **GitHub.com Fallback** ⚠️