Last active
December 29, 2015 13:15
-
-
Save waelio/9a270d4ee6bbd5d12bcd to your computer and use it in GitHub Desktop.
WP- Return the object type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @param object|int|string $object | |
* @return string | |
*/ | |
function get_object_type($object){ | |
$workable = false; | |
$object_type = gettype($object); | |
switch($object_type){ | |
case 'object': | |
$workable=true; | |
break; | |
case 'string': | |
$workable = (is_numeric(intval(trim($object)))); | |
break; | |
case 'integer': | |
$workable =true; | |
break; | |
} | |
if($workable){ | |
if ($object_type == 'object'){ | |
return (isset($object->post_type)) ? $object->post_type : $object->taxonomy; | |
}else{ | |
$test = get_post($object); | |
if (is_object($test)) | |
return get_object_type($test); | |
else | |
return get_object_type(get_category($object)); | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment