Skip to content

Instantly share code, notes, and snippets.

@nacin
Forked from norcross/admin_htaccess.txt
Created November 5, 2011 04:03
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nacin/1341091 to your computer and use it in GitHub Desktop.
Save nacin/1341091 to your computer and use it in GitHub Desktop.
WCPhilly Admin
<?php
/*
Plugin Name: WordCamp Philly 2011 Admin
Plugin URI: http://localhost/whitelabel
Description: Some swanky stuff to make your admin look GOOD
Author: Andrew Norcross
Version: 0.1
Requires at least: 3.0
Author URI: http://andrewnorcross.com
*/
/* Copyright 2011 Andrew Norcross
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License (GPL v2) only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// custom CSS for admin logo and layout
function rkv_custom_stylez() {
# You may want to use plugins_url( 'img/favicon.png', __FILE__ ), as it feels cleaner.
echo '<link rel="shortcut icon" type="image/png" href="' . plugin_dir_url(__FILE__) . '/img/favicon.png" />';
# You're better off using wp_enqueue_style() here, and hook that to admin_enqueue_scripts and login_enqueue_scripts.
# Example: wp_enqueue_style( 'rkv_admin_style', plugins_url( 'css/rkv_admin_style.css', __FILE__ ) );
echo '<link rel="stylesheet" href="' . plugin_dir_url(__FILE__) . '/css/rkv_admin_style.css" type="text/css" media="screen" />';
}
add_action('login_head', 'rkv_custom_stylez');
add_action('admin_head', 'rkv_custom_stylez');
// add admin logo link swap
function rkv_login_link_swap() {
# You can use home_url('/') here.
$site_url = get_bloginfo('url');
$site_name = get_bloginfo('name');
# Don't do this. What if jQuery is already loaded? Instead: wp_enqueue_script( 'jquery' ), and do that on login_enqueue_scripts.
echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>';
# Don't do this. WordPress has filters here -- login_headertitle and login_headerurl. Hook in and you don't need this function at all.
?>
<script type="text/javascript">
jQuery(function(){
$('h1 a').replaceWith('<a title="<?php echo $site_name ?>. Powered by WordPress" href="<?php echo $site_url ?>"><?php echo $site_name ?></a>');
});
</script>
<?php }
add_action('login_head', 'rkv_login_link_swap');
// re-order admin panel
# Nice find. This is rarely used.
function rkv_reorder_menu($menu_ord) {
# See note below on why this line isn't necessary (and is confusing).
if (!$menu_ord) return true;
return array(
'index.php', // this represents the dashboard link
'edit.php?post_type=page', // this is the default page menu
'edit.php', // this is the default POST admin menu
'upload.php',
);
}
# Rather than passing this to rkv_reorder_menu() with the hack above there,
# just use '__return_true' as the callback. Simple, effective.
add_filter('custom_menu_order', 'rkv_reorder_menu');
add_filter('menu_order', 'rkv_reorder_menu');
// change main post labels
# Not a fan, but you gotta do what you gotta do.
function rkv_main_post_menu_labels() {
global $menu;
global $submenu;
$menu[5][0] = 'Products';
$submenu['edit.php'][5][0] = 'Products';
$submenu['edit.php'][10][0] = 'Add Product';
$submenu['edit.php'][15][0] = 'Product Types';
$submenu['edit.php'][16][0] = 'Product Tags';
echo '';
}
add_action( 'admin_menu', 'rkv_main_post_menu_labels' );
// Change post to product labels
# See above note -- not a fan, but gotta do what you gotta do. Not sure why you wouldn't just
# avoid the core taxonomies and post types though, and just create your own at this point.
function rkv_detail_post_labels() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'Products';
$labels->singular_name = 'Product';
$labels->add_new = 'Add Product';
$labels->add_new_item = 'Add Product';
$labels->edit_item = 'Edit Products';
$labels->new_item = 'Product';
$labels->view_item = 'View Product';
$labels->search_items = 'Search Products';
$labels->not_found = 'No Products found';
$labels->not_found_in_trash = 'No Products found in Trash';
}
add_action( 'init', 'rkv_detail_post_labels' );
// change category labels
function rkv_change_category_labels() {
global $wp_taxonomies;
$labels = &$wp_taxonomies['category']->labels;
$labels->name = 'Product Types';
$labels->singular_name = 'Product Type';
$labels->add_new_item = 'Add New Product Type';
$labels->edit_item = 'Edit Product Type';
$labels->search_items = 'Search Product Types';
$labels->update_item = 'Update Product Type';
$labels->all_items = 'All Product Types';
}
add_action( 'init', 'rkv_change_category_labels' );
// change tag labels
function rkv_change_tag_labels() {
global $wp_taxonomies;
$labels = &$wp_taxonomies['post_tag']->labels;
$labels->name = 'Product Tags';
$labels->singular_name = 'Product Tag';
$labels->add_new_item = 'Add New Product Tag';
$labels->edit_item = 'Edit Product Tag';
$labels->search_items = 'Search Product Tags';
$labels->update_item = 'Update Product Tag';
$labels->all_items = 'All Product Tags';
}
add_action( 'init', 'rkv_change_tag_labels' );
// remove dashboard widgets
function rkv_dashboard_cleanup() {
# :-( Use remove_meta_box() instead.
# remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
global $wp_meta_boxes;
unset(
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'],
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'],
$wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'],
$wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'],
$wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts'],
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links'],
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'],
$wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']
);
// add call to include two custom ones
wp_add_dashboard_widget('rkv_help_text', 'Help and Support Links', 'rkv_help_links'); // add a new custom widget for help and support
wp_add_dashboard_widget('rkv_help_vids', 'Help and Support Videos', 'rkv_help_videos'); // add a new custom widget for help and support
}
add_action('wp_dashboard_setup', 'rkv_dashboard_cleanup');
// add custom help links and video
function rkv_help_links() { ?>
<p>Take a look at these links</p>
<ul>
<li><a href="http://awesome.com">Support Link #1</a></li>
<li><a href="http://awesome.com">Support Link #2</a></li>
<li><a href="http://awesome.com">Support Link #1</a></li>
</ul>
<?php }
function rkv_help_videos() { ?>
<div style="width:420px; margin:0 auto; display:block;"><iframe width="420" height="243" src="http://www.youtube.com/embed/9IbGVWDO0YU?rel=0&amp;hd=1" frameborder="0" allowfullscreen></iframe></div>
<?php }
// change post title box text
function rkv_change_post_text( $translation ) {
global $post;
if( isset( $post ) ) {
switch( $post->post_type ){
case 'post' :
# This works, but you'd be better off inspecting the current screen object.
# Example: $screen = get_current_screen(); if $screen->id == 'post' ... (post-new.php or post.php for post type = post), and you're done.
# HOWEVER: There's a filter here! There's an enter_title_here filter designed for this. This avoids gettext hacks.
if( $translation == 'Enter title here' )
return 'Enter Product Name Here';
break;
}
}
return $translation;
}
add_action('gettext', 'rkv_change_post_text');
// remove items from the admin panel
# Looks good.
function rkv_remove_extras() {
remove_menu_page('link-manager.php');
remove_menu_page('edit-comments.php');
remove_menu_page('theme-editor.php');
}
add_action( 'admin_menu', 'rkv_remove_extras' );
// remove the columns I don't need
function rkv_edit_post_columns($defaults) {
unset($defaults['comments']);
unset($defaults['author']);
unset($defaults['date']);
return $defaults;
}
# Looks good, but note that these filters fire for all post types. (The first one for all non-hierarchical post types,
# the secondone for all hierarhical post types.) You probably don't want to step on other post types.
# Try manage_{$post_type}_posts_columns for that.
add_filter('manage_posts_columns', 'rkv_edit_post_columns');
add_filter('manage_pages_columns', 'rkv_edit_post_columns');
// re-title my columns
function rkv_mod_columns($new_columns) {
# Next line isn't necessary.
$new_columns['cb'] = '<input type="checkbox" />';
$new_columns['title'] = _x('Product Name', 'column name');
$new_columns['categories'] = _x('Product Type', 'column name');
$new_columns['tags'] = _x('Product Tags', 'column name');
return $new_columns;
}
add_filter('manage_posts_columns', 'rkv_mod_columns');
// Make these columns sortable
# This code doesn't do anything. You've told WordPress they can be clicked to be sorted, but WordPress
# doesn't know how to sort them. See http://scribu.net/wordpress/custom-sortable-columns.html.
function rkv_sortable_columns($columns) {
$columns['categories'] = 'categories';
$columns['tags'] = 'tags';
return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'rkv_sortable_columns' );
// clean up the admin bar to match
function rkv_admin_bar_cleanup() {
global $wp_admin_bar;
// we can remove an entire menu item
$wp_admin_bar->remove_menu('comments');
// or we can remove just a submenu item.
$wp_admin_bar->remove_menu('new-link', 'new-content');
// we can add also submenu item too
$wp_admin_bar->add_menu( array(
'parent' => 'dashboard',
'id' => 'new_awesome',
'title' => __('Awesome Help Links'),
'href' => 'http://awesome.com'
) );
}
// and we hook our function via
# Looks good, though I'd use the add_admin_bar_menus hook. (Similar to the widgets_init hook -- it
# fires after the core widgets are registered.)
add_action( 'wp_before_admin_bar_render', 'rkv_admin_bar_cleanup' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment