Create a specialized QA Heatmap Analytics browsing account.

This article is based on information provided by our ambassador, uzurea.net. Thank you very much.

By customizing the permissions feature of WordPress, you can enable a specific account to view only QA Heatmap Analytics. The steps are as follows

  1. Add any user. The permission to view the dashboard is fine for subscribers, but to be able to view the heatmap, you need to be an administrator (editor or higher for paid plans) in the current version 1.1.3.
  2. Add the code shown below to your theme’s functions.php.
  3. Replace ‘login_name’ (two places) in the code in step 2 with the login ID of the user you added in step 1.
    1. 例)$user_login === ‘myname@test.com’
  4. In the variable $need_submenus in the code of 2, add or leave the submenu names you need for the users of 1.
    1. 例)$need_submenus = [‘ダッシュボード’];
  5. After logging in as user 1 and going directly to the QA Heatmap Analytics admin URL, make sure you can view the menu that you correctly set up in 4.

※add_cap関数を用いるため、上記の設定を行うと該当ユーザーには永久的にQA Heatmap Analyticsの閲覧権限が与えられます(DBのuser_metaに保存されます)。不要になった権限を削除するには、ユーザーごと削除するか、remove_cap関数を活用してください。Since the add_cap function is used, the above setting will permanently give the user the permission to view QA Heatmap Analytics (stored in the user_meta of the DB). To remove the permissions that are no longer needed, delete the entire user or use the remove_cap function.

Code to add to functions.php

//管理者画面へのアクセス権を付与
function qa_roleadd_func ( $user_login , $current_user ) {
    //権限を与えたいユーザーのログインIDを指定します
    if ( $user_login === 'login_name' ) {
        $current_user->add_cap('manage_options');
    }
}
add_action( 'wp_login', 'qa_roleadd_func', 10, 2 );

//管理画面の不要なメニューを消す
function remove_admin_menus() {
    $currentuser = wp_get_current_user();
    if ( $currentuser->user_login === 'login_name' ) {

        //QA Heatmap Analytics以外のメニューを消します
        //下記で消せないメニューは、themeに入っているfunctions.phpなどで直接追加されている可能性があります。
        global $menu;
        foreach ( $menu as $idx => $eachmenu ) {
            if ( $eachmenu[0] !== 'QA Heatmap Analytics' ) {
                unset( $menu[$idx] );
            }
        }

        //QA Heatmap Analytics サブメニューコントロール
        //必要なメニュー名を記入しておきます。
        $need_submenus = ['ダッシュボード', 'サイト統計情報', 'ヒートマップ管理'];
        global $submenu;
        foreach ( $submenu['qahm-realtime'] as $idx => $eachsub ) {
            $is_need = false;
            foreach ( $need_submenus as $need_submenu ) {
                if ( $eachsub[0] === $need_submenu ) {
                    $is_need = true;
                }
            }
            if ( ! $is_need ) {
                unset( $submenu['qahm-realtime'][$idx] );
            }
        }
    }
}
add_action('admin_menu', 'remove_admin_menus');

Was this article helpful?

Related Articles