0

I have no experience in PHP but I found the following php-code for a wordpress-plugin that asks a user to say Yes or No when user clicks on the Publish-button in Wordpress.

The problem with the code below is that some characters are now shown correctly in the popup-box which appear. I think that the string-message somehow needs to be encoded with UTF8 and I really don't know how to do this or if it is even possible. This is the code:

<?php
/*
Plugin Name: Confirm publish
*/
$c_message = 'è un test?'; // your confirm message
function confirm_publish(){
    global $c_message;
    echo '
<script type="text/javascript"><!--
var publish = document.getElementById("publish");
if (publish !== null) publish.onclick = function(){
    return confirm("'.$c_message.'");
};
// --></script>';
}

add_action('admin_footer', 'confirm_publish');
?>

If it is possible, can someone please let me know what I need to look for or what I need to do with above code to make it work?

moster67
  • 830
  • 3
  • 12
  • 30

1 Answers1

1

You should make sure that the data you return to the HTML is displayed correctly by the browser. You can do this with the following meta-tag:

<meta charset="utf-8"> 

You need to put this as high as possible in the head-tag for everything to be displayed properly. It might even be better to put this above the title tag to avoid issues there.

When working with databases, also make sure that they are set up in utf-8. When doing that, no issues displaying any data whatsoever should occur.

vdwijngaert
  • 1,515
  • 11
  • 24