Helper.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Orders\Legacy; |
| 4 | |
| 5 | use WPML\FP\Obj; |
| 6 | |
| 7 | class Helper { |
| 8 | |
| 9 | const POST_TYPE_ORDER = 'shop_order'; |
| 10 | |
| 11 | const PAGE_ORDER_LIST = 'edit.php'; |
| 12 | |
| 13 | const PAGE_ORDER_NEW = 'post-new.php'; |
| 14 | |
| 15 | const PAGE_ORDER_EDIT = 'post.php'; |
| 16 | |
| 17 | const ACTION_EDIT = 'edit'; |
| 18 | |
| 19 | private static function isPostTypeOrder( $postType = null ) { |
| 20 | if ( null === $postType ) { |
| 21 | $postType = Obj::prop( 'post_type', $_GET ); |
| 22 | } |
| 23 | return self::POST_TYPE_ORDER === $postType; |
| 24 | } |
| 25 | |
| 26 | private static function isOrderAdminScreen( $page ) { |
| 27 | global $pagenow; |
| 28 | return is_admin() && $page === $pagenow; |
| 29 | } |
| 30 | |
| 31 | public static function isOrderCreateAdminScreen() { |
| 32 | return self::isOrderAdminScreen( self::PAGE_ORDER_NEW ) && self::isPostTypeOrder(); |
| 33 | } |
| 34 | |
| 35 | public static function isOrderListAdminScreen() { |
| 36 | return self::isOrderAdminScreen( self::PAGE_ORDER_LIST ) && self::isPostTypeOrder(); |
| 37 | } |
| 38 | |
| 39 | public static function isOrderEditAdminScreen() { |
| 40 | $isActionEdit = Obj::prop( 'action', $_GET ) === self::ACTION_EDIT; |
| 41 | $getPost = Obj::prop( 'post', $_GET ); |
| 42 | |
| 43 | return self::isOrderAdminScreen( self::PAGE_ORDER_EDIT ) && $isActionEdit && $getPost && self::isPostTypeOrder( get_post_type( $getPost ) ); |
| 44 | } |
| 45 | } |
| 46 |