博文

目前显示的是 一月, 2017的博文

[WordPress Plugin] Translator with Baidu Service -- a good alternative to GTranslate to avoid GFW problem

If some of your WordPress site's users are in mainland China, you may need a plugin to translate your site into Chinese. One of the most popular translating plugin is GTranslate which is based on the Google translating service. But the problem is people in mainland China can not access Google. As a result, GTranslate cannot work in mainland China, only if using the VPN -- it's not quiet possible for a potential visitor to buy a VPN account.  Translator with Baidu Service is a similar plugin which is based on Baidu translating service. As Baidu is a big Chinese company, its translating service can be accessed from mainland China. Moreover, because Baidu deploys its servers all over the world,  people can use its services wherever they are.  Baidu translating service is very good at translating different languages into Chinese. Currently Translator with Baidu Service supports 25 languages: Chinese, English, Japanese, Korean, French, Spanish, Thai, Arabic, Russian, Portuguese, G

[PHP]Difference between require and include

require: 1.Upon failure it will also produce a fatal E_COMPILE_ERROR. 2.   require() will always read in the target file, even if the line it's on never executes. That means if require() is in 'if', no matter whether the condition is met, the file will be read. include: 1.Upon failure it will only emit a warn ing   E_WARNING. 2.Can conditionally include a file.

How to make a triangle with CSS

Some times we need to make a triangle after some elements in the page, for example, simulating a kind of dropdown menu. The triangle above is made by div and CSS. Here is the code: <div class="example-btn"> </div> <style> .example-btn{ background-color: transparent; height: 0px; width: 0px; padding: 0px; content: " "; border-width:25px 25px 0px 25px; border-color: #000000 transparent; border-style: solid; } </style> The code is very simple, I believe everyone knows CSS can read this code -- it is an empty div with 0 width and 0 height and borders. But how does this form an triangle? If we change the code above like this: <div class="example-btn"> </div> <style> .example-btn{ background-color: transparent; height: 0px; width: 0px; padding: 0px; content: " "; border-width:25px 25px 25px 25px; border-color: #000000; border-style: solid; } </style> We will get t

Using Ajax in WordPress

AJax stands for Asynchronous JavaScript and XML. In a nutshell, it is the use of the XMLHttpRequest object to communicate with server-side scripts.  When we write Word Press Plugins, Ajax is sometimes necessary for us if we need to grab some data from server in our javascript from the browser. Word Press provide admin-ajax.php in the wp-adim folder to help us dealing with Ajax request. There are two important hooks: 1. wp_ajax_nopriv_{$_REQUEST['action']} 2. wp_ajax_{$_REQUEST['action']} The first hook is for visitors (without any administrator logged in). The second one is for administrators. To deal an ajax request, we need to add some actions for the two hooks above. (assume that the action name is 'action-name') add_action('wp_ajax_nopriv_action-name', 'visitor_ajax_callback'); add_action('wp_ajax_action-name', 'admin_ajax_callback'); Then complete the callback functions. function visitor_ajax_callback () {

About the param of the admin_enqueue_scripts hook in WordPress

The typical code using admin_enqueue_scripts is add_action ( ' admin_enqueue_scripts ', ' enqueue_assets ' ) ; function enqueue_assets( $suffix ) {     wp_enqueue_style ( ' baidu-translator-admin ' ) ; }       The question is what the param suffix refer to? After adding a 'echo' sentence, I got the print. function enqueue_assets( $suffix ) {     echo $suffix;     wp_enqueue_style (  ' baidu-translator-admin '  ) ; }   The print is: settings_page_baidu-translator The id of the page added by add_option_page is 'baidu-translator'. So the param suffix refers to a screen id which consists of the id of parent page and current option page.

How to post an array for checkboxes from html

In most of the cases, we just need simple values to be posted to server. For example, <input type="checkbox" value="test1" name="checkboxtest"></input> After we check it and submit, we will receive the following structure: 'checkboxtest' => 'test1' But the problem is, if we add another checkbox with the same name: <input type="checkbox" value="test1" name="checkboxtest"></input> <input type="checkbox" value="test2" name="checkboxtest"></input> We can only receive 'checkboxtest' => 'test2'. 'test1' will be lost. How to save both test1 and test2 into an array? We can do it like this: <input type="checkbox" value="test1" name="checkboxtest[]"></input> <input type="checkbox" value="test2" name="checkboxtest[]"></input> The

Using Hierarchical Structure in POST or GET When Submit Form in HTML

First, let's see a simple example: File1: post.html <!DOCTYPE html> < html >      < head >      </ head >      < body >      < form   action = "post.php"   method = "get" >                                                                                                                                                       < input   type = "text"   name = "word"   value = ""  />            < input   type = "submit"   value = "submit"  />      </ form >      </ body > </ html > File2: post.php <?php var_dump ( $ _POST ) ; var_dump ( $ _GET ) ;    When we visit post.html and input 'a' in the input box, then submit. We get the following prints: /Library/WebServer/Documents/test/post.php:2: array (size=0) empty /Library/WebServer/Documents/test/post.php:3: array (size=2) 'word' =>

The params of add options page -- explain in detail

图片
add_options_page(  string   $page_title ,   string   $menu_title ,   string   $capability ,  string   $menu_slug ,   callable   $function  =  ''  ) Parameters  # Parameters $page_title ( string )   (Required)   The text to be displayed in the title tags of the page when the menu is selected. It will be displayed in the position 1. $menu_title ( string )   (Required)   The text to be used for the menu.    It will be displayed in the position 2. $capability ( string )   (Required)   The capability required for this menu to be displayed to the user. This confused me because I don't know what capabilities I can choose until I found this page:  List of possible capabilities are here .  $menu_slug ( string )   (Required)   The slug name to refer to this menu by (should be unique for this menu). This will be used in the url. For example: http://127.0.0.1/html2/wp-admin/options-general.php?page=baidu-translator. 'baidu-translator' is a menu_slug.