Is there a way to prevent a function/method from being called outside a specific hook?

There’s a WordPress function current_filter() that retrieves the name of the current filter or hook that called a function/method. You can match it to a whitelist and either end or continue the function based on the result.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)