Upload
jesper-van-engelen
View
200
Download
0
Embed Size (px)
Citation preview
CUSTOMISING WORDPRESS’ADMIN PANEL
#wcgva
Hello! I’mJesper van Engelen.
Plugin developer
Core contributor
WP translator
AdminColumns.com
WP developer
We’re lucky to bein WordPress
#wcgva @jesperengelen
WORDPRESS POWERS 47,847,425 WEBSITES
13% 16%
18% 22%
24% 26%
2011 2012 2013 2014 2015 2016
(give or take)
SO WHY IS THE BACKEND ALWAYSSO DARN UGLY?
What have you done to
my beautiful WordPress?
Let’s cleanwp-admin
#wcgva @jesperengelen
1.The Menu (API)
Keep what you need, discard what you don’t
3 plugins
“ Why do it yourself if somebody hasalready done it for you?
Or simply do it yourself: The Menu API
add_menu_page( [..] )add_submenu_page( [..] )
Add
remove_menu_page( $slug )remove_submenu_page( $slug )
Remove
WHAT’S ASLUG?
Removing menu items
add_action( 'admin_menu', 'myplugin_clean_menu' );
function myplugin_clean_menu() {// Default menu itemsremove_menu_page( 'options-general.php' );remove_menu_page( 'tools.php' );remove_menu_page( 'edit-comments.php' );remove_menu_page( 'edit.php' );remove_menu_page( 'themes.php' );
// Plugin menu itemsremove_menu_page( 'wpseo_dashboard' );
}
Old New
2.The Columns (API)
Display information that is relevant to your content
THEPROBLEM
2 plugins
“ Why do it yourself if somebody hasalready done it for you?
The Columns API
Add and remove columns
add_filter( 'manage_[post_type]_posts_columns', 'mp_columns' );function mp_columns( $columns ) {
/* Add or remove columns here */
return $columns;}
Create column content
add_action( 'manage_[post_type]_custom_column', 'mp_column_rent' );function mp_column_rent( $column, $post_id ) {
/* Output content for columns */}
The Columns API
Add and remove columns
add_filter( 'manage_[post_type]_posts_columns', 'mp_columns' );function mp_columns( $columns ) {
/* Add or remove columns here */
return $columns;}
Create column content
add_action( 'manage_[post_type]_custom_column', 'mp_column_rent' );function mp_column_rent( $column, $post_id ) {
/* Output content for columns */}
Add and remove columnsReal Estate:
add_filter( 'manage_realestate_posts_columns', 'mp_columns', 100 );function mp_columns( $columns ) {
// Remove existing columnsunset( $columns['date'] );unset( $columns['wpseo-score'] );unset( $columns['wpseo-score-readability'] );
// Add new column)$columns = array_slice( $columns, 0, 1, true )
+ array( 'image' => __( 'Image' ) )+ array_slice( $columns, 1, NULL, true )+ array( 'rent' => __( 'Rent' ) );
return $columns;}
add_action( 'manage_realestate_posts_custom_column', 'mp_column', 10, 2 );function mp_column( $column, $post_id ) {
// Image columnif ( $column == 'image' ) {
echo get_the_post_thumbnail( $post_id, array(80,80) );}
// Monthly rent columnif ( $column == 'rent' ) {
$rent = get_post_meta( $post_id, 'rent', true );if ( ! $rent ) {
_e( 'n/a' );} else {
echo number_format( $rent, 0, '.', ',' ) . ' CHF';}
}}
Add column contentReal Estate:
Old New
OH YEAH!
THANKS!Any questions?…or talk to me on Twitter @jesperengelen