[wp-trac] [WordPress Trac] #49740: Hooking to page_attributes_dropdown_pages_args filter adds a dropdown to the Page Attributes metabox

WordPress Trac noreply at wordpress.org
Tue Mar 31 14:34:21 UTC 2020


#49740: Hooking to page_attributes_dropdown_pages_args filter adds a dropdown to
the Page Attributes metabox
-------------------------------------------+----------------------
 Reporter:  nfmohit                        |       Owner:  (none)
     Type:  defect (bug)                   |      Status:  closed
 Priority:  normal                         |   Milestone:
Component:  Editor                         |     Version:  5.4
 Severity:  normal                         |  Resolution:  invalid
 Keywords:  has-screenshots needs-testing  |     Focuses:
-------------------------------------------+----------------------

Comment (by nfmohit):

 Replying to [comment:1 johnbillion]:
 > @nfmohit This is more of a support question which you'll need to post on
 wordpress.org/support, but the problem seems to be that a) you're using
 `add_action` instead of `add_filter`, and b) you're missing a return
 statement in your callback(s). This combined causes the default arguments
 to be passed to `wp_dropdown_pages()` which causes it to be unexpectedly
 output instead of assigned to a variable and used later.

 Hi, @johnbillion !
 I hope you're doing well!

 Thank you so much for getting back to me!

 Ugh! I feel so silly for posting this here. I think personally, I came to
 a conclusion assuming it as a bug too soon. I'm very sorry about that.

 Thank you for pointing the issues out with the attached code. The
 `add_action` was actually a typo while I added the code there, it had the
 same effect when using `add_filter`, but the issue was that I wasn't
 returning a statement. I appear to have resolved the issue with the
 following code:

 {{{#!php
 <?php
 function set_bp_custom_menu_depth( $a ) {
         global $post;
         if( $post->post_type == 'bp_custom_menu_page' ) {
                 $a['depth'] = 1;
                 return $a;
         }
         return $a;
 }
 add_filter( 'page_attributes_dropdown_pages_args',
 'set_bp_custom_menu_depth' );
 }}}

 Again, thank you very much for your help and sincere apologies again for
 posting this in the wrong place.

 Kind regards,
 Nahid

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


More information about the wp-trac mailing list