I am spending so much time to shoo away the bloat on my small WordPress theme, and unregistering (wp_deregister_script) plug ins that do not need to be incorporated is really a priority.

I have got a comment editing script that require simply be incorporated sometimes (but always for drenched in customers -- just me)

My first attempt (within the header):

  if (!is_user_logged_in() AND !comments_open()) {

This is sufficient, however the script still remains incorporated unnecessarily for customers who're rapidly going to a webpage or publish and also have absolutely nothing to edit.

I possibly could make use of your brain energy...

The customer comment the weather is:

  • Just posted a comment (the page will refresh)
  • The customer left comment, sailed away and came back towards the page to edit

I am getting rid of time conditions: as lengthy because the comment is unmoderated it may be edited (rapidly made by hiding the edit link if comment approved).

I believed...

It is possible to method to test for comment submission page refresh (referrer -- or otherwise confident that any Publish data causes it to be to the page)?

It is possible to magic formula to check if any comments around the page/publish are waiting for moderation.

Each of individuals cooperating would most likely be great enough.


In my opinion I have crafted a strategy to devote the header.php

$comments_count = wp_count_comments($post->ID);
if (!is_user_logged_in() AND ($post->comment_status == 'closed' OR $comments_count->moderated == 0)) {
  // if the visitor isn't logged in, and the comments are closed or there are no comments in moderation:

This will certainly work nicely enough, as long as I always keep the amount of comments moderately low (every moderated comments for your particular publish or page means all site visitors can get the scripts incorporated, not only the commenter).

Relevant: http://codex.wordpress.org/Function_Reference/wp_count_comments