WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 8 weeks ago

#43884 new enhancement

new is_front() function

Reported by: Tkama Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

When we need to check if we doing something in front-end, we do it like this:

if( ! is_admin() ){}

But this not convenient and not so clear because of !. And maybe not full, because we don't check other admin functions like: is_blog_admin(), is_network_admin(), is_user_admin().

We have so many functions in WordPress, but haven't this simple but useful function, why?

Maybe its a good idea to add is_front() function in /wp-includes/load.php file?

function is_front(){
	return ! is_admin();
}

Change History (2)

#1 in reply to: ↑ description @SergeyBiryukov
8 weeks ago

Replying to Tkama:

When we need to check if we doing something in front-end, we do it like this:

if( ! is_admin() ){}

But this not convenient and not so clear because of !. And maybe not full, because we don't check other admin functions like: is_blog_admin(), is_network_admin(), is_user_admin().

If any of them is true, is_admin() should also return true.

#2 @Tkama
8 weeks ago

Thanks! I examine the code more carefully, we don't need to check is_blog_admin(), is_network_admin(), is_user_admin() in this case.

But, my main idea was to add a new function is_front() in core. It's more clear (understandable) to write if( is_front() ) than if( ! is_admin() )...

Last edited 8 weeks ago by Tkama (previous) (diff)
Note: See TracTickets for help on using tickets.