Rules regarding concealing righteous deeds and making them public

Question
What are the rules regarding concealing righteous deeds and making them public when the person knows that making them public has greater good?
Answer

Allah says,

إِن تُبۡدُواْ ٱلصَّدَقَٰتِ فَنِعِمَّا هِيَۖ وَإِن تُخۡفُوهَا وَتُؤۡتُوهَا ٱلۡفُقَرَآءَ فَهُوَ خَيۡرٞ لَّكُمۡۚ 
If you disclose your charitable expenditures, they are good; but if you conceal them and give them to the poor, it is better for you’ (Al-Baqarah, 271)

What proves that concealing good deeds is better is that it is closest to sincerity. It is recorded in the hadeeth about the Seven, the Prophet ﷺ said, ‘…and a man who made a charitable donation and he concealed it to the extent that he is left-handed not know what his right hand spent’ (Bukhaary1423). Therefore, concealing good deeds is better and that is the underlying rule. However, at times it is better to do the alternative such as when the donor intends that if he is the first to make the donation others will follow him such as what has been recorded in the hadeeth about ‘people dressed in striped woollen clothes’ who were poor and in need of donation. The Prophet ﷺ encouraged people to give donations. A man came and gave the donations and thereafter others followed him. Whereupon the Prophet ﷺ said, ‘Whoever sets a good example then he shall receive the reward of it and the reward of all those who follow him’ (Muslim: 1017). So, doing it for such reasons, namely, that others may follow him, is without doubt a rewardable act and such a person will receive the reward of all those who follow him. The same applies to other deeds other than charity such as voluntary acts of worship. For example, it is encouraged that a person offers voluntary prayer at home. The Prophet ﷺ said ‘The best prayer person can pray is in his house except for the compulsory prayers’ (Al-Bukhaary, 7290). However, if he intends that people would follow him in offering their voluntary prayers or accusations that he does not offer voluntary prayers will be removed, such as a student of knowledge seen by people not to offer voluntary prayers except for the compulsory prayers so the lay people follow him in this regard. Therefore, they offer the compulsory prayer and leave without offering voluntary prayers. The one who prays his compulsory prayer and leaves and does not offer his voluntary prayer not knowing that the one he is following has offered his prayer at home. Well, firstly, the reason why praying voluntary prayers at home is better is for those who remain at home such as women and children they can learn how to pray once they see their father praying and therefore there is no doubt that praying at home is better and more complete. However, if people start to doubt or  people become lazy in offering their voluntary prayers or see that he is always late coming to prayers and he does not attend except just before the iqaamah and does not offer the voluntary prayer before the compulsory ones, because they do not know that he has prayed at home before coming to the mosque like the Prophet ﷺ used to do, if such an example is true for someone and no clarification has been made to them, and so he were to pray in front of them so that they may follow him then he will have reward, Allaah-willing.