0

first of all I'm really sorry if the title of the question doesn't explain everything. Anyways here's what I was looking for.

I'm creating a WordPress plugin with OOP concept. So, I've codes like this

class somePlugin {
 //constructor goes here
 public function is_it_safe() {
  if( true ) {
   return true;
  } else {
   return false;
  } 
 }
}

Please Note: the above code is just an example. So, it may not make any sense.

So, now what I want is to make sure the is_it_safe() function can easily be called within other themes or plugins without even knowing the class or creating an object of the class. Is it possible?

I want the is_it_safe() function to be used by others easily without even doing somePlugin::is_it_safe().

I'm not sure if it is possible or not. But if it is possible, if anyone can help, it would be heally helpful.

2
  • 2
    I didn't test it but try doing a trick. Create a file e.x. my-function.php and create a function e.x. myplugin_is_it_safe() which calls somePlugin::is_it_safe(). Then include that file to your main plugin file. Now when you activate your plugin, myplugin_is_it_safe() function should be available so as is_it_safe() method. I hope you know what I mean. And again, I didn't test it so I don't know if it does work Commented Oct 28, 2016 at 19:46
  • @SebastianKaczmarek Amazing I was also thinking trying the same thing.
    – iSaumya
    Commented Oct 28, 2016 at 20:16

1 Answer 1

1

No. You always have to refer to the instance of the class.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.