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