class-link-util.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Admin\Utils; |
| 4 | |
| 5 | use SuperbAddons\Data\Controllers\LinkController; |
| 6 | |
| 7 | class AdminLinkUtil |
| 8 | { |
| 9 | public static function GetLinkID() |
| 10 | { |
| 11 | return apply_filters('superb_addons_link_id', ''); |
| 12 | } |
| 13 | |
| 14 | public static function GetLink($source, $options = false) |
| 15 | { |
| 16 | if (!in_array($source, AdminLinkSource::ALLOWED_SOURCE)) { |
| 17 | $source = AdminLinkSource::DEFAULT; |
| 18 | } |
| 19 | $args = array( |
| 20 | 'su_source' => $source, |
| 21 | ); |
| 22 | $id = self::GetLinkID(); |
| 23 | if (!empty($id)) { |
| 24 | $args['ref'] = substr(sanitize_text_field($id), 0, 25); |
| 25 | } |
| 26 | if (is_array($options) && isset($options['experiment'])) { |
| 27 | $args = array_merge($args, LinkController::GetLinkExpArgs($options['experiment'])); |
| 28 | } |
| 29 | $url = is_array($options) && isset($options['url']) ? $options['url'] : 'https://superbthemes.com/superb-addons/'; |
| 30 | if (is_array($options) && isset($options['anchor'])) { |
| 31 | $url .= '#' . $options['anchor']; |
| 32 | } |
| 33 | return add_query_arg($args, $url); |
| 34 | } |
| 35 | |
| 36 | public static function GetExpLink($source, $options = false) |
| 37 | { |
| 38 | $options = is_array($options) ? $options : array(); |
| 39 | if (!isset($options['experiment'])) { |
| 40 | $options['experiment'] = 'upsell'; |
| 41 | } |
| 42 | return self::GetLink($source, $options); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | class AdminLinkSource |
| 47 | { |
| 48 | const DEFAULT = 'superb-addons'; |
| 49 | const NOTICE = 'notice'; |
| 50 | const NOTICE_LOCK = 'notice-lock'; |
| 51 | const WP_PLUGIN_PAGE = 'plugin-page'; |
| 52 | const NAVIGATION = 'navigation'; |
| 53 | const NAVIGATION_CTA = 'navigation-cta'; |
| 54 | const SETTINGS = 'settings'; |
| 55 | const LIBRARY_ITEM = 'pattern-library'; |
| 56 | const LIBRARY_PAGE_ITEM = 'prebuilt-pages'; |
| 57 | const DESIGNER = 'designer'; |
| 58 | const CSS = 'css'; |
| 59 | const CSS_TARGET = 'css-target'; |
| 60 | const CSS_EXPORT = 'css-export'; |
| 61 | const FORMS = 'forms'; |
| 62 | const SUPPORT = 'support'; |
| 63 | |
| 64 | const ALLOWED_SOURCE = array( |
| 65 | self::NOTICE, |
| 66 | self::NOTICE_LOCK, |
| 67 | self::WP_PLUGIN_PAGE, |
| 68 | self::NAVIGATION, |
| 69 | self::NAVIGATION_CTA, |
| 70 | self::SETTINGS, |
| 71 | self::LIBRARY_ITEM, |
| 72 | self::LIBRARY_PAGE_ITEM, |
| 73 | self::DESIGNER, |
| 74 | self::CSS, |
| 75 | self::CSS_TARGET, |
| 76 | self::CSS_EXPORT, |
| 77 | self::FORMS, |
| 78 | self::SUPPORT |
| 79 | ); |
| 80 | } |
| 81 |