| 1 |
<?php |
| 2 |
|
| 3 |
class VP_WP_Admin |
| 4 |
{ |
| 5 |
|
| 6 |
/** |
| 7 |
* [taken from WPAlchemy Class by Dimas Begunoff] |
| 8 |
* Used to check if creating or editing a post or page |
| 9 |
* |
| 10 |
* @static |
| 11 |
* @access private |
| 12 |
* @return string "post" or "page" |
| 13 |
*/ |
| 14 |
public static function is_post_or_page() |
| 15 |
{ |
| 16 |
$post_type = self::get_current_post_type(); |
| 17 |
|
| 18 |
if (isset($post_type)) |
| 19 |
{ |
| 20 |
if ('page' == $post_type) |
| 21 |
{ |
| 22 |
return 'page'; |
| 23 |
} |
| 24 |
else |
| 25 |
{ |
| 26 |
return 'post'; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
return NULL; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* [taken from WPAlchemy Class by Dimas Begunoff] |
| 35 |
* Used to check for the current post type, works when creating or editing a |
| 36 |
* new post, page or custom post type. |
| 37 |
* |
| 38 |
* @static |
| 39 |
* @return string [custom_post_type], page or post |
| 40 |
*/ |
| 41 |
public static function get_current_post_type() |
| 42 |
{ |
| 43 |
|
| 44 |
if(!class_exists('WPAlchemy_MetaBox')) |
| 45 |
{ |
| 46 |
require_once VP_FileSystem::instance()->resolve_path('includes', 'wpalchemy/MetaBox'); |
| 47 |
} |
| 48 |
|
| 49 |
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL ; |
| 50 |
|
| 51 |
if ( isset( $uri ) ) |
| 52 |
{ |
| 53 |
$uri_parts = parse_url($uri); |
| 54 |
|
| 55 |
$file = basename($uri_parts['path']); |
| 56 |
|
| 57 |
if ($uri AND in_array($file, array('post.php', 'post-new.php'))) |
| 58 |
{ |
| 59 |
$post_id = WPAlchemy_MetaBox::_get_post_id(); |
| 60 |
|
| 61 |
$post_type = isset($_GET['post_type']) ? $_GET['post_type'] : NULL ; |
| 62 |
|
| 63 |
$post_type = $post_id ? get_post_type($post_id) : $post_type ; |
| 64 |
|
| 65 |
if (isset($post_type)) |
| 66 |
{ |
| 67 |
return $post_type; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
// because of the 'post.php' and 'post-new.php' checks above, we can default to 'post' |
| 72 |
return 'post'; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
return NULL; |
| 78 |
} |
| 79 |
|
| 80 |
} |