Opened 9 years ago
Last modified 5 years ago
#32545 reopened enhancement
Adding actions before and after "Add New" button
Reported by: | vivekbhusal | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.2.2 |
Component: | Posts, Post Types | Keywords: | 2nd-opinion |
Focuses: | administration, template | Cc: |
Description
We need a proper action to add new customs options (button, link, information) before and after the "Add New" button of post pages.
Such as http://stackoverflow.com/questions/29811433/wordpress-add-custom-button-on-post-type-list-page
on #wp-admin/edit.php line 281
on #wp-admin/edit-form-advanced.php line 395
This is just a addition of actions to make wordpress more customizable and modular.
Solution
We can use the following sample code to solve the problem.
/**
* Fires before the Add New button is added to screen.
*
* The before_add_new- hook fires in a number of contexts.
*
* The dynamic portion of the hook name, `$pagenow`, is a global variable
* referring to the filename of the current page, such as 'edit.php',
* 'post.php' etc. A complete hook for the latter would be
* 'before_add_new-post.php'.
*/
do_action('before_add_new-'.$pagenow);
if ( current_user_can( $post_type_object->cap->create_posts ) )
echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="add-new-h2">' . esc_html( $post_type_object->labels->add_new ) . '</a>';
/**
* Fires after the Add New button is added to screen.
*
* The after_add_new- hook fires in a number of contexts.
*
* The dynamic portion of the hook name, `$pagenow`, is a global variable
* referring to the filename of the current page, such as 'edit.php',
* 'post.php' etc. A complete hook for the latter would be
* 'before_add_new-post.php'.
*/
do_action('after_add_new-'.$pagenow);
Attachments (2)
Change History (12)
#1
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#2
@
9 years ago
Absolutely agree with you. Adding a hook in that location and assuming user to test the layout won't work. But there are other ways we can implement to make it more open to developers' and in the same time making sure that it doesn't affect the user experience of wordpress. I think it would be nice to explore other options.
#3
@
9 years ago
- Keywords 2nd-opinion added
- Resolution wontfix deleted
- Status changed from closed to reopened
#4
@
9 years ago
- Component changed from Administration to Posts, Post Types
- Milestone set to Awaiting Review
#5
@
8 years ago
I just had a need to add a button after "New" to a custom pots type. So I found this ticket. I am building sort of a web application by white labeling WP and using custom post types with Pods.
I understand and agree on the point about responsiveness, but I think this would be good to have.
#6
@
7 years ago
Actually I used javascript to add a button like that patch do but is not a cool hack.
This ticket was mentioned in Slack in #core by jeremyescott. View the logs.
7 years ago
#8
@
7 years ago
I was just about to write a patch for this very feature.
This is something I've found myself wanting a couple of times for my WP-based applications. The ability to add behaviors up there, eg: Sync with External Data, etc, is something that may be more and more and common as WP becomes more of an app platform. Asking users to find a tools or settings screen to press a button is a pain.
Yes, Javascript injection will continue to work, but its not ideal and JS is harder to test around, plus we get screen flickers on slow loading connections. I know that it may cause issues with responsiveness, but that should be up to the developers to address if they're adding buttons.
+1
I'll volunteer to revise the patch if needed.
#9
@
7 years ago
+1
Maybe we could change the UI here to allow a dropdown with addition actions allow with a filter to acc them.
#10
@
5 years ago
I also agree with this request. Many times I've had to resort to using JS to move elements into the right spots at the top of the admin edit list pages because there isn't any appropriate hooks.
post.php (for editing single posts) has similar filters with edit_form_after_title and such. This seems like a natural extension of this.
I would rather not add hooks in this location - variable horizontal items do not scale well across different screen sizes and unless the implementer using such hooks takes special care to style everything, most elements will look quite bad. These are also hooks that would inherently be tied to the current look and layout, which I find to be difficult to maintain long term when things move around or styling changes.