[wp-hackers] change display on custom headers screen
Mike Schinkel
mikeschinkel at newclarity.net
Sat Nov 27 03:10:59 UTC 2010
On Nov 26, 2010, at 1:13 AM, Steve Wolfson wrote:
> I am setting up the Custom Headers admin page as used in the twenty ten
> theme on another theme. I need to remove some of the options from the Admin
> screen. It seems everything on that screen is hard coded in
> /wp-admin/custom-header.php. For example, this will be a WP multisite
> installation. We want users to choose one of the custom headers that will
> be displayed on the custom header page, and not have the option to upload
> their own file. There are no classes or ID's in the code in the areas I
> need to remove display of.
Hi Steve,
If I understand what you are asking you want to modify the "Header" screen in the admin something like this?:
http://mikeschinkel.com/websnaps/skitched-20101126-214332.png
Assuming I understood then yes, you've found that the admin often does not have CSS classes to allow you to hide things and there are frequently no hooks available to modify what you want to modify. I'm not sure why nobody has thought to add CSS classes yet but as for hooks I think it's simply a case of hooks are added when someone takes the effort to ask for them and supply a patch on trac and, at least with the admin, there haven't been many people to do so. So it is what it is.
If you need a hook then best thing would be for you to suggest a hook and include a patch and maybe in next version it'll be there for both you and all the others who may need it in the future.
Of course that doesn't solve your (or others) immediate needs. Lately I've also had numerous client requirements to modify similar things in the admin so I developed a simple plugin I called "Admin Parse Output" to enable me to hook the HTML output of the admin from my functions.php file and make any text substitutes that I might need.
Here's the "Admin Parse Output" plugin:
https://gist.github.com/717514
This approach can be very fragile and is no substitute for proper hooks, to be sure but if you have no other option at least you can get what you need working. It uses the PHP output buffer which is why I created a plugin rather than just putting into functions.php; I've found that if too many plugins use the output buffer they can result in conflicts so having one that offers a parse hook eliminates my need to use multiple ob_start/ob_end_clean() pairs.
Anyway, here's code you can put into your theme's functions.php file (also here: https://gist.github.com/717515):
add_action('admin_parse_output', 'yoursite_admin_parse_output');
function yoursite_admin_parse_output($html) {
global $pagenow;
if ($pagenow=='themes.php' && isset($_GET['page']) && $_GET['page']=='custom-header') {
$msg = '<p>' . __( 'If you don‘t want to upload your own image, you can use one of these cool headers.' ) . '</p>';
$html = str_replace($msg,'',$html);
$html = str_replace(__( 'Default Images' ),__( 'Available Images' ),$html);
$html = preg_replace('#<tr valign="top">\s*<th scope="row">'.__('Upload Image').'</th>(.*)?</td>\s*</tr>#Us','',$html);
}
return $html;
}
If you need it to work slightly differently change what you search for and replace with when calling str_replace() and/or preg_replace().
Hope this helps.
-Mike
P.S. Here's an answer I wrote on WordPress Answers when I first started doing this. While the technique I described above it more evolved this post might help too: http://wordpress.stackexchange.com/questions/2384/#2392
P.P.S. Actually, this hook might make a nice addition to WordPress itself as a "catchall" for those things that there are not already hooks for? Having it in core would eliminate the need for a plugin to use the output buffer directly and thus minimize issues of compatibility which is why there might be a benefit to having it in core.
More information about the wp-hackers
mailing list