WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP-OpenID] How do I make it load only when needed? (7 posts)

  1. Pinoy.ca
    Member
    Posted 5 years ago #

    WP-OpenID, at least in my site, uses 2 megabytes of memory. That is probably reasonable.

    It also needs the browser to load four javascript files to work: jquery.js, jquery.textnode.js, jquery.xpath.js and openid.js That is probably reasonable, too.

    What is unreasonable is that it uses 2 megabytes of memory AND browsers have to load four javascript files on every single blog page.

    WP-OpenID is loading all its authentication machinery when my visitor is reading my archives. WP-OpenID is loading all its admin-screens machinery when my visitor runs a search in my blog. Meanwhile, the four javascript files are adding several seconds to page load times.

    I tried to reclaim memory by coating the core.php file with the conditional

    if (is_single() || is_admin() || stripos($_SERVER['PHP_SELF'],'wp-login.php') > 0) {
        // all of core.php
    }

    However this quick hack doesn't work. Would you please tell me what if condition to use?

    Thank you.

  2. Pinoy.ca
    Member
    Posted 5 years ago #

    Can anyone help me with this? Why are is_single() and is_admin() giving the wrong result?

  3. Will Norris
    Member
    Posted 5 years ago #

    if you are comfortable with using subversion, I'd recommend taking a look at my latest blog post about wp-openid. I believe a lot of the changes I made cleaned up the loading code. If it looks like it is still loading unnecessarily, please file a bug in the DiSo issue tracker if it's not already there.

  4. Pinoy.ca
    Member
    Posted 5 years ago #

    I read your post, and thanks for the info that wp-openid reinvents wp-comments-post.php but is terrible at it. I appreciate all your work on this plugin.

    Can you answer my question though? Why are is_single() and is_admin() giving the wrong result? I just want to quickly exclude the plugin on pages that don't need it.

  5. Will Norris
    Member
    Posted 5 years ago #

    plugins get loaded very early on in the process. At the time of loading the plugin, wordpress doesn't know if the page is single or not. The correct solution here would be to have the hook methods be very lightweight and only load up the openid object if necessary. I'm all about better performance, so I'll see what I can do in that regard.

  6. Pinoy.ca
    Member
    Posted 5 years ago #

    You're right. I glanced at some plugins I used to use, and their authors basically used this structure:

    class MonstrousClass {
      require_once('MonstrousLibraryOfFunctionsMyPluginsUse.php');
      require_once('SecondMonstrousLibraryOfUsefulGadgets.php');
      require_once('AnotherMonstrousClass.php');
      $data = new HugeClassOfSorts();
      function doohickey() {
        /* do something with $data */
      }
      add_action('inconsequential_hook','doohickey');
      /* ... */
    }
    $plugmein = new MonstrousClass();

    These authors don't realize that few of us run our own servers. I hope they don't see themselves proud they use object-oriented PHP and "encapsulation."

    Nowadays when I shop for plugins I sort them by filesize first.

    Best Regards,

  7. Pinoy.ca
    Member
    Posted 5 years ago #

    Bump.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags