0

菜单屏幕选项

我想CSS classes默认启用菜单屏幕选项。
我应该使用什么代码来实现这一点?

4

1 回答 1

3

您可以在函数中检查用户元键的get_user_option_{$option}位置添加过滤器。如果元值是,这将是用户第一次登录,它会设置默认的隐藏选项。如果您对此进行了挂钩,则可以设置自己的默认值并确保它永远不会返回。{$option}managenav-menuscolumnshiddenwp_nav_menu_setup()falsefalse

// add a filter to catch unset hidden options
add_filter( 'get_user_option_managenav-menuscolumnshidden', 'my_default_menuscolumnshidden', 99, 3 );
function my_default_menuscolumnshidden( $result, $option, $user_id ){
    if( $option == "managenav-menuscolumnshidden" ){
        // remove this function to prevent a loop
        remove_filter( 'get_user_option_managenav-menuscolumnshidden', 'my_default_menuscolumnshidden', 99 );
        // check if it is false (first login)
        $result = get_user_option( $option );
        if ( false === $result ) {
            // update with your own defaults (omits CSS from the hidden options)
            $result = array( 0 => 'link-target', 1 => 'xfn', 2 => 'description' );
            update_user_option($user->ID, 'managenav-menuscolumnshidden',
                $result,
                true);
        }
        // re-add filter in case it gets called again
        add_filter( 'get_user_option_managenav-menuscolumnshidden', 'my_default_menuscolumnshidden', 99 );
    }
    // if this was false before, now it is set to custom defaults
    return $result;
}
于 2013-04-03T05:02:07.220 回答