| 1 | Index: wp-includes/taxonomy.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/taxonomy.php (revision 15595) |
|---|
| 4 | +++ wp-includes/taxonomy.php (working copy) |
|---|
| 5 | @@ -70,6 +70,19 @@ |
|---|
| 6 | 'show_ui' => false, |
|---|
| 7 | '_builtin' => true, |
|---|
| 8 | ) ) ; |
|---|
| 9 | + |
|---|
| 10 | + register_taxonomy( 'post_mode', array('post', 'page', 'attachment'), array( |
|---|
| 11 | + 'hierarchical' => false, |
|---|
| 12 | + 'labels' => array( |
|---|
| 13 | + 'name' => '', |
|---|
| 14 | + 'singular_name' => '', |
|---|
| 15 | + ), |
|---|
| 16 | + 'query_var' => false, |
|---|
| 17 | + 'rewrite' => false, |
|---|
| 18 | + 'show_ui' => false, |
|---|
| 19 | + '_builtin' => true, |
|---|
| 20 | + 'show_in_nav_menus' => false, |
|---|
| 21 | + ) ) ; |
|---|
| 22 | } |
|---|
| 23 | add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority |
|---|
| 24 | |
|---|
| 25 | Index: wp-includes/post.php |
|---|
| 26 | =================================================================== |
|---|
| 27 | --- wp-includes/post.php (revision 15595) |
|---|
| 28 | +++ wp-includes/post.php (working copy) |
|---|
| 29 | @@ -471,6 +471,52 @@ |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | /** |
|---|
| 33 | + * Register support for a post mode. |
|---|
| 34 | + * |
|---|
| 35 | + * @param string|array $mode A mode or array of modes to register. Valid modes are 'aside', 'chat', 'gallery', 'image', 'link', 'quote', or 'video'. |
|---|
| 36 | + * @param string|array |
|---|
| 37 | + * @return mixed WP_Error on error. |
|---|
| 38 | + */ |
|---|
| 39 | +function register_post_mode( $modes, $post_types = array('post', 'page', 'attachment') ) { |
|---|
| 40 | + global $wp_post_modes; |
|---|
| 41 | + |
|---|
| 42 | + if ( !isset($wp_post_modes) ) |
|---|
| 43 | + $wp_post_modes = array(); |
|---|
| 44 | + |
|---|
| 45 | + $the_modes = array('aside', 'chat', 'gallery', 'image', 'link', 'quote', 'video'); |
|---|
| 46 | + // Dummy gettext calls to get translations for modes into the default catalog. |
|---|
| 47 | + // @todo gettext context. Move to an admin function? |
|---|
| 48 | + __('Aside'); __('Chat'); __('Gallery'); __('Image'); __('Link'); __('Quote'); __('Video'); |
|---|
| 49 | + |
|---|
| 50 | + foreach ( (array) $modes as $mode ) { |
|---|
| 51 | + if ( !in_array($mode, $the_modes) ) |
|---|
| 52 | + return new WP_Error('invalid_mode', __('Invalid mode')); |
|---|
| 53 | + $wp_post_modes[$mode] = (array) $post_types; |
|---|
| 54 | + } |
|---|
| 55 | +} |
|---|
| 56 | + |
|---|
| 57 | +/** |
|---|
| 58 | + * Assign a mode to a post |
|---|
| 59 | + * |
|---|
| 60 | + * @param int|object $post The post for which to assign a mode |
|---|
| 61 | + * @param string $mode A mode to assign. The mode must have already been registered with register_post_mode(). |
|---|
| 62 | + * @return mixed WP_Error on error. Array of affected term IDs on success. |
|---|
| 63 | + */ |
|---|
| 64 | +function set_post_mode( $post, $mode ) { |
|---|
| 65 | + global $wp_post_modes; |
|---|
| 66 | + |
|---|
| 67 | + $post = get_post($post); |
|---|
| 68 | + |
|---|
| 69 | + if ( empty($post) ) |
|---|
| 70 | + return new WP_Error('invalid_post', __('Invalid post')); |
|---|
| 71 | + |
|---|
| 72 | + if ( !isset($wp_post_nodes) || ! in_array($mode, $wp_post_modes) ) |
|---|
| 73 | + return new WP_Error('invalid_mode', __('Invalid mode')); |
|---|
| 74 | + |
|---|
| 75 | + return wp_set_post_terms($post_id, array('mode-' . $mode), 'post_mode'); |
|---|
| 76 | +} |
|---|
| 77 | + |
|---|
| 78 | +/** |
|---|
| 79 | * Retrieve the post status based on the Post ID. |
|---|
| 80 | * |
|---|
| 81 | * If the post ID is of an attachment, then the parent post status will be given |
|---|