Ok nothing posted answered my question on the last topic but have got a workable solution after messing around with various plugins
I have a separate issue now arising from this, I am using a theme which uses the following function to ad various custom buttons to the post editor
function media_buttons($editor_id = 'content') {
$post = get_post();
if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
$post = $GLOBALS['post_ID'];
wp_enqueue_media( array(
'post' => $post,
) );
$img = '<span class="wp-media-buttons-icon"></span> ';
echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
// Don't use this filter. Want to add a button? Use the media_buttons action.
$legacy_filter = apply_filters('media_buttons_context', ''); // deprecated
if ( $legacy_filter ) {
// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
$legacy_filter .= '</a>';
echo $legacy_filter;
}
}
add_action( 'media_buttons', 'media_buttons' );
I wish to modify this function so the buttons show on custom page types I setup along with regular posts and page in the backend for all user roles
Navjot Singh answers:
Try the solution mentioned [[LINK href="http://wordpress.stackexchange.com/a/88397/5730"]]here[[/LINK]].
Navjot Singh comments:
Also add 'map_meta_cap' => true as an argument in your above custom post type function.
richard o' neill comments:
Hi Navjot, think that solution might work but a bit unsure how to implement it do you know where the fubction he has mentioned in the solution needs to go ie. what file?
Navjot Singh comments:
That function should go in your theme's function.php.
Navjot Singh comments:
For your modified question try this code instead of the one you listed
function media_buttons($editor_id = 'content') {
global $post;
if($post->post_type == 'YOURCUSTOMPOSTTYPE' || $post->post_type == 'post' || $post->post_type == 'page') {
wp_enqueue_media();
$img = '<span class="wp-media-buttons-icon"></span> ';
echo '<a href="#" class="button insert-media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' . esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';
// Don't use this filter. Want to add a button? Use the media_buttons action.
$legacy_filter = apply_filters('media_buttons_context', ''); // deprecated
if ( $legacy_filter ) {
// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
$legacy_filter .= '</a>';
echo $legacy_filter;
}
}
}
add_action( 'media_buttons', 'media_buttons' );
Arnav Joy answers:
try this
<?php
function create_post_type() {
register_post_type( 'subjects',
array(
'labels' => array(
'name' => __( 'subjects' ),
'singular_name' => __( 'subjects' )
),
'public' => true,
'capability_type' => 'subjects',
'capabilities' => array(
'publish_posts' => 'publish_subjects',
'edit_posts' => 'edit_subjects',
'edit_others_posts' => 'edit_others_subjects',
'delete_posts' => 'delete_subjects',
'delete_others_posts' => 'delete_others_subjects',
'read_private_posts' => 'read_private_subjects',
'edit_post' => 'edit_subject',
'delete_post' => 'delete_subject',
'read_post' => 'read_subject',
),
'menu_position' => 5,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes' ),
'rewrite' => array('slug' => 'subjects')
)
);
}
add_action( 'init', 'create_post_type' );
add_filter( 'map_meta_cap', 'map_meta_cap', 10, 4 );
function map_meta_cap( $caps, $cap, $user_id, $args ) {
/* If editing, deleting, or reading a movie, get the post and post type object. */
if ( 'edit_subject' == $cap || 'delete_subject' == $cap || 'read_subject' == $cap ) {
$post = get_post( $args[0] );
$post_type = get_post_type_object( $post->post_type );
/* Set an empty array for the caps. */
$caps = array();
}
/* If editing a movie, assign the required capability. */
if ( 'edit_subject' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->edit_posts;
else
$caps[] = $post_type->cap->edit_others_posts;
}
/* If deleting a movie, assign the required capability. */
elseif ( 'delete_subject' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->delete_posts;
else
$caps[] = $post_type->cap->delete_others_posts;
}
/* If reading a private movie, assign the required capability. */
elseif ( 'read_subject' == $cap ) {
if ( 'private' != $post->post_status )
$caps[] = 'read';
elseif ( $user_id == $post->post_author )
$caps[] = 'read';
else
$caps[] = $post_type->cap->read_private_posts;
}
/* Return the capabilities required by the user. */
return $caps;
}
Arnav Joy comments:
i do not think so , this is the only function used to show the buttons , can you share everything related to it?
Dbranes answers:
Here are some useful <em>custom-post-type</em> / <em>custom-taxonomy</em> <strong>generators</strong> that you might find helpful :
[[LINK href="http://themergency.com/generators/wordpress-custom-post-types/"]]http://themergency.com/generators/wordpress-custom-post-types/[[/LINK]]
[[LINK href="http://themergency.com/generators/simple-wordpress-custom-post-type-generator/"]]http://themergency.com/generators/simple-wordpress-custom-post-type-generator/[[/LINK]]
[[LINK href="http://themergency.com/generators/wordpress-custom-taxonomy/"]]http://themergency.com/generators/wordpress-custom-taxonomy/[[/LINK]]