Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Problem with custom post-type

UserPost

8:00 am
November 11, 2010


acebone

Member

Denmark

posts 9

1

[RESOLVED]

When adding the hook that registers the new post type, give it a low value in the init queue like this:

add_action('init', 'my_custom_init', 1);

[QUESTION]

Using 1.3.5-dev and WP 3.01

In the codex page for register_post_type they give an elaborate example of how to define and register a custom post type.

When using the example verbatim I get the following notices when either adding or editing a book:

Notice: Trying to get property of non-object in C:\Users\em.BOLIG\Documents\My Dropbox\xampp\htdocs\WPVanilla\wp-content\plugins\role-scoper\admin\admin_rs.php on line 175

Notice: Trying to get property of non-object in C:\Users\em.BOLIG\Documents\My Dropbox\xampp\htdocs\WPVanilla\wp-content\plugins\role-scoper\admin\admin_rs.php on line 175

Notice: Trying to get property of non-object in C:\Users\em.BOLIG\Documents\My Dropbox\xampp\htdocs\WPVanilla\wp-content\plugins\role-scoper\admin\admin_rs.php on line 176

Notice: Trying to get property of non-object in C:\Users\em.BOLIG\Documents\My Dropbox\xampp\htdocs\WPVanilla\wp-content\plugins\role-scoper\admin\admin_rs.php on line 176

Furthermore the post-type is not available in the role-scoper menues.

I've used diff. automatic solutions for custom-post types, and I've had no problems with role-scoper in that respect.

I've tried other examples from other resources on how to call the register_post_type function manually, they too result in the notices from role-scoper (and non-availability of the posts for role-scoping)

Is anything missing in the call, or is it a bug in RS?

<?php
add_action('init', 'my_custom_init');
function my_custom_init()
{
$labels = array(
'name' => _x('Books', 'post type general name'),
'singular_name' => _x('Book', 'post type singular name'),
'add_new' => _x('Add New', 'book'),
'add_new_item' => __('Add New Book'),
'edit_item' => __('Edit Book'),
'new_item' => __('New Book'),
'view_item' => __('View Book'),
'search_items' => __('Search Books'),
'not_found' => __('No books found'),
'not_found_in_trash' => __('No books found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt','comments')
);
register_post_type('book',$args);
}

//add filter to insure the text Book, or book, is displayed when user updates a book
add_filter('post_updated_messages', 'book_updated_messages');
function book_updated_messages( $messages ) {
global $post, $post_ID;

$messages['book'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __('Book updated. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
2 => __('Custom field updated.'),
3 => __('Custom field deleted.'),
4 => __('Book updated.'),
/* translators: %s: date and time of the revision */
5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __('Book published. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
7 => __('Book saved.'),
8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>'),
// translators: Publish box date format, see http://php.net/date
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);

return $messages;
}

//display contextual help for Books
add_action( 'contextual_help', 'add_help_text', 10, 3 );

function add_help_text($contextual_help, $screen_id, $screen) {
//$contextual_help .= var_dump($screen); // use this to help determine $screen->id
if ('book' == $screen->id ) {
$contextual_help =
'<p>' . __('Things to remember when adding or editing a book:') . '</p>' .
'<ul>' .
'<li>' . __('Specify the correct genre such as Mystery, or Historic.') . '</li>' .
'<li>' . __('Specify the correct writer of the book. Remember that the Author module refers to you, the author of this book review.') . '</li>' .
'</ul>' .
'<p>' . __('If you want to schedule the book review to be published in the future:') . '</p>' .
'<ul>' .
'<li>' . __('Under the Publish module, click on the Edit link next to Publish.') . '</li>' .
'<li>' . __('Change the date to the date to actual publish this article, then click on Ok.') . '</li>' .
'</ul>' .
'<p><strong>' . __('For more information:') . '</strong></p>' .
'<p>' . __('<a href="http://codex.wordpress.org/Posts_Edit_SubPanel" target="_blank">Edit Posts Documentation</a>') . '</p>' .
'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' ;
} elseif ( 'edit-book' == $screen->id ) {
$contextual_help =
'<p>' . __('This is the help screen displaying the table of books blah blah blah.') . '</p>' ;
}
return $contextual_help;
}

?>

About the Agapetry forum

Currently Online:

17 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1248

Posts: 5657

Members:

There are 1260 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin