[wp-trac] [WordPress Trac] #32545: Adding actions before and after "Add New" button

WordPress Trac noreply at wordpress.org
Mon Jun 1 05:33:28 UTC 2015


#32545: Adding actions before and after "Add New" button
--------------------------------------+-----------------------------
 Reporter:  vivekbhusal               |      Owner:
     Type:  enhancement               |     Status:  new
 Priority:  normal                    |  Milestone:  Awaiting Review
Component:  Administration            |    Version:  4.2.2
 Severity:  normal                    |   Keywords:
  Focuses:  administration, template  |
--------------------------------------+-----------------------------
 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.

 Few use-case scenarios
 [[Image(screenshot1.png)]]
 [[Image(screenshot2.png)]]

 '''Solution'''
 We can use the following sample code to solve the problem.

 {{{#!php

 /**
  * 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);
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32545>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list