Why is Turkey taking on Kurdish and Islamic State militants?

Why is Turkey taking on Kurdish and Islamic State militants?