Skip to content

Instantly share code, notes, and snippets.

@evanre
Last active June 27, 2017 16:00
Show Gist options
  • Save evanre/390c2870b3a5682953c0f017d350d6bf to your computer and use it in GitHub Desktop.
Save evanre/390c2870b3a5682953c0f017d350d6bf to your computer and use it in GitHub Desktop.
Function to check if the current page is a post edit page
<?php
/**
* is_edit_page
* function to check if the current page is a post edit page
*
* @author Ohad Raz <[email protected]>
* @url https://wordpress.stackexchange.com/questions/50043
*
* @param string $new_edit what page to check for accepts new - new post page ,edit - edit post page, null for either
* @return boolean
*/
function is_edit_page($new_edit = null){
global $pagenow;
//make sure we are on the backend
if (!is_admin()) return false;
if($new_edit == "edit")
return in_array( $pagenow, array( 'post.php', ) );
elseif($new_edit == "new") //check for new post page
return in_array( $pagenow, array( 'post-new.php' ) );
else //check for either new or edit
return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment