| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +defined('ABSPATH') || die('Restricted Access'); | |
| 4 | + | |
| 3 | 5 | function acym_addScript(bool $raw, string $script, array $params = []): string |
| 4 | 6 | { |
| 5 | 7 | static $scriptNumber = 0; |
| 6 | 8 | $scriptNumber++; |
| @@ -13,14 +15,25 @@ | ||
| 13 | 15 | if ($raw) { |
| 14 | 16 | if (!empty($params['dependencies']['script_name'])) { |
| 15 | 17 | wp_add_inline_script($params['dependencies']['script_name'], $script); |
| 16 | 18 | } else { |
| 19 | + // TODO: refactor js insertion to use CMS dedicated methods | |
| 20 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Raw JS content passed by caller. | |
| 17 | 21 | echo '<script type="text/javascript">'.$script.'</script>'; |
| 18 | 22 | } |
| 19 | 23 | } elseif (!empty($params['defer']) || !empty($params['async']) || !empty($params['needTagScript'])) { |
| 20 | - echo '<script type="text/javascript" src="'.$script.'"'.(!empty($params['async']) ? ' async' : '').(!empty($params['defer']) ? ' defer' : '').'></script>'; | |
| 24 | + // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript -- After WordPress hook. | |
| 25 | + echo '<script type="text/javascript" src="'.esc_url($script).'"'.(!empty($params['async']) ? ' async' : '').(!empty($params['defer']) ? ' defer' : '').'></script>'; | |
| 21 | 26 | } else { |
| 22 | - wp_enqueue_script($handle, $script, $params['dependencies']); | |
| 27 | + wp_enqueue_script( | |
| 28 | + $handle, | |
| 29 | + $script, | |
| 30 | + $params['dependencies'], | |
| 31 | + '11.1.0', | |
| 32 | + [ | |
| 33 | + 'in_footer' => false, | |
| 34 | + ] | |
| 35 | + ); | |
| 23 | 36 | } |
| 24 | 37 | |
| 25 | 38 | return $handle; |
| 26 | 39 | } |
| @@ -26,12 +39,16 @@ | ||
| 26 | 39 | } |
| 27 | 40 | |
| 28 | 41 | function acym_addStyle(bool $raw, string $style): void |
| 29 | 42 | { |
| 43 | + // TODO: refactor style insertion to use CMS dedicated methods | |
| 44 | + | |
| 30 | 45 | if ($raw) { |
| 46 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Raw CSS content passed by caller. | |
| 31 | 47 | echo '<style>'.$style.'</style>'; |
| 32 | 48 | } else { |
| 33 | - echo '<link rel="stylesheet" href="'.$style.'" type="text/css">'; | |
| 49 | + // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet -- To refactor. | |
| 50 | + echo '<link rel="stylesheet" href="'.esc_url($style).'" type="text/css">'; | |
| 34 | 51 | } |
| 35 | 52 | } |
| 36 | 53 | |
| 37 | 54 | function acym_loadCmsScripts(): void |
| @@ -45,8 +62,9 @@ | ||
| 45 | 62 | var ACYM_IS_ADMIN = '.(acym_isAdmin() ? 'true' : 'false').'; |
| 46 | 63 | if("undefined" === typeof icl_ajxloaderimg_src) var icl_ajxloaderimg_src = "";' |
| 47 | 64 | ); |
| 48 | 65 | |
| 66 | + // Without this line the image insertion and dtexts button doesn't work | |
| 49 | 67 | wp_enqueue_media(); |
| 50 | 68 | |
| 51 | 69 | wp_enqueue_script('jquery'); |
| 52 | 70 | wp_enqueue_script('jquery-ui-draggable'); |
| @@ -54,9 +72,9 @@ | ||
| 54 | 72 | wp_enqueue_script('jquery-ui-sortable'); |
| 55 | 73 | wp_enqueue_script('jquery-effects-slide'); |
| 56 | 74 | } |
| 57 | 75 | |
| 58 | -function acym_redirect(string $url, string $msg = '', string $msgType = 'message', bool $safe = false): void | |
| 76 | +function acym_redirect(string $url, string $msg = '', string $msgType = 'message', bool $safe = true): void | |
| 59 | 77 | { |
| 60 | 78 | if (acym_isAdmin() && substr($url, 0, 4) != 'http' && substr($url, 0, 4) != 'www.') { |
| 61 | 79 | $url = acym_addPageParam($url); |
| 62 | 80 | } |
| @@ -66,14 +84,16 @@ | ||
| 66 | 84 | } |
| 67 | 85 | |
| 68 | 86 | $wordpressOutput = @ob_get_clean(); |
| 69 | 87 | if (headers_sent()) { |
| 88 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped output from WordPress itself. | |
| 70 | 89 | echo $wordpressOutput; |
| 71 | - acym_addScript(true, 'window.location.href = "'.addslashes($url).'";'); | |
| 90 | + acym_addScript(true, 'window.location.href = '.wp_json_encode($url).';'); | |
| 72 | 91 | } else { |
| 73 | 92 | if ($safe) { |
| 74 | 93 | wp_safe_redirect($url); |
| 75 | 94 | } else { |
| 95 | + // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- mainly for email links after tracking is applied | |
| 76 | 96 | wp_redirect($url); |
| 77 | 97 | } |
| 78 | 98 | } |
| 79 | 99 | exit; |