stephenharris / WordPress-Post-Type-Archive-Links

Adds a metabox on Appearance > Menus to create menu items pointing to post type archives
55 stars 25 forks source link

Version 1.3? #25

Closed gmazzap closed 9 years ago

gmazzap commented 10 years ago

In last 2 days I worked on the code of this plugin. My work covered 3 aspects:

  1. code approach (better explained below)
  2. new features
  3. business logic
  4. readmes update

I ended up to create a candidate V1.3, but before sending a PR, I want to discuss what I've done.

Code approach

Regarding first point main modification is on plugin boot up: instead of using a static init method, the class instantiation happen inside the add_action call: add_action( 'plugins_loaded', array( new Post_Type_Archive_Links, 'init' ) ); so init method is not static but dynamic. After that, all the hooks are moved from constructor to a method enable. This method pairs with another one disable that roll back it: remove hooks and text domain. To call disable we need the class instance, that can be retrieved using a filter hook: "post_type_archive_links". All this changes are in comit 792c959.

The other are minor changes:

Currently the CPTs to be shown in the metabox are retrieved using '_builtin' => false and 'has_archive' => false, however when a CPT is registered with true 'has_archive' but false 'publicly_queryable' it is shown in the metabox, but I think they should not be added. Moreover, I think CPTs registered with 'show_in_nav_menus' set to false (even if core refers to single items), should also be removed from metabox. My code reflects these thoughts, and add a filter "show_{$cpt_slug}_archive_in_nav_menus" to force a CPT being added even if 'publicly_queryable' and/or 'show_in_nav_menus' are set to false (but not if 'has_archive' is false). My code also moves the CPTs retrieval from metabox method to a separate get_cpts method that runs just before metabox (same hook higher priority): this allow to easily show "No items." and avoid js addition if there are no CPTs.

Readmes update

I've updated:

Code explain better than thousands of words (I hope), the full release compare is here