Notifications
Clear all

Limited Support

Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed.
We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.

 

Script [Solved] Admin message on forum front page + PHP

7 Posts
2 Users
2 Reactions
1,458 Views
st7878
Posts: 115
Topic starter
(@aima-forum)
Estimable Member
Joined: 5 years ago

I want to write in a message for forum guests: "XXX users are registered. Become XXX+1". Number of users, I want to call php function. How can I add a php script to the field on the screen?

 

6 Replies
Tutrix
Posts: 1522
(@tutrix)
Noble Member
Joined: 5 years ago

@aima-forum

you can use this code

add_action( 'wp_head', function () { ?>
<script>
$(document).ready(function() {	
$('#wpforo #wpforo-wrap .wpforo-admin-note').prepend($('<div class="usercount"> <?php $stat = WPF()->statistic(); ?> <?php echo $stat['members']; ?> users are registered. Become <?php echo $stat['members']; ?> + 1</div>'));
});
</script>
<?php } );

either via the Code Snippets plugin
or in the functions.php of your WP theme

you also have to add text to the admin note, to make it active

1 Reply
st7878
(@aima-forum)
Joined: 5 years ago

Estimable Member
Posts: 115

@tutrix no(((

 

Tutrix
Posts: 1522
(@tutrix)
Noble Member
Joined: 5 years ago
1 Reply
st7878
(@aima-forum)
Joined: 5 years ago

Estimable Member
Posts: 115

@tutrix Hmmmm 🙄 

in the page code - there is a script. but no text is displayed on the page. and further. in my case I need: "153 users are registered. Become 154" (not 153+1)

and after the main text, not before

 
 
PS: I won! it worked like this "jQuery (document) .ready (function ($)"
 
PPS: please help more:
1) below the text, not above the text
2) not 153+1, but 154
Tutrix
Posts: 1522
(@tutrix)
Noble Member
Joined: 5 years ago

@aima-forum

I don't know where the problem is on your side
for me the code works without any problem

use the plugin if it doesn't work for you via functions.php

you asked for a way to add php to the admin note

the php code above is just an example, you can use your own

1 Reply
st7878
(@aima-forum)
Joined: 5 years ago

Estimable Member
Posts: 115

@tutrix Thanks you! You showed me the way, and I finished it. 👍 👍 👍

Spoiler
This is what I need
add_action( 'wp_head', function () { ?>
<script>
jQuery(document).ready(function($) {	
$('#wpforo #wpforo-wrap .wpforo-admin-note').append($('<div class="usercount"> На форуме зарегистрированы <?php $stat = WPF()->statistic(); ?> <?php echo $stat['members']; ?> пользователей. Стань <?php echo $stat['members']+1; ?>!</div>'));
});
</script>
<?php } );