Skip to content

WPGet – a question to all users

I’m working on the new inline Ajaxified comments thing in the next WPGet release (where you click the comments link, and theoretically a little box will pop up and show you the latest comments on that post). I have a question to ask as to how best achieve a solution to a problem I’m facing. If you don’t want to delve into the technical reasons behind this, skip a couple of paragraphs and rejoin. I really do need the users input here as to what the best way of fixing it is, so please please please tell me what I should do.

I’ve run into an interesting problem. In order to do this cool Ajax stuff, I need to pass some special information in the URL so that WPGet springs into action and delivers the Ajax content you requested (pulling out comments out for each and every post would be far too database intensive).

However, WPGet is included by another page, which means that the user doesn’t access the wpget.php file directly, all of that is be handled by the master script. That makes it a pain to get that special information passed in the URL, as I can’t control the master script invoking WPGet and change how it works.

Basically, if I cut the technical drivel, which of these solutions to this problem is better?

  1. At install time, you have to paste two bits of PHP into your file – one snippet of code at the top to handle Ajax stuff (this is the new bit) and one where you want the posts to appear as normal. This would only affect people wanting the Ajax functionality.
  2. Only one snippet to copy and paste, but we ask the users at install time which directory wpget.php will be located relative to the script calling it (index.php for example). In most cases, it’s the current directory (index.php and wpget.php in the same folder), so novices will leave it at that and there’s no problem. For people wanting to put it in /includes or whatever, they would have to remember to state this during the setup process.

    Technical talk – in this solution, when Ajaxing, we’d request the wpget.php script directly in the URL, along with our arguments, so therefore we need to know where it is relative to $_SERVER[‘PHP_SELF’]

Now, there’s clearly arguments for and against both and I don’t want to complicate the installation process too much. These measures probably won’t affect users not wanting the Ajax comments functionality, but I really want to keep installation simple.

I am relying on you to tell me which solution is best, as I’m not really sure. Particularly Lee, as you suggested this feature, what do you think is best?

Alternatively, I’m if (likely) being incredibly stupid, someone please tell me how to get the current file’s web-accessible filename from within PHP (not the filename of the file that calls wpget.php, but the wpget.php file itself).

Like this post?

If you would like to support the time and effort I have put into my tutorials and writing, please consider making a donation.


  1. Huw wrote:

    I think you should do the second option. The more down and dirty code insertion you make people do, the more likely they are to mess it up (I’m obviously talking from personal experience!)

    Sounds like a cool feature!

    Wednesday, January 10, 2007 at 18:26 | Permalink |
  2. Lee wrote:

    I agree with Huw, and would say the second option would be best, and in regard to novices installing and needing to know what to put in the path box, here is something (probably needs a but of modifying, and I think is only php5 compatible):

    //File to find
    //Most Portions of open dir takin form example
    while (false !== ($folder = readdir($handle))) {
    if ($folder != “.” && $folder != “..”) {
    $folders=array_merge((array)$folders, (array)$folder);

    Maybe you could do something along the lines of that so that novices could choose an option to “search” (well, not really search) for wpget, and that returns the directories it has found it in as an array, although only goes one directory deep. It needs a bit of cleaning up, and may be totally the wrong idea, if so, please ignore my babbling. Although you may be able to use it along with $_SERVER[‘DOCUMENT_ROOT’]; to locate the file.
    Sorry for suggesting this idea if it’s a bit of a pain to do 🙂

    Lee 😀

    Just a note: Theres meant to be php code above, note sure how WP handles it, if it for some reason doesn’t show up and you want it just send me an email.

    Wednesday, January 10, 2007 at 19:15 | Permalink |
  3. Peter wrote:

    OK, thanks.

    Decision made. 🙂

    No, it’s not a pain to do – it’s just a case of picking a solution and implementing it and I couldn’t immediately choose which one to do.

    For completeness, here’s what I’ll do. If you’re planning to put wpget.php in a different folder to the current one, you’ll be asked to specify this folder (relative to the web-accessible root) at install time. This means that the Ajax features will run directly off the wpget.php script. wpget.php will be required to be web-accessible (not locked down and only include’able by PHP) as the browser calls it directly.

    Thanks for the code Lee. I’ll take a look at it when I’m looking at the config tool (it’s the last thing I do, because up until then things change). I’m sure I’ll find some solution.

    Wednesday, January 10, 2007 at 19:57 | Permalink |
  4. Boon wrote:

    Very cool, this is so awsome1!!!!

    Sunday, January 14, 2007 at 16:21 | Permalink |

Post a Comment

On some sites, you must be logged in to post a comment. This is not the case on this site.
Your email address is not made public or shared. Required fields are marked with *.

Posting a comment signifies you accept the privacy policy.
Please note — your comment will not appear straight away, as all comments are held for approval.