Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0 #18

Merged
merged 48 commits into from
Oct 24, 2017
Merged

v2.0 #18

merged 48 commits into from
Oct 24, 2017

Conversation

jjgrainger
Copy link
Owner

v2.0 contains a lot of changes, fixes and features. For those of you upgrading from v1.1.2 here are some of the key changes to consider.

The register method

When creating post types and taxonomies you will now need to register them to WordPress using the register() method. This method calls all WordPress hooks responsible for registering a custom post type to WordPress.

// Create a PostType object for books
$books = new PostType('books');

// Register the books post type to WordPress
$books->register();

Taxonomies

Taxonomies are now created with the Taxonomy class and has the same methods and properties as PostTypes, including columns.

// Create a Taxonomy object for genres
$genres = new Taxonomy('genre');

// Add the genre taxonomy to the books post type
$genres->posttype('book');

// Create a custom column for the taxonomy list table
$genres->columns()->add([
    'popularity' => __('Popularity')
]);

// Register the taxonomy to WordPress
$genres->register();

Translations

Previously, PostTypes used a variable to set the textdomain for translatable strings. Based on the WordPress documentation, this vairable has been removed and PostTypes no longer uses any gettext functions.

To translate strings when using PostTypes, you can use WordPress gettext functions when setting any names or labels.

$books = new PostType([
    'name'  => 'book',
    'singular' => __('Book', 'my-plugin'),
    'plural' => __('Books', 'my-plugin'),
    'slug' => 'book'
]);

$books->labels([
    'add_new' => __('Add New', 'my-plugin'),
    'add_new_item' => __('Add New Book', 'my-plugin'),
    'edit_item' => __('Edit Book', 'my-plugin'),
    'new_item' => __('New Book', 'my-plugin'),
    'view_item' => __('View Book', 'my-plugin'),
    'search_items' => __('Search Books', 'my-plugin'),
    'not_found' => __('No Books found', 'my-plugin'),
    'not_found_in_trash' => __('No Books found in Trash', 'my-plugin'),
    'parent_item_colon' => __('Parent Book:', 'my-plugin'),
]);

Changelog

@jjgrainger jjgrainger merged commit 9fa23e7 into master Oct 24, 2017
@jjgrainger jjgrainger deleted the rc-v2.0 branch October 25, 2017 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conflict with WooCommerce admin columns Customize taxonomy columns Add unit tests t10ns
1 participant