How can I get the requested entry from a plugin? If I’m accessing an entry’s URL (the 4th check in Routing), how can I get the entry that the URL matched from a plugin?
You can get the request’s matched element via:



$element = craft()-&gt;urlManager-&gt;getMatchedElement();


There are two things to remember though:


There may not be a matched element
The matched element might not be an entry. (It could also be a category, and if you have any plugins installed that add their own element types that can have their own URLs, it could be one of those.)


To defend against those possibilities, just use the following conditional:

if ($element &amp;&amp; $element-&gt;getElementType() == ElementType::Entry)
{
    // There was a matched element, and it's an entry!
    // ...
}