Allah Accepts Deeds That Are Only For Him
عَنْ أَمِيْرِ المؤْمِنِيْن أَبِي حَفْصٍ عُمَرَ بْنِ الْخَطَّابِ رضي الله عنه قَالَ: سَمِعْتُ رَسُولَ اللهِ صلي الله عليه و سلم يَقُولُ : إِنَّمَا الأَعْمَالُ بِالنِّيَّاتِ، وَإِنَّمَا لِكُلِّ امْرِئٍ مَا نَوَى، فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللهِ وَرَسُولِهِ؛ فَهِجْرَتُهُ إِلَى اللهِ وَرَسُولِهِ، وَمَنْ كَانَتْ هِجْرَتُهُ لدُنْيَا يُصِيبُهَا، أَوِ امْرَأَةٍ يَنْكِحُهَا؛ فَهِجْرَتُهُ إِلَى مَا هَاجَرَ إِلَيْهِ
رَوَاهُ البُخَارِيُّ وَمسلم
It is related by Umar Ibn al-Khattab (رضى الله تعالى عنه ) that he heard the Messenger of Allah (صلى الله عليه وسلم ) say:
The actions are but judged according to intentions; and to every man is due what he intended. Thus, whosoever migrates for the sake of Allah (SWT) and His Messenger (صلى الله عليه وسلم ) (and there is no other motive of his migration except compliance with the commands of Allah (SWT) and his Prophet (صلى الله عليه وسلم ) and winning of their good pleasure), his migration is accounted for the sake of Allah and His Messenger (صلى الله عليه وسلم ) (and doubtlessly, he is to true Muhajir- Emigrant- and shall receive the recompense prescribed for Hijrat-Migration-towards Allah and His Messenger (صلى الله عليه وسلم )); and whosoever migrates for the sake of this world or to wed a woman (his migration will not be for Allah and the Prophet [صلى الله عليه وسلم ]), and will be accounted only for the purpose for which it is intended. (Bukhari and Muslim)
The Main purpose of the Hadith is to Show that the goodness or badness and acceptability or otherwise of all human actions is dependant on intention.
Or, in other words, only such deeds will be deemed good and carry merit in the sight of Allah (SWT) which is done with a good and virtues intention and a good deed noble and meritorious; on the contrary, it will held to be wicked and detestable according to the intention which motivated it through, apparently, it may be good and praiseworthy.
To summarise, Allah (SWT) judges the worth and value of a deed by the motive with which it is performed.
Source: Bilal Academy