Reputation: 5449
I'm trying to call a method defined in a custom plugin from a custom template part.
In my plugin, I've defined a class, and initiate it via $users_activity = new OBJ_user_activity();
.
The following works while in main template (author.php
, page.php
) ...
$users_activity->get_currently_online_users_count();
... But doesn't work with a custom template part. Instead I'm getting a the following error:
Call to undefined variable $users_activity.
Would anyone know how to correctly call a method from a custom template part ?
Upvotes: 0
Views: 627
Reputation: 168
Get_template_part()
allows a 3rd parameter to pass in variables.
Based on your question:
get_template_part( 'templates/app', 'aside', array( 'users_activity' => $users_activity ) );
... and from the template part:
echo $args['users_activity']->get_currently_online_users_count();
Upvotes: 2