Validating Custom Meta Box Values & Required Fields

The easiest way is to add Javascript validation via the jQuery Validate plugin. Here’s the most basic walkthrough: Near your add_meta_box call, enqueue the jQuery Validate plugin as well as a JS file for your simple script: add_action(‘admin_enqueue_scripts’, ‘add_my_js’); function add_my_js(){ wp_enqueue_script(‘my_validate’, ‘path/to/jquery.validate.min.js’, array(‘jquery’)); wp_enqueue_script(‘my_script_js’, ‘path/to/my_script.js’); } Then in my_script.js include the following: jQuery().ready(function() { … Read more

Creating an Image-Centric Custom Post Type?

goldenapple’s initial answer gave me the jumpstart I needed to finish this up. functions.php Here is the complete code I’m using to add a new post type “header-image” and modify other admin screens accordingly: /** * Register the Header Image custom post type. */ function sixohthree_init() { $labels = array( ‘name’ => ‘Header Images’, ‘singular_name’ … Read more

How to *remove* a parent theme page template from a child theme?

Overriding that template would be much easier than getting rid of it. Just the way logic goes. I make no claim it’s efficient idea (late here), but this would get it nuked from edit screen: add_action(‘admin_head-post.php’,’remove_template’); function remove_template() { global $wp_themes; get_themes(); $templates = &$wp_themes[‘Twenty Ten’][‘Template Files’]; $template = trailingslashit( TEMPLATEPATH ).’onecolumn-page.php’; $key = array_search($template, … Read more

Restrict custom post type to only site administrator role

register_post_type() accepts a parameter capabilities in its arguments. See get_post_type_capabilities() for possible values. From the comments: By default, seven keys are accepted as part of the capabilities array: edit_post, read_post, and delete_post are meta capabilities, which are then generally mapped to corresponding primitive capabilities depending on the context, which would be the post being edited/read/deleted … Read more