AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

Filter by custom fields

Topic prefix

AI Assistant
Notifications
Clear all

[Solved] Admin message on forum front page + PHP

7 Posts
2 Users
2 Reactions
1,752 Views
st7878
Posts: 115
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@aima-forum)
Estimable Member
Joined: 6 years ago
[#16283]

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?

 

1

6 Replies
Tutrix
Posts: 1519
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@tutrix)
Noble Member
Joined: 6 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: 6 years ago

Estimable Member
Posts: 115
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@tutrix no(((

 

add code
 result

Tutrix
Posts: 1519
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@tutrix)
Noble Member
Joined: 6 years ago
1 Reply
st7878
(@aima-forum)
Joined: 6 years ago

Estimable Member
Posts: 115
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@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

Desktop screenshot
 
 
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: 1519
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@tutrix)
Noble Member
Joined: 6 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: 6 years ago

Estimable Member
Posts: 115
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

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

 


Share: