How to access wordpress functions inside a new main plugin class.?

new_plugin_class is the classname of plugin.

I want to get access all wordpress functions inside new_plugin_class.

like doing require_once("..../.../.../wp_load.php"); for php pages.

is there any way to do it ??

  • 1
    wp in-built functions have global scope, so you can access them within your new_plugin_class class. – Eduardo Escobar Sep 3 '18 at 19:10

In WordPress, most of the functions won't get loaded until certain points in the event stack. In the Event Driven Architecture [EDA] of WordPress, you have to put your classes into actions or filters.

class MyGreatClass{

    public function __construct(){
        //I can use WP functions here

    public function myGreatMethod(){
        return "I don't do much, but the WP functions are available to me!";

//This line instantiates MyGreatClass and calls myGreatMethod during the "init" event.
add_action('init', array(new MyGreatClass, myGreatFunction'));
| improve this answer | |
  • yesss......thats workng well...thanku soo muchh.... @John Dee – guest Sep 4 '18 at 16:44
  • No problem. Click the up arrow to accept so others know this has an answer. – John Dee Sep 4 '18 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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