Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) was asked: Some people at times of hardship say Ya Muhammad or Ya ‘Ali or Ya Jilaani. What is the ruling on that?
He replied:
If the intention is to call upon them and seek their help, then the person is a mushrik in the sense of major shirk that puts one beyond the pale of Islam, and he must repent to Allaah and call upon Allaah alone, as Allaah says (interpretation of the meaning):
“Is not He (better than your gods) Who responds to the distressed one, when he calls on Him, and Who removes the evil, and makes you inheritors of the earth, generations after generations? Is there any ilaah (god) with Allaah? Little is that you remember!”
[al-Naml 27:62]
As well as being a mushrik, he is also fooling himself. Allaah says (interpretation of the meaning):
“And who turns away from the religion of Ibraaheem (Abraham) (i.e. Islamic Monotheism) except him who befools himself?”
[al-Baqarah 2:130]
“And who is more astray than one who calls on (invokes) besides Allaah, such as will not answer him till the Day of Resurrection, and who are (even) unaware of their calls (invocations) to them?”
[al-Ahqaaf 46:5]
End quote from Fataawa al-Shaykh Ibn ‘Uthaymeen (2/133).