Forums

Template php code for calling class within template (2 posts)

  1. samueleast
    Member
    Posted 1 year ago #

    Hi all

    I have just developed a wordpress plugin and it is all strutured within a class called isimpledesign_feeds_class() so everything works fine and i am calling a function out from the class using.

    <?php $isimpledesign = new isimpledesign_feeds_class(); $isimpledesign->isimpledesign_feeds(); ?>

    i was just wondering if their is a problem calling it like this because from previous plugins i have always used

    <?php if (function_exists('isimpledesign_feeds')) { isimpledesign_feeds(); } ?>

    to call a function in the theme files.

    Just wondering if anyone has any suggestions???

    Thanks

  2. David Gwyer
    Member
    Posted 1 year ago #

    You could use the PHP function class_exists() to check for a particular class existence:

    http://php.net/manual/en/function.class-exists.php

    Or, for a particular method of an existing class you can use the PHP function method_exists() to check if a class function (method) exists:

    http://www.php.net/manual/en/function.method-exists.php

    So, your code would become something like:

    <?php
      if ( method_exists($isimpledesign, 'isimpledesign_feeds') ) { $isimpledesign->isimpledesign_feeds(); }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic