Ticket #9674: 9674.11.diff

File 9674.11.diff, 4.3 KB (added by ryan, 3 years ago)

Post type capabilities (incomplete and untested)

Line 
1Index: wp-includes/post.php
2===================================================================
3--- wp-includes/post.php        (revision 12646)
4+++ wp-includes/post.php        (working copy)
5@@ -19,6 +19,7 @@
6        register_post_type( 'page', array('label' => __('Pages'),'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'page.php?post=%d', 'capability_type' => 'page', 'hierarchical' => true) );
7        register_post_type( 'attachment', array('label' => __('Media'), 'exclude_from_search' => false, '_builtin' => true, '_edit_link' => 'media.php?attachment_id=%d', 'capability_type' => 'post', 'hierarchical' => false) );
8        register_post_type( 'revision', array('label' => __('Revisions'),'exclude_from_search' => true, '_builtin' => true, '_edit_link' => 'revision.php?revision=%d', 'capability_type' => 'post', 'hierarchical' => false) );
9+       add_post_type_support('post', array('thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') );
10 }
11 add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
12 
13@@ -562,6 +563,50 @@
14 }
15 
16 /**
17+ * Register support of certain features for a post type.
18+ *
19+ * @since 3.0
20+ * @param string $post_type The post type for which to add the feature
21+ * @param string|array $feature the feature being added, can be an array of feature strings or a single string
22+ */
23+function add_post_type_support( $post_type, $feature ) {
24+       global $_wp_post_type_features;
25+
26+       $features = array($feature);
27+       foreach ($features as $feature) {
28+               if ( func_num_args() == 2 )
29+                       $_wp_post_type_features[$post_type][$feature] = true;
30+               else
31+                       $_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
32+       }
33+}
34+
35+/**
36+ * Checks a post type's support for a given feature
37+ *
38+ * @since 3.0
39+ * @param string $post_type The post type being checked
40+ * @param string $feature the feature being checked
41+ * @return boolean
42+ */
43+
44+function post_type_supports( $post_type, $feature ) {
45+       global $_wp_post_type_features;
46+
47+       if ( !isset( $_wp_post_type_features[$post_type][$feature] ) )
48+               return false;
49+
50+       // If no args passed then no extra checks need be performed
51+       if ( func_num_args() <= 2 )
52+               return true;
53+
54+       // @todo Allow pluggable arg checking
55+       //$args = array_slice( func_get_args(), 2 );
56+
57+       return true;
58+}
59+
60+/**
61  * Updates the post type for the post ID.
62  *
63  * The page or post cache will be cleaned for the post ID.
64Index: wp-admin/edit-form-advanced.php
65===================================================================
66--- wp-admin/edit-form-advanced.php     (revision 12646)
67+++ wp-admin/edit-form-advanced.php     (working copy)
68@@ -101,13 +101,17 @@
69        add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', $post_type, 'side', 'core');
70 if ( current_theme_supports( 'post-thumbnails', $post_type ) )
71        add_meta_box('postimagediv', __('Post Thumbnail'), 'post_thumbnail_meta_box', $post_type, 'side', 'low');
72-add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
73-add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
74-add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
75+if ( post_type_supports($post_type, 'excerpts') )
76+       add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $post_type, 'normal', 'core');
77+if ( post_type_supports($post_type, 'trackbacks') )
78+       add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', $post_type, 'normal', 'core');
79+if ( post_type_supports($post_type, 'custom-fields') )
80+       add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', $post_type, 'normal', 'core');
81 do_action('dbx_post_advanced');
82-add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
83+if ( post_type_supports($post_type, 'comments') )
84+       add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', $post_type, 'normal', 'core');
85 
86-if ( 'publish' == $post->post_status || 'private' == $post->post_status )
87+if ( ('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments') )
88        add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', $post_type, 'normal', 'core');
89 
90 if ( !( 'pending' == $post->post_status && !current_user_can( 'publish_posts' ) ) )