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. Commented Sep 3, 2018 at 19:10

1 Answer 1


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(){
        echo "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'));
  • yesss......thats workng well...thanku soo muchh.... @John Dee
    – guest
    Commented Sep 4, 2018 at 16:44
  • No problem. Click the up arrow to accept so others know this has an answer.
    – John Dee
    Commented Sep 4, 2018 at 19:20

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.