0

I want to make only one call to external API in the 'my_widget' class here is an example:

class my_widget extends WP_Widget {

    public function __construct() {
        $args = array(
            'description' => "this is my widget"
        );
        parent::__construct( 'my_widget_id', 'make lists name', $args );
    }

and I have another class that working with external body

class externalApiHelper
{
    public function getNamesList()
    {
    //my code

      return $namesList;
    }
 }

I tried this option:

class my_widget extends WP_Widget {

    public function __construct() {
        $args = array(
            'description' => "this is my widget"
        );
        parent::__construct( 'my_widget_id', 'make lists name', $args );
        $external_api_helper = externalApiHelper ();
        $names_list          = $external_api_helper->getNamesList(); 

    }

but got an error:

Fatal error: Uncaught Error: Class 'externalApiHelper' not found

Despite the fact that the class is properly included and can be called from any other method in my_widget.

How do I call getNamesList()?

  • Are either of the files using namespaces? – Jacob Peattie Nov 5 at 11:42
  • No, but it works in every other method in the class. But every other method calls the function more than one time. – szz Nov 5 at 12:21

Your Answer

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

Browse other questions tagged or ask your own question.