功能显示错误

时间:2014-08-29 15:34:08

标签: php wordpress wordpress-plugin

您好我正在尝试使用某个功能,我收到此错误

Parse error: syntax error, unexpected 'function' (T_FUNCTION) on line 3

附上代码

<?php

add_action('admin_menu', 'zkr_my_theme_menu_first'); // we need this action to create     the menu
// this  makes the menu
function zkr_my_theme_menu_first()
{
$page_title = "Theme Settings";
$menu_title = "Theme Settings";
$capability = "administrator";
$menu_slug = "zkr-theme-settings";
$function = "zkr_main_theme_menu";
$icon_url = get_template_directory_uri() . "/zkrframework/images/settings_icon.gif";

add_menu_page($page_title,$menu_title,$capability,$menu_slug, $function, $icon_url);

}
// this shows the menu html think of it as the view.
function zkr_main_theme_menu() 
{
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
if ( !user_can( $user_id, 'create_users' ) )
    return false;
?>

<div class="wrap">

<h2>Hello Menu</h2>

</div>

<?php
}

?>

我正在尝试向我的wordpress管理面板添加菜单,我收到此错误

如何修复此错误?

1 个答案:

答案 0 :(得分:0)

您在第3行调用函数addAction(),但您尚未在您提供的代码示例中声明它。

在声明函数之前调用函数是可以的,但是在调用未定义的函数时,解释器会以隐喻的'wtf'耸肩。