PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 10.3.0 10.4.0 All 60 releases
acymailing / back / Core / wordpress / url.php

url.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress trunk, at back/Core/wordpress/url.php

95 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') || die('Restricted Access');
4
5 function acym_route(string $url, bool $xhtml = true): string
6 {
7 return acym_baseURI().$url;
8 }
9
10 function acym_addPageParam(string $url, bool $ajax = false, bool $front = false): string
11 {
12 preg_match('#^([a-z]+)(?:[^a-z]|$)#Uis', $url, $ctrl);
13
14 if ($front) {
15 $link = 'index.php?page='.ACYM_COMPONENT.'_front&ctrl='.$url;
16 if ($ajax) $link .= '&'.acym_noTemplate();
17 } else {
18 $link = 'admin.php?page='.ACYM_COMPONENT.'_'.$ctrl[1].'&ctrl='.$url;
19 if ($ajax) {
20 $link .= '&action='.ACYM_COMPONENT.'_router&'.acym_noTemplate();
21 }
22 }
23
24 return $link;
25 }
26
27 function acym_baseURI(bool $pathonly = false): string
28 {
29 if (acym_isAdmin()) {
30 return admin_url();
31 }
32
33 return acym_rootURI();
34 }
35
36 function acym_rootURI(bool $pathonly = false, ?string $path = 'siteurl'): string
37 {
38 $rootURI = rtrim(site_url(), '/').'/';
39
40 // For WPML
41 if (!acym_isAdmin()) {
42 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook for integration.
43 $wpmlSiteUrl = apply_filters('wpml_home_url', $rootURI);
44 if ($wpmlSiteUrl !== $rootURI) {
45 $rootURI = rtrim($wpmlSiteUrl, '/').'/';
46 }
47 }
48
49 // For WordPress bedrock
50 if (defined('CONTENT_DIR') && substr($rootURI, -3) === 'wp/') {
51 $rootURI = substr($rootURI, 0, -3);
52 }
53
54 return $rootURI;
55 }
56
57 function acym_completeLink(string $link, bool $popup = false, bool $redirect = false, bool $forceNoPopup = false): string
58 {
59 if (($popup || acym_isNoTemplate()) && $forceNoPopup == false) {
60 $link .= '&'.acym_noTemplate();
61 }
62
63 $link = acym_addPageParam($link);
64
65 return acym_route($link);
66 }
67
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
72 {
73 return htmlspecialchars_decode(acym_route(acym_addPageParam($url, true)));
74 }
75
76 function acym_frontendLink(string $link, bool $complete = true, bool $sef = true): string
77 {
78 return acym_rootURI().acym_addPageParam($link, true, true);
79 }
80
81 function acym_backendLink(string $link): string
82 {
83 return admin_url().acym_addPageParam($link);
84 }
85
86 function acym_getMenu()
87 {
88 return get_post();
89 }
90
91 function acym_parseUrl(string $url)
92 {
93 return wp_parse_url($url);
94 }
95