[wp-trac] [WordPress Trac] #39800: current_item_{parent|ancestor} Not set for Post Type Archive Items

WordPress Trac noreply at wordpress.org
Tue May 23 20:57:52 UTC 2017


#39800: current_item_{parent|ancestor} Not set for Post Type Archive Items
----------------------------------------+-----------------------------
 Reporter:  mrwweb                      |       Owner:
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Future Release
Component:  Menus                       |     Version:  4.7.2
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+-----------------------------

Comment (by mrwweb):

 Was rushing to get a patch and then saw this just got punted :( Maybe if
 we hurry it can still get in?

 @welcher I'm happy to redo this patch, but have a quick question I need an
 answer on first.

 > change the in_array method to use the strict parameter to avoid
 unexpected results.

 This was copied from elsewhere in that file that also doesn't use strict
 mode. Should it get added in both places even though the second instance
 is for custom links, not post type archives?

 > can you share more detailed instructions?

 I think this is maybe what you want? Here's a little testing plugin I was
 using. (Suffice it to say I don't know how to write unit tests!)

 {{{
 <?php
 /**
  * MU Plugin for Testing Ticket #39800
  * https://core.trac.wordpress.org/ticket/39800
  *
  * Setup:
  *
  * 1. Dump this code somewhere like an mu-plugin
  * 2. Create at least one Book post and one Page
  * 3. Create a menu with the following structures
  *
  *     - Page
  *                      - Page
  *                      - Post Type Archive
  *     - Page
  *              - Page
  *                      - Page
  *                      - Post Type Archive
  *
  * 4. View the menu/var_dump on the front end.
  *
  * Expected Results:
  *              - Without the patch: The current_item_parent and
 current_item_ancestor values for the parent/ancestor menu items should be
 incorrect when on the Post Type Archive page (compare to results on
 sibling Page's).
  *              - With the patch: current_item_parent and
 current_item_ancestor are correct.
  *
  */
 /* Register a custom post type with archive for testing */
 function _39800_register_a_cpt() {
         register_post_type( 'books', array( 'label' => 'Books', 'public'
 => true, 'has_archive'=> true ) );
 }
 add_action('init','_39800_register_a_cpt');

 /* var_dump current_item_parent and current_item_ancestor properties for
 each menu item to observe bug and patch results. */
 function _39800_dump_my_vars( $items, $args ) {

         $dump = array();
         foreach( $items as $item ) {

                 $dump[$item->title] =
 array('current_item_parent'=>$item->current_item_parent,'current_item_ancestor'=>$item->current_item_ancestor);

         }
         echo '<pre style="position:relative">'; var_dump($dump); echo
 '</pre>';

         return $items;

 }
 add_filter( 'wp_nav_menu_objects', '_39800_dump_my_vars', 10, 2 );
 }}}

 I've got a patch ready to go, just need an answer on whether to patch both
 instances of `in_array` or just the one relevant to this ticket?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39800#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list