#49740 closed defect (bug) (invalid)
Hooking to page_attributes_dropdown_pages_args filter adds a dropdown to the Page Attributes metabox
Reported by: | nfmohit | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.4 |
Component: | Editor | Keywords: | has-screenshots needs-testing |
Focuses: | Cc: |
Description
Hi team!
I hope you're all doing well in these challenging times.
WordPress: 5.4-RC2-47447
Classic Editor: 1.5
This only happens with the classic editor. I'm seeing an unusual behaviour with page_attributes_dropdown_pages_args
hook. Basically, I'm using it to limit the depth of a hierarchical post type's to 1 using the following code:
<?php function set_bp_custom_menu_depth( $a ) { global $post; if( $post->post_type == 'bp_custom_menu_page' ) { $a['depth'] = 1; return $a; } } add_action( 'page_attributes_dropdown_pages_args', 'set_bp_custom_menu_depth' );
But whenever I use that hook, it adds a dropdown to the "Page Attributes" metabox in the page edit screens. Here's a screencast for reference. It also removes the "(no parent)" option from the "Parent" dropdown. Here's a screencast for reference.
This also happens even if you just hook an empty function to it, for example:
<?php add_filter( 'page_attributes_dropdown_pages_args', function() {} );
I want to confirm if this is expected behaviour or a bug. Please advise.
Kind regards,
Nahid
Change History (3)
#1
follow-up:
↓ 2
@
5 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#2
in reply to:
↑ 1
@
5 years ago
Replying to 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 ofadd_filter
, and b) you're missing a return statement in your callback(s). This combined causes the default arguments to be passed towp_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 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
@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 ofadd_filter
, and b) you're missing a return statement in your callback(s). This combined causes the default arguments to be passed towp_dropdown_pages()
which causes it to be unexpectedly output instead of assigned to a variable and used later.