解析错误:语法错误,意外')'在第36行的/home/prayqxia/public_html/friendsofjesusnetwork.com/wp-content/themes/iamsocial/functions.php

时间:2015-11-20 19:40:02

标签: wordpress wordpress-plugin

我尝试将此代码插入我的wordpress网站,在我的主题fuction.php文件中。那是我开始遇到这个问题的时候。

/**
 * Checks if a particular user has a role.
 * Returns true if a match was found.
 *
 * @param string $role Role name.
 * @param int $user_id (Optional) The ID of a user. Defaults to the current user.
 * @return bool
 */
function appthemes_check_user_role( $role, $user_id = null ) {

    if ( is_numeric( $user_id ) )
    $user = get_userdata( $user_id );
    else
        $user = wp_get_current_user();

    if ( empty( $user ) )
    return false;

    return in_array( $role, (array) $user->roles );
}

1 个答案:

答案 0 :(得分:0)

试试这段代码:

function appthemes_check_user_role( $role, $user_id = null ) {

    if ( is_numeric( $user_id ) ) {
      $user = get_userdata( $user_id );
    } else {
        $user = wp_get_current_user();
    }

    if ( empty( $user ) ) { return false; }

    return in_array( $role, (array) $user->roles );
}