Custom Plugin Undefined Function Error

I am building another plugin to add Disqus Commenting system to Zenphoto.

I have the plugin working but whenever I call it I get the php "undefined function" error.

The plugin is setup like:

class disqus_comment_form {

//options function

function printDisqusCommentForm {
//print stuff
}

}

I have tested that the class exists on the page with:

if (class_exists('disqus_comment_form')){//test}

But it still can't find the function unless I use:

$disqus = new disqus_comment_form();

$disqus->printDisqusCommentForm();

All of the other example plugins I have been looking through don't have to do this but I can't figure out what I have done differently.

I've probably missed something very simple but any help would be greatly appreciated.

Comments

  • acrylian Administrator, Developer
    `
    $disqus = new disqus_comment_form();
    $disqus->printDisqusCommentForm();
    `
    Yes, as you cannot use a class method directly. This is how object orientation works and how you setup it. However you class is missing a constructor. Otherwise you can make the method static if it is standalone having no other depencencies to call it without creating an object first.

    Our official comment_form plugin is based on a class as well but it also additionally has the plain function `printCommentForm()` that directly can be used on themes.
  • acrylian Administrator, Developer
    FYI, our team member gjr once had made disqus plugin we have rediscovered so we put it on our unsuppported repository: http://www.zenphoto.org/news/zpdisqus
    It may naturally not work anymore since it isn't maintained but maybe it does or could be a starting point for you.
  • I moved my function out of the class and got it to work as I wanted. I'm still pretty new to using classes etc. so I appreciate your help :)

    With my Disqus plugin I am hoping to use Single Sign On (SSO) so the user wont have to register for my site twice (once to use favorites etc. and the other to use Disqus comments).

    To do this I need to be able to get the current user's id, name and email and use it on any page that Disqus is active. What would be the best way to get this information?
  • Looking over the documentation you provided I'm guessing I need to use some combination of the class Zenphoto_Administrator and the functions getID(), getName() and getEmail() but I can't seem to get it right.
  • fretzl Administrator, Developer
    You can use the global (always available) variable `$_zp_current_admin_obj`
    (http://www.zenphoto.org/news/zenphotos-global-variables)

    `
    $_zp_current_admin_obj->getUser() // Login name
    $_zp_current_admin_obj->getID() // User ID (number)
    $_zp_current_admin_obj->getEmail() // Email
    `
  • acrylian Administrator, Developer
    I'm still pretty new to using classes etc. so I appreciate your help :)

    As you probably assume "teaching" the general PHP class stuff (unless you meant the ZP class stuff specifially) is a bit outside the scope of this forum but we try ;-)

    There is a federated logon plugin available for similar things. Never used it myself and we don't really maintain it although it is included I admit.
Sign In or Register to comment.