One time call to external API in widget
Question
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()?
0
api, plugin-development, plugins, widgets
4 years
2019-11-05T04:41:00-05:00
2019-11-05T04:41:00-05:00 0 Answers
69 views
0
Leave an answer