Every attorney who shall, directly or indirectly, advise in relation to, or aid or promote the defense of, any action or proceeding in any court, the prosecution of which shall be carried on, aided, or promoted by any person as county attorney or other public prosecutor with whom such attorney shall be, directly or indirectly, connected as partner, or who, having personally prosecuted or in any manner aided or promoted any action or proceeding in any court as county attorney or other public prosecutor, shall afterwards, directly or indirectly, advise in relation to, or take any part in, the defense thereof, as attorney or otherwise, or who shall take or receive any valuable consideration from or on behalf of any defendant in any such action, upon any understanding or agreement whatsoever, expressed or implied, having relation to the defense thereof, shall be guilty of a misdemeanor.