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