Category Archives: Plugin

Add Admin Menu

Note the parameters types of function add_options_page:

//Initialize admin panel
if(!function_exists(‘WikirexLatestNews_ap’)){
function WikirexLatestNews_ap(){
global $wr_latest_news;
if(!isset($wr_latest_news)){
return;
}
//echo var_dump(function_exists(‘add_options_page’));
//exit();
if(function_exists(‘add_options_page’)){
//add_options_page(‘wikirex Latest News Box’, ‘Latest News Box’, 9, basename(__FILE__), array(&$wr_latest_news, ‘print_admin_page’));
add_options_page(‘wikirex Latest News Box’, ‘Latest News Box’, ‘manage_options’, basename(__FILE__), array(&$wr_latest_news, ‘print_admin_page’));
}
}
}
//WikirexLatestNews_ap();
add_action(‘admin_menu’, ‘WikirexLatestNews_ap’);

Pass Variable from PHP to Javascript

wp_enqueue_script('my-script','/path/to/whatever.js',…);

$params = array(
‘foo’ => ‘bar’,
‘setting’ => 123,
);

wp_localize_script( 'my-script''MyScriptParams'$params );

Output Example:

<script type=’text/javascript’>
/* <![CDATA[ */
var data = “[{\”title\”:\”Demo Title 1\”,\”content\”:\”Demo Content 1\”},{\”title\”:\”Demo Title 2\”,\”content\”:\”Demo Content 2\”}]”;
/* ]]> */
</script>