| @@ -1,12 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -function acym_route($url, $xhtml = true, $ssl = null) | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 5 | +function acym_route(string $url, bool $xhtml = true): string | |
| 4 | 6 | { |
| 5 | 7 | return acym_baseURI().$url; |
| 6 | 8 | } |
| 7 | 9 | |
| 8 | -function acym_addPageParam($url, $ajax = false, $front = false) | |
| 10 | +function acym_addPageParam(string $url, bool $ajax = false, bool $front = false): string | |
| 9 | 11 | { |
| 10 | 12 | preg_match('#^([a-z]+)(?:[^a-z]|$)#Uis', $url, $ctrl); |
| 11 | 13 | |
| 12 | 14 | if ($front) { |
| @@ -21,9 +23,9 @@ | ||
| 21 | 23 | |
| 22 | 24 | return $link; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | -function acym_baseURI($pathonly = false) | |
| 27 | +function acym_baseURI(bool $pathonly = false): string | |
| 26 | 28 | { |
| 27 | 29 | if (acym_isAdmin()) { |
| 28 | 30 | return admin_url(); |
| 29 | 31 | } |
| @@ -30,13 +32,15 @@ | ||
| 30 | 32 | |
| 31 | 33 | return acym_rootURI(); |
| 32 | 34 | } |
| 33 | 35 | |
| 34 | -function acym_rootURI($pathonly = false, $path = 'siteurl') | |
| 36 | +function acym_rootURI(bool $pathonly = false, ?string $path = 'siteurl', bool $skipMultilingual = false): string | |
| 35 | 37 | { |
| 36 | - $rootURI = rtrim(site_url(), '/').'/'; | |
| 38 | + $rootURI = rtrim($skipMultilingual ? get_option('siteurl') : site_url(), '/').'/'; | |
| 37 | 39 | |
| 38 | - if (!acym_isAdmin()) { | |
| 40 | + // For WPML | |
| 41 | + if (!$skipMultilingual && !acym_isAdmin()) { | |
| 42 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook for integration. | |
| 39 | 43 | $wpmlSiteUrl = apply_filters('wpml_home_url', $rootURI); |
| 40 | 44 | if ($wpmlSiteUrl !== $rootURI) { |
| 41 | 45 | $rootURI = rtrim($wpmlSiteUrl, '/').'/'; |
| 42 | 46 | } |
| @@ -41,8 +45,9 @@ | ||
| 41 | 45 | $rootURI = rtrim($wpmlSiteUrl, '/').'/'; |
| 42 | 46 | } |
| 43 | 47 | } |
| 44 | 48 | |
| 49 | + // For WordPress bedrock | |
| 45 | 50 | if (defined('CONTENT_DIR') && substr($rootURI, -3) === 'wp/') { |
| 46 | 51 | $rootURI = substr($rootURI, 0, -3); |
| 47 | 52 | } |
| 48 | 53 | |
| @@ -48,9 +53,9 @@ | ||
| 48 | 53 | |
| 49 | 54 | return $rootURI; |
| 50 | 55 | } |
| 51 | 56 | |
| 52 | -function acym_completeLink($link, $popup = false, $redirect = false, $forceNoPopup = false) | |
| 57 | +function acym_completeLink(string $link, bool $popup = false, bool $redirect = false, bool $forceNoPopup = false): string | |
| 53 | 58 | { |
| 54 | 59 | if (($popup || acym_isNoTemplate()) && $forceNoPopup == false) { |
| 55 | 60 | $link .= '&'.acym_noTemplate(); |
| 56 | 61 | } |
| @@ -59,18 +64,31 @@ | ||
| 59 | 64 | |
| 60 | 65 | return acym_route($link); |
| 61 | 66 | } |
| 62 | 67 | |
| 63 | -function acym_prepareAjaxURL($url) | |
| 68 | +/** | |
| 69 | + * If you use it to prepare a POST ajax, make sure you add the action and page parameters to the data passed, it's not taken into account if it's only in the URL | |
| 70 | + */ | |
| 71 | +function acym_prepareAjaxURL(string $url): string | |
| 64 | 72 | { |
| 65 | 73 | return htmlspecialchars_decode(acym_route(acym_addPageParam($url, true))); |
| 66 | 74 | } |
| 67 | 75 | |
| 68 | -function acym_frontendLink($link, $complete = true, $sef = true) | |
| 76 | +function acym_frontendLink(string $link, bool $complete = true, bool $sef = true): string | |
| 69 | 77 | { |
| 70 | - return acym_rootURI().acym_addPageParam($link, true, true); | |
| 78 | + return acym_rootURI(false, 'siteurl', true).acym_addPageParam($link, true, true); | |
| 71 | 79 | } |
| 72 | 80 | |
| 81 | +function acym_backendLink(string $link): string | |
| 82 | +{ | |
| 83 | + return admin_url().acym_addPageParam($link); | |
| 84 | +} | |
| 85 | + | |
| 73 | 86 | function acym_getMenu() |
| 74 | 87 | { |
| 75 | 88 | return get_post(); |
| 89 | +} | |
| 90 | + | |
| 91 | +function acym_parseUrl(string $url) | |
| 92 | +{ | |
| 93 | + return wp_parse_url($url); | |
| 76 | 94 | } |