In a sealed box speaker, the entire purpose of the box is to form an ‘infinite baffle’, stopping any of the output from the rear of the drive unit reaching the listener, as this can detract from the desired output from the front of the cone. Before box speakers became popular, this was achieved by mounting drive units in as large a baffle as possible: effective, but not entirely practical.
Bass ports work by allowing some of that rear, out of phase, output to escape from the enclosure, but in an controlled manner that allows it to reinforce, not reduce, the effect of the main forward output of the driver.
The other effect of a port is reduce the back-pressure on the driver, thus allowing it more excursion: in a sealed box, the fact that the air has nowhere to go, and thus has to expand and contract as the driver within that space moves, acts as a spring or damper on the driver unit, impeding its movement and thus limiting, its output.
A port reduces this back-pressure and damping, and the design of the port (length, diameter, profile, surface finish) can be adjusted to control the effect it has. Blocking the port will of course remove its influence, which can be useful if the bass is overbearing or too loose, but you don’t have to go the whole way and block it completely.
Different densities of foam plugs will have differing effects, as will (for example) inserting a foam ring in the port to reduce its diameter and add some resistance to air flow. One old idea used to be to insert a bundle of drinking straws into a port to slow the air flow by creating lots of small diameters rather than one big one.
All of this is something with which you can experiment: what works in one room might well create too little bass in another.