Skip to content

Commit b9e389a

Browse files
committed
Large update
Renamed files to organize better, cleaned up code, sorted by use type
1 parent f98b6b9 commit b9e389a

9 files changed

+660
-0
lines changed

functions-admin.php

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?php
2+
3+
// remove editor support for fields on specific post types
4+
add_action( 'admin_init', 'wp_removed_editable_fields' );
5+
function wp_removed_editable_fields() {
6+
remove_post_type_support( 'post', 'title' );
7+
}
8+
9+
// add or remove items from WP menu bar
10+
// http://codex.wordpress.org/Function_Reference/add_menu
11+
function wp_modify_admin_bar() {
12+
global $wp_admin_bar;
13+
$wp_admin_bar->remove_menu( 'wp-logo' );
14+
$wp_admin_bar->remove_menu( 'view-site' );
15+
}
16+
add_action( 'wp_before_admin_bar_render', 'wp_modify_admin_bar' );
17+
18+
// restrict wp-admin access to subscribers
19+
function restrict_access_admin_panel(){
20+
global $current_user;
21+
get_currentuserinfo();
22+
if ($current_user->user_level < 4) {
23+
wp_redirect( get_bloginfo('url') );
24+
exit;
25+
}
26+
}
27+
add_action('admin_init', 'restrict_access_admin_panel', 1);
28+
29+
// disable browser nag/upgrade warnings
30+
function disable_browser_upgrade_warning() {
31+
remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' );
32+
}
33+
add_action( 'wp_dashboard_setup', 'disable_browser_upgrade_warning' );
34+
35+
// increase default (30) limit on custom fields
36+
add_filter( 'postmeta_form_limit' , 'customfield_limit_increase' );
37+
function customfield_limit_increase( $limit ) {
38+
$limit = 60;
39+
return $limit;
40+
}
41+
42+
// disable autosaving in editor screen
43+
function disableAutoSave(){
44+
wp_deregister_script('autosave');
45+
}
46+
add_action( 'wp_print_scripts', 'disableAutoSave' );
47+
48+
// remove curly quotes
49+
remove_filter('the_content', 'wptexturize');
50+
51+
// replace wp-login.php logo
52+
function wp_badge_login_logo() {
53+
echo '<style type="text/css">h1 a { background-image:url("path/to/image") !important; }</style>';
54+
}
55+
add_action('login_head', 'wp_badge_login_logo');
56+
57+
// remove custom fields metabox
58+
function remove_default_page_screen_metaboxes() {
59+
remove_meta_box( 'postcustom','post','normal' );
60+
}
61+
add_action('admin_menu','remove_default_page_screen_metaboxes');
62+
63+
// remove revision list from editor
64+
function remove_revisions_metabox() {
65+
remove_meta_box( 'revisionsdiv','post','normal' );
66+
}
67+
add_action('admin_menu','remove_revisions_metabox');
68+
69+
// add subscript & superscript to tinymce
70+
function enable_more_buttons($buttons) {
71+
$buttons[] = 'sub';
72+
$buttons[] = 'sup';
73+
return $buttons;
74+
}
75+
add_filter("mce_buttons_3", "enable_more_buttons");
76+
77+
// remove default profile fields from admin
78+
function hide_profile_fields( $contactmethods ) {
79+
unset($contactmethods['aim']);
80+
unset($contactmethods['jabber']);
81+
unset($contactmethods['yim']);
82+
return $contactmethods;
83+
}
84+
add_filter('user_contactmethods','hide_profile_fields',10,1);
85+
86+
// restrict author (user) to see only authored posts
87+
function posts_for_current_author($query) {
88+
global $pagenow;
89+
if( 'edit.php' != $pagenow || !$query->is_admin )
90+
return $query;
91+
if( !current_user_can( 'manage_options' ) ) {
92+
global $user_ID;
93+
$query->set('author', $user_ID );
94+
}
95+
return $query;
96+
}
97+
add_filter('pre_get_posts', 'posts_for_current_author');
98+
99+
// restrict user to only see media they have uploaded
100+
function current_user_files_only( $wp_query ) {
101+
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
102+
if ( !current_user_can( 'level_5' ) ) {
103+
global $current_user;
104+
$wp_query->set( 'author', $current_user->id );
105+
}
106+
}
107+
}
108+
add_filter('parse_query', 'current_user_files_only' );
109+
110+
// disable ability to use captions
111+
add_filter( 'disable_captions', create_function( '$a','return true;' ) );
112+
113+
// remove the theme editor submenu
114+
function remove_editor_menu() {
115+
remove_action('admin_menu', '_add_themes_utility_last', 101);
116+
}
117+
add_action('_admin_menu', 'remove_editor_menu', 1);
118+
119+
// disable html editor for roles below admin
120+
function disable_html_editor() {
121+
global $current_user;
122+
get_currentuserinfo();
123+
if ($current_user->user_level != 10) {
124+
echo '<style type="text/css">#editor-toolbar #edButtonHTML, #quicktags {display: none;}</style>';
125+
}
126+
}
127+
add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
128+
add_action( 'admin_head', 'disable_html_editor' );
129+
130+
// remove ability for anyone not "admin" to swap themes
131+
function slt_lock_theme() {
132+
global $submenu, $userdata;
133+
get_currentuserinfo();
134+
if ( $userdata->ID != 1 ) {
135+
unset( $submenu['themes.php'][5] );
136+
unset( $submenu['themes.php'][15] );
137+
}
138+
}
139+
add_action( 'admin_init', 'slt_lock_theme' );
140+
141+
// add a custom message to the login screen
142+
function custom_login_message() {
143+
$message = '<p class="message">Welcome, please read our <a href="#">terms of service</a> before you register.</p><br />';
144+
return $message;
145+
}
146+
add_filter('login_message', 'custom_login_message');
147+
148+
// automatically categorize and tag posts when saved
149+
function update_post_terms( $post_id ) {
150+
if ( $parent = wp_is_post_revision( $post_id ) )
151+
$post_id = $parent;
152+
$post = get_post( $post_id );
153+
if ( $post->post_type != 'post' )
154+
return;
155+
// add a tag
156+
wp_set_post_terms( $post_id, 'new tag', 'post_tag', true );
157+
// add a category
158+
$categories = wp_get_post_categories( $post_id );
159+
$newcat = get_term_by( 'name', 'Some Category', 'category' );
160+
array_push( $categories, $newcat->term_id );
161+
wp_set_post_categories( $post_id, $categories );
162+
}
163+
add_action( 'wp_insert_post', 'update_post_terms' );
164+
165+
// restrict upload file types
166+
function restrict_mime($mimes) {
167+
$mimes = array(
168+
'jpg|jpeg|jpe' => 'image/jpeg',
169+
'gif' => 'image/gif',
170+
);
171+
return $mimes;
172+
}
173+
add_filter('upload_mimes','restrict_mime');
174+
175+
// add total members to “Right Now” dashboard widget
176+
function dashboard_wp_user_count() {
177+
global $wpdb;
178+
$user_c = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users");
179+
?>
180+
<table>
181+
<tbody>
182+
<tr class="first">
183+
<td class="first b b_pages"><a href="users.php"><? echo $user_c; ?></a></td>
184+
<td class="t pages"><a href="users.php">Members</a></td>
185+
</tr>
186+
</tbody>
187+
</table>
188+
<?php
189+
}
190+
add_action( 'right_now_content_table_end', 'dashboard_wp_user_count');
191+
192+
// remove WP defined admin submenus
193+
function remove_submenus() {
194+
global $submenu;
195+
//Dashboard menu
196+
unset($submenu['index.php'][10]); // Removes Updates
197+
//Posts menu
198+
unset($submenu['edit.php'][5]); // Leads to listing of available posts to edit
199+
unset($submenu['edit.php'][10]); // Add new post
200+
unset($submenu['edit.php'][15]); // Remove categories
201+
unset($submenu['edit.php'][16]); // Removes Post Tags
202+
//Media Menu
203+
unset($submenu['upload.php'][5]); // View the Media library
204+
unset($submenu['upload.php'][10]); // Add to Media library
205+
//Links Menu
206+
unset($submenu['link-manager.php'][5]); // Link manager
207+
unset($submenu['link-manager.php'][10]); // Add new link
208+
unset($submenu['link-manager.php'][15]); // Link Categories
209+
//Pages Menu
210+
unset($submenu['edit.php?post_type=page'][5]); // The Pages listing
211+
unset($submenu['edit.php?post_type=page'][10]); // Add New page
212+
//Appearance Menu
213+
unset($submenu['themes.php'][5]); // Removes 'Themes'
214+
unset($submenu['themes.php'][7]); // Widgets
215+
unset($submenu['themes.php'][15]); // Removes Theme Installer tab
216+
//Plugins Menu
217+
unset($submenu['plugins.php'][5]); // Plugin Manager
218+
unset($submenu['plugins.php'][10]); // Add New Plugins
219+
unset($submenu['plugins.php'][15]); // Plugin Editor
220+
//Users Menu
221+
unset($submenu['users.php'][5]); // Users list
222+
unset($submenu['users.php'][10]); // Add new user
223+
unset($submenu['users.php'][15]); // Edit your profile
224+
//Tools Menu
225+
unset($submenu['tools.php'][5]); // Tools area
226+
unset($submenu['tools.php'][10]); // Import
227+
unset($submenu['tools.php'][15]); // Export
228+
unset($submenu['tools.php'][20]); // Upgrade plugins and core files
229+
//Settings Menu
230+
unset($submenu['options-general.php'][10]); // General Options
231+
unset($submenu['options-general.php'][15]); // Writing
232+
unset($submenu['options-general.php'][20]); // Reading
233+
unset($submenu['options-general.php'][25]); // Discussion
234+
unset($submenu['options-general.php'][30]); // Media
235+
unset($submenu['options-general.php'][35]); // Privacy
236+
unset($submenu['options-general.php'][40]); // Permalinks
237+
unset($submenu['options-general.php'][45]); // Misc
238+
}
239+
add_action('admin_menu', 'remove_submenus');

0 commit comments

Comments
 (0)