[wp-hackers] Universal Edit Button

Stephen Rider wp-hackers at striderweb.com
Fri Jun 20 03:37:00 GMT 2008


You should wrap it in a conditional -- the link only makes sense on  
single posts or pages.  Thus:

function ueb_add_head_link() {
     if( is_single() || is_page() ) {
         global $post;
         switch ($post->post_type) {
                case 'attachment':
                        return;
                case 'page':
                        if( !current_user_can( 'edit_page', $post- 
 >ID ) ) return;
                        break;
                case 'post':
                default:
                        if ( !current_user_can( 'edit_post', $post- 
 >ID ) ) return;
                        break;
         }

         echo '<link rel="alternate" type="application/x-wiki"  
title="Edit this page" href="' . get_edit_post_link($post->ID) . "\" /> 
\n";
     }
}

On Jun 19, 2008, at 7:09 PM, Alan J Castonguay wrote:

> Took longer to convince TextMate to talk to the remote network share  
> that WP live on, than it did to type
>
> <?php
> /*
> Plugin Name: Universal Edit Button
> Plugin URI: http://universaleditbutton.org/
> Description: The Universal Edit Button is currently a green pencil  
> icon in the URL bar that indicates a web page is editable.
> Version: 1.0
> Author: Alan J Castonguay
> Author URI: http://verselogic.net/
> */
>
> function ueb_add_head_link() {
>        global $post;
>        switch ($post->post_type) {
>                case 'attachment':
>                        return;
>                case 'page':
>                        if( !current_user_can( 'edit_page', $post- 
> >ID ) ) return;
>                        break;
>                case 'post':
>                default:
>                        if ( !current_user_can( 'edit_post', $post- 
> >ID ) ) return;
>                        break;
>        }
>
>        echo '<link rel="alternate" type="application/x-wiki"  
> title="Edit this page" href="' . get_edit_post_link($post->ID) .  
> "\" />\n";
> }
>
> add_action( 'wp_head', 'ueb_add_head_link' );
> ?>
>
> Would have used edit_post_link() directly, except for the "<a"  
> sitting in it's output. str_replace, or the above.



More information about the wp-hackers mailing list