Hi,
Show me your code and write what you want to make your site?
I’ll try to change your code so that it works for you.
Best regards, Alex
Hi!
I do have the same problem, so I allow myself to post my code here, instead of creating another topic with the same issue. If needed, I still can create a new topic!
$default_ip = '0.0.0.0';
$current_ip = $default_ip;
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
if (array_key_exists($key, $_SERVER) === true)
foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip)
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
$current_ip = $ip;
$server_id = '30103';
if ($current_ip !== $default_ip)
{
$is_valid_vote = file_get_contents('https://www.serveurs-minecraft.org/api/is_valid_vote.php?id='.$server_id.'&ip='.$current_ip.'&duration=1440');
if ($is_valid_vote == 0)
echo "<a href='https://www.serveurs-minecraft.org/vote.php?id=".$server_id."' target='_blank'><img src='http://arkhium.fr/wp-content/uploads/2018/07/voter.png' style='display: block; margin-left: auto; margin-right: auto;'></a>";
}
This works perfectly when using this: [wbcr_php_snippet id="303"]
When I try to use the Run Everywhere option, it doesn’t show anything, not even an error message.
Thank you in advance!
-
This reply was modified 7 years, 8 months ago by
fanfrelesque.
@fanfrelesque
Hi,
Do you want to run this code on every page and on every post of your website?
Then try running this code everywhere:
// returns the content of $GLOBALS['post']
// if the page is called 'debug'
function wbcr_my_the_content_filter($content) {
$default_ip = '0.0.0.0';
$current_ip = $default_ip;
foreach(array(
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
) as $key) {
if( array_key_exists($key, $_SERVER) === true ) {
foreach(array_map('trim', explode(',', $_SERVER[$key])) as $ip)
if( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) {
$current_ip = $ip;
}
}
}
$server_id = '30103';
if( $current_ip !== $default_ip ) {
$is_valid_vote = file_get_contents('https://www.serveurs-minecraft.org/api/is_valid_vote.php?id=' . $server_id . '&ip=' . $current_ip . '&duration=1440');
if( $is_valid_vote == 0 ) {
$content .= "<a href='https://www.serveurs-minecraft.org/vote.php?id=" . $server_id . "' target='_blank'><img src='http://arkhium.fr/wp-content/uploads/2018/07/voter.png' style='display: block; margin-left: auto; margin-right: auto;'></a>";
}
}
// otherwise returns the database content
return $content;
}
add_filter( 'the_content', 'wbcr_my_the_content_filter' );
Best regards, Alex
Hi Alex,
This works perfectly, thank you very much for your help!
However, I want it only on pages. I searched a bit, and found that i had to use is_page(). So now it works!
Regards,
Fanfrelesque.