Potassium is absorbed from soil as potassium ions. It helps to maintain an anion cation balance in cells and is involved in protein synthesis, opening and closing of stomata, activation of enzymes and maintenance of cell turgidity.
Magnesium is absorbed by plants as divalent $Mg^{2+}$ . It activates enzymes of respiration and photosynthesis, is a constituent of chlorophyll and helps to maintain ribosome structure. Two subunits of ribosomes fail to join in absence of Mg, while its abundance forms aggregates of ribosomes