Notifications
Clear all

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

7 Posts
2 Users
2 Likes
786 Views
st7878
Posts: 111
Topic starter
(@aima-forum)
Estimable Member
Joined: 4 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: 1186
(@tutrix)
Noble Member
Joined: 4 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: 4 years ago

Estimable Member
Posts: 111

@tutrix no(((

 

Tutrix
Posts: 1186
(@tutrix)
Noble Member
Joined: 4 years ago

@aima-forum

yes 😀 😉 it works

https://www.screencast.com/t/qXBRjsZFW2qV

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

Estimable Member
Posts: 111

@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: 1186
(@tutrix)
Noble Member
Joined: 4 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: 4 years ago

Estimable Member
Posts: 111

@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 } );