[wp-trac] [WordPress Trac] #10544: Specify tags on new posts through the URL

WordPress Trac wp-trac at lists.automattic.com
Thu Dec 10 17:47:31 UTC 2009


#10544: Specify tags on new posts through the URL
-------------------------+--------------------------------------------------
 Reporter:  rvenable     |        Owner:          
     Type:  enhancement  |       Status:  reopened
 Priority:  low          |    Milestone:          
Component:  Plugins      |      Version:  2.8.1   
 Severity:  minor        |   Resolution:          
 Keywords:  2nd-opinion  |  
-------------------------+--------------------------------------------------
Changes (by rvenable):

  * status:  closed => reopened
  * resolution:  duplicate =>


Comment:

 Replying to [comment:4 Denis-de-Bernardy]:
 > #8223
 >
 > for an example of it being done in a plugin:
 >
 > http://plugins.trac.wordpress.org/browser/sem-admin-menu/trunk/

 This ticket is not for adding additional functionality to wordpress (as
 ticket #8223), but for simply allowing the functionality to be added by a
 plugin. Right now plugins cannot solve this.

 The plugin you mention, from what I can see from scanning the code,
 succeeds in adding a parent ID to a post via a $_GET param. It does this
 by simply editing the value of $post->post_parent, which works because the
 value of $post->post_parent is output as part of the edit menu.

 It is not so easy to add a tag to a new post via a $_GET param, and you
 cannot simply modify some values in the $post variable because they won't
 be displayed. The function post_tags_meta_box() displays all the tags for
 a given post. It displays any tags returned by the get_terms_to_edit()
 function.

 So, the only way to get tags to appear on the new post edit page is to go
 through the get_terms_to_edit() function. '''Unfortunately, that function
 bails out early when there is no post ID, making it impossible for a
 plugin to specify tags to be displayed for a new post.''' So in essence,
 the problem is that the function assumes that new posts have no tags,
 which is what I want to be fixed.

 Here is the function: (notice I marked where it bails out)

 {{{
 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
         $post_id = (int) $post_id;
         if ( !$post_id )
                 return false; // <------ BAILS OUT EARLY HERE

         $tags = wp_get_post_terms($post_id, $taxonomy, array());

         if ( !$tags )
                 return false;

         if ( is_wp_error($tags) )
                 return $tags;

         foreach ( $tags as $tag )
                 $tag_names[] = $tag->name;
         $tags_to_edit = join( ',', $tag_names );
         $tags_to_edit = esc_attr( $tags_to_edit );
         $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit,
 $taxonomy ); // <-------- THE FILTER I NEED TO HOOK ONTO TO ADD MY NEW TAG

         return $tags_to_edit;
 }

 }}}

 A fix would either remove the early bail out or add a filter that I can
 hook onto when it bails out:

 {{{
 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
         $post_id = (int) $post_id;
         if ( !$post_id )
                 return apply_filters('get_terms_to_edit_new_post', false,
 $taxonomy);
 ...
 }

 }}}


 Pretty simple fix, I think.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10544#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list