MyBB Community Forums

Full Version: Newpoints in other templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone. I would like to first mention that I am new to MyBB, so please bare with me.

As the title suggests, I would like to know how to change the location of Newpoints variables ( {$newpoints_profile} and {$post['newpoints_postbit']} ) to show in {$profilefields} and {$post['user_details']} templates accordingly, instead of the normal member_profile and postbit/postbit_classic.

If anyone could help me figure it out, I would be grateful. Thank you!
waiting never help /
Bumping with the hope that someone can still help me out figuring the solution
I just realized I wrongly adressed the question. Sorry!

TL;DR: How can I show the value of NewPoints Currency inside other 'Member' and 'Postbit' templates? (The value that also auto-updates once users post, without the need of recounting the points manually through AdminCP)

*Note: I do have Template Conditionals installed in case this can be donr through Conditionals/Template PHP
If they don’t work in the other templates you’re trying them in, then it would need an additional plugin to define those variables. The variables are defined in a hook and if the hook isn’t placed to define the variable before outputting the template you want to display the value in, it won’t exist.
(2023-01-30, 12:10 AM)Matt Wrote: [ -> ]If they don’t work in the other templates you’re trying them in, then it would need an additional plugin to define those variables. The variables are defined in a hook and if the hook isn’t placed to define the variable before outputting the template you want to display the value in, it won’t exist.

Thank you Matt for clarifying what I have to do. Would you, by any chance, know the hooks to allow these variables to be used in "postbit_author_user" and "member_customfields" templates?
Going to be awkward to have it in postbit_author_user, you'd still need to use the postbit hooks as it does now, but you'd need to do a str_replace on a string in the postbit_author_user template.

So in postbit_author_user you'd need to add something like:

<!-- NEWPOINTS_POSTBIT -->

And then in these same hooks:

$plugins->add_hook('postbit', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_prev', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_pm', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_announcement', 'newpoints_postbit', 50); // set priority to 50

with a lower priority so it runs after, have another function that does:

$post['user_details'] = str_replace('<!-- NEWPOINTS_POSTBIT -->', $post['newpoints_postbit'], $post['user_details']);

This is because postbit_author_user has already been rendered by the time you can hook in.

For the profile, you maybe just need to call the same function on member_profile_start instead of member_profile_end. So instead of:

$plugins->add_hook("member_profile_end", "newpoints_profile");

have:

$plugins->add_hook("member_profile_start", "newpoints_profile");
(2023-01-30, 12:02 PM)Matt Wrote: [ -> ]Going to be awkward to have it in postbit_author_user, you'd still need to use the postbit hooks as it does now, but you'd need to do a str_replace on a string in the postbit_author_user template.

So in postbit_author_user you'd need to add something like:

<!-- NEWPOINTS_POSTBIT -->

And then in these same hooks:

$plugins->add_hook('postbit', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_prev', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_pm', 'newpoints_postbit', 50); // set priority to 50
$plugins->add_hook('postbit_announcement', 'newpoints_postbit', 50); // set priority to 50

with a lower priority so it runs after, have another function that does:

$post['user_details'] = str_replace('<!-- NEWPOINTS_POSTBIT -->', $post['newpoints_postbit'], $post['user_details']);

This is because postbit_author_user has already been rendered by the time you can hook in.

For the profile, you maybe just need to call the same function on member_profile_start instead of member_profile_end. So instead of:

$plugins->add_hook("member_profile_end", "newpoints_profile");

have:

$plugins->add_hook("member_profile_start", "newpoints_profile");

Alright, after fiddling around in the PHP hook file trying to get the postbit part to work (I couldn't manage to get it to work at all, but the member part did work), I thought about using the variables found in the hook file that defines the currency for both profile and postbit ($profile['newpoints'] and &post['newpoints']) to see what would happen. To my surprise, the points now show up in the templates I used these 2 and the way I want them to show up, however I found myself against another small issue, because they do not update once a user post without the need of recounting all the points through AdminCP all the time.

Any idea how I could get them to update without the need of using AdminCP -> Newpoints -> Maintenance -> Recount every single time?
I don't know what the values actually are or how they're generated, if they're a cached value then it would need some other process to run to recount them, it's not something you'd handle in a template.