Change the order of the "subpalette"  to last position.
Change the callback "subpaletteButton". Only entries which can have subpalettes get the new button.
Change the order of parameters from an "array_replace_recursive" function.