Archive for wordpress

notes on admin comment reply

OK, I think I’ve got a cut for the next release of Lorelle’s requested plugin. However, I have not had a chance to test this outside of my own system (where it seems to work fine), and so I would love to have any volunteers help check this out on different installations for anything I’ve overlooked.

The basic mechanics are as follows: I coded up a new link “Reply To” for each post, which you all saw in the last cut. In that one the link goes to the post page’s comment reply section, which at least cut out the intervening pages. At one point I realized the Reply To doesn’t need to be added for comments not yet approved (!) so I cleaned that up (see example).

Anyway, now the Reply To link (see example) opens up a small box with a submit button under the comment using javascript (see example). I added code to the edit-comment.php that now handles a submit query. Each “Reply To” opens up its own box/submit button for the owner’s (see example). On submission, it refreshes, staying on this comment management page (see example). Sorry, no ajaxy goodness at this step, perhaps at the next step if I can figure out how to hook into something similar as to what the approve/unapprove links are doing.

There are a few annoying points left, which I’m not entirely sure how addressable they are. For example, once you approve a post, you’ll need to refresh the page to get its Reply To link, since that part of the code is not hooked into the ajax that WP is using to do this. Ideally I’d like to tap into that, I’ll have to poke around some more. I also have a feeling I should be utilizing the Nonce security model as well.

If you’d like to test this out, please comment! I’d feel better if it were tested out on a few more sites before I release it out in the wild…

del.icio.us:notes on admin comment reply  digg:notes on admin comment reply

Comments (6)

creating another plugin: reply to from admin panel

Lorelle at Wordpress blogged about a plugin (or WordPress feature) she wants: the ability to reply directly to a comment from the Admin comments page. When I spotted that, I thought I’d give it a go, because it seems like a short and sweet plugin to have. My first concept of the design is to add a Reply To link that sends you directly to the proper spot on the post page to put in the reply. This does not resolve the “backing up” problem to return to the original Admin page; I will address that in a second version. For now the problem can be worked around simply by opening the reply to link in a new tab and then closing that tab when returning to the admin page. Since all the major browsers now have tab functionality, this seems reasonable.

However, as I looked through Wordpress’ structure, I realised that the anchor, or name for the post comment section of a post is dependent on the name that the theme’s author gave it. In other words, we don’t always know what the name/id of the reply form (comment form) is for a post in a given theme. Mine is #postcomment; the popular ones seemed to be #respond or some variation of #postcomment (including a #postComment). So the first step I need to take is to guarantee that, if a comment is allowed for the post in question, a particular anchor name exists. We’ll use this snippet to do that:


function add_admin_comment_reply_anchor() {
     <a name="admin_comment_reply_anchor"></a>
}
add_action('comment_form', 'add_admin_comment_reply_anchor');

I played around directly with the wp-admin/edit-comments.php file and confirmed that this works (provided the above anchor name exists):


<a href="<?php echo get_permalink($comment->comment_post_ID); ?>#admin_comment_reply_anchor" title="<?php echo $post_title; ?>"><?php _e('Reply to Post') ?></a> 

I tested this by directly editing my edit-comments.php file. Do not do this at home! This is for professionals only! :-) . My point in doing this was to be sure this approach would even work. There’s roadblocks ahead, though: testing this segment is how I realized that the theme is an issue, needing the above anchor hook. At this point, I’d like to note that it would be easy for WordPress to implement this: all they would need to do is add the automatic anchor as I did, and modify the base edit-comments.php file as above. But since we don’t have that, I’ll proceed with how to do the desired tweaking.

At this point, I looked at two existing plugins: Paged Comment Editing and Commenter Spy. I looked at Paged Comment Editing first since it seemed to be the most similar plugin: a plugin that somehow reworked the edit-comments.php. I was especially hoping to discover a useful WordPress hook to add the Reply To link.

But the more I looked through this plugin the less I liked the overall approach. The problem with it is two fold. First of all it’s directly incompatible with any other plugins that might affect edit-comments.php because it basically takes out edit-comments.php, and regenerates it itself. Second, this approach makes it a potential problem if there’s ever a security patch or even just plain upgrade from WordPress involving this file: the plugin will continue to put out the old code preserved within it. I don’t mean to come off completely criticizing this plugin because it’s very clever with how it reaches in and reworks the file. But I decided I didn’t really want to do it this way.

So it was back to Commenter Spy. This one’s not without its pitfalls either, of course. Since it uses javascript to modify the page output on the fly I had originally rejected it because it won’t work if the user has disabled javascript. However, javascript is ubiquitous enough it seems reasonable to use especially given the alternatives above. The premise of this plugin is as follows: Scan through the DOM of the given page, and do a regular expression substitution in order to sneak in the desired new link. So I put together the following snippets:

Define the desired text (and then escape it; since I’m localizing the term, I have no idea what this might become, so I protect it by escaping the text first).


        $admincommenttext = __('View Post');
        $eadmincommenttext = str_replace('/', '\/', preg_quote($admincommenttext));

Plus, define the Reply To to add in:


        $admincommentreply = __('Reply to Post');
        $eadmincommentreply = str_replace('/', '\/', preg_quote($admincommentreply));

Now define the regular expression to search on:


        $ViewPostBaseURLEscaped = "(<a[ \\n\\r]*href=\"([^\"]*)\"([^>]*)>$eadmincommenttext<\/a>)";

With these pieces in place, I can now use the following snippet of javascript:


<script type="text/javascript">
//<![CDATA[

        var links;
        links = document.getElementsByTagName('p');
        for (var i = 0; i < links.length; i++) {
                var curr;
                curr = links[i];
                curr.innerHTML = curr.innerHTML.replace(/<?php echo $ViewPostBaseURLEscaped; ?>/, "$1 | <a  href=\"$2#admin_comment_reply_anchor\" $3><?php echo $eadmincommentreply; ?></a>");
        }

//]]>
</script>

Now, to wrap this all up and to make sure it gets added into the output HTML of the proper page (edit-comments.php), I put the above code into a function called adminCommentReplyModifyViewPostURLs and hooked it in as follows:


/* activate only on correct page */
if (basename($_SERVER['SCRIPT_FILENAME']) === 'edit-comments.php')
{
        add_action('admin_footer', 'adminCommentReplyModifyViewPostURLs');
}

In the next version of this plugin, I would like to change the Reply To link to open up an inline text area for the reply which then adds it in properly, without ever leaving the page. However, I need to dig in more deeply to see how comments are added, so I’ve left this for a future improvement. It would also mean not seeing the full content of the comment being replied to although presumably the admin of the site has already seen that in the email notification. (Perhaps a button to expand the excerpt to a full version and back?)

You might be wondering how do I do this, how do I know what filters to apply, where to look. The answer is really I don’t. I do know that I can add in actions and filters, and I peruse the WordPress Codex site’s list of hooks for anything that looks like it might do the trick. I also browse the various files in the themes and in the wp-admin directories: I actually found the the comment form hook in the theme’s comment.php file. I also look for plugins that do something similar to what I want to do, or at least knock about in the same general area. In this case, I found two, one of which gave me the bulk of my material.

Thank god for GPL ;-)

OK, at this point, I’m using it on my installation and it seems to work. It is, however still fairly rough. I’ve got the download page set up here.

del.icio.us:creating another plugin: reply to from admin panel  digg:creating another plugin: reply to from admin panel

Comments (25)

attention all WordPress 2.1.1 upgraders…

Better read this announcement immediately if you’ve updated to 2.1.1 within the last few days. It’s quite likely you need to go to 2.1.2 asap as the security on 2.1.1 was compromised.

This security hole does NOT apply to people still on 2.1 (but I imagine if you were planning to upgrade, you should go directly to 2.1.2…).

del.icio.us:attention all WordPress 2.1.1 upgraders...  digg:attention all WordPress 2.1.1 upgraders...

Comments

wordpress update 2.1.1

Those busy folks are at it again…just installed another update. This one apparently comes highly recommended with security fixes and the like. As usual, I used Mark on WordPress’s zipped diff file. No fuss, no muss…

del.icio.us:wordpress update 2.1.1  digg:wordpress update 2.1.1

Comments

yes, yet another wordpress upgrade

They’ve been working overtime…2.1 was released a couple of days ago and as usual, its best to update as soon as possible. One of the nice things about this upgrade is that it includes the latest Akismet. Which along with Bad Behavior (verified good for 2.1) will help cut your spam right out.

This is a major upgrade, so Mark on Wordpress didn’t create convenient diff files this time. Instead, follow the instructions over at wordpress: Upgrading Wordpress which are clear and straightforward.

All my plugins were fine with the upgrade, and while that of course won’t be true for ALL plugins, chances are you probably won’t have too much issue with that.

del.icio.us:yes, yet another wordpress upgrade  digg:yes, yet another wordpress upgrade

Comments (1)

« Previous entries Next Page » Next Page »

Bad Behavior has blocked 327 access attempts in the last 7 days.