| @@ -84,12 +84,42 @@ | ||
| 84 | 84 | do_action('ws_plugin__s2member_before_add_css', get_defined_vars()); |
| 85 | 85 | |
| 86 | 86 | if(!is_admin() && c_ws_plugin__s2member_css_js_themes::lazy_load_css_js()) |
| 87 | 87 | { |
| 88 | - $s2o = $GLOBALS['WS_PLUGIN__']['s2member']['c']['s2o_url']; | |
| 88 | + $static = (!empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['static_css'])) ? c_ws_plugin__s2member_utils_assets::ensure_static_assets('css') : array(); | |
| 89 | + $static_css = !empty($static['ok']) && !empty($static['assets']); | |
| 90 | + $dynamic_css = !$static_css; | |
| 89 | 91 | |
| 90 | - wp_enqueue_style('ws-plugin--s2member', $s2o.'?ws_plugin__s2member_css=1&qcABC=1', array(), c_ws_plugin__s2member_utilities::ver_checksum(), 'all'); | |
| 92 | + if($static_css) | |
| 93 | + { | |
| 94 | + $dependency = array(); | |
| 95 | + foreach($static['assets'] as $id => $asset) | |
| 96 | + { | |
| 97 | + $handle = ($id === 's2member-pro.css') ? 'ws-plugin--s2member-pro' : 'ws-plugin--s2member'; | |
| 98 | + wp_enqueue_style($handle, $asset['url'], $dependency, NULL, 'all'); | |
| 99 | + c_ws_plugin__s2member_utils_assets::register_page_asset_expectations($id, 'css', $asset['url'], 'static', $asset['build']); | |
| 100 | + $dependency = array($handle); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + else | |
| 104 | + { | |
| 105 | + //260906.0738 If requested static delivery cannot be used, prefer full WordPress so normal-plugin hooks/customizations that caused the fallback are preserved. | |
| 106 | + $dynamic_css_url = c_ws_plugin__s2member_utils_assets::dynamic_asset_url(!empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['static_css'])).'?ws_plugin__s2member_css=1&qcABC=1'; | |
| 107 | + $dynamic_css_delivery = (strpos($dynamic_css_url, $GLOBALS['WS_PLUGIN__']['s2member']['c']['s2o_url'].'?') === 0) ? 'dynamic-s2member-o' : 'dynamic-wordpress'; //260910.0709 Runtime diagnostics name the physical route; the saved loader preference intentionally remains the legacy `s2o` value. | |
| 108 | + $static_css_failed_id = ''; | |
| 109 | + if(!empty($static['assets']) && is_array($static['assets'])) | |
| 110 | + foreach($static['assets'] as $_static_css_id => $_static_css_asset) | |
| 111 | + if(empty($_static_css_asset['ok'])) | |
| 112 | + { | |
| 113 | + $static_css_failed_id = (string)$_static_css_id; | |
| 114 | + break; | |
| 115 | + } | |
| 116 | + wp_enqueue_style('ws-plugin--s2member', $dynamic_css_url, array(), c_ws_plugin__s2member_utilities::ver_checksum(), 'all'); | |
| 117 | + //260913.2001 Preserve static-route context server-side; compatibility-required Dynamic delivery stays Healthy, while real fallback retains its specific Last issue cause. | |
| 118 | + c_ws_plugin__s2member_utils_assets::register_page_asset_expectations($static_css_failed_id, 'css', $dynamic_css_url, $dynamic_css_delivery, 0, (!empty($static['error'])) ? (string)$static['error'] : '', !empty($static['dynamic_required'])); | |
| 119 | + } | |
| 91 | 120 | |
| 121 | + //260903.1918 Static CSS keeps Framework/Pro files separate by default, with optional combining; any incompatible hook/build failure retains the single legacy dynamic response. | |
| 92 | 122 | do_action('ws_plugin__s2member_during_add_css', get_defined_vars()); |
| 93 | 123 | } |
| 94 | 124 | do_action('ws_plugin__s2member_after_add_css', get_defined_vars()); |
| 95 | 125 | } |
| @@ -96,9 +126,9 @@ | ||
| 96 | 126 | |
| 97 | 127 | /** |
| 98 | 128 | * Enqueues JS file for theme integration. |
| 99 | 129 | * |
| 100 | - * Be sure s2Member's API Constants are already defined before firing this. | |
| 130 | + * Current-user inline globals tolerate unusually early script printing before s2Member's normal API Constants setup. | |
| 101 | 131 | * |
| 102 | 132 | * @package s2Member\CSS_JS |
| 103 | 133 | * @since 3.5 |
| 104 | 134 | * |
| @@ -113,21 +143,49 @@ | ||
| 113 | 143 | do_action('ws_plugin__s2member_before_add_js_w_globals', get_defined_vars()); |
| 114 | 144 | |
| 115 | 145 | if((!is_admin() && c_ws_plugin__s2member_css_js_themes::lazy_load_css_js()) || (is_user_admin() && $pagenow === 'profile.php' && !current_user_can('edit_users'))) |
| 116 | 146 | { |
| 117 | - $s2o = $GLOBALS['WS_PLUGIN__']['s2member']['c']['s2o_url']; | |
| 147 | + $static = (!is_admin() && !empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['static_js']) && function_exists('wp_add_inline_script')) ? c_ws_plugin__s2member_utils_assets::ensure_static_assets('js') : array(); | |
| 148 | + $static_js = !empty($static['ok']) && !empty($static['assets']); | |
| 149 | + $page_text = c_ws_plugin__s2member_utils_assets::static_js_text_delivery() === 'page'; | |
| 150 | + $static_inline_js = ($static_js && $page_text) ? c_ws_plugin__s2member_utils_assets::static_js_inline_data($static['assets']) : ''; | |
| 151 | + if($static_js && $page_text && $static_inline_js === '') | |
| 152 | + $static_js = FALSE; //260906.2049 Page-loaded JavaScript text requires the matching shipped data map before slot-based static JavaScript can be used. | |
| 153 | + $dynamic_js = !$static_js; | |
| 118 | 154 | |
| 119 | - if(is_user_logged_in()) // Separate version for logged-in Users/Members. | |
| 155 | + if($static_js) | |
| 120 | 156 | { |
| 121 | - $md5 = WS_PLUGIN__S2MEMBER_API_CONSTANTS_MD5; // An MD5 hash based on global key => values. | |
| 122 | - // The MD5 hash allows the script to be cached in the browser until the globals happen to change. | |
| 123 | - // For instance, the global variables may change when a User who is logged-in changes their Profile. | |
| 124 | - wp_enqueue_script('ws-plugin--s2member', $s2o.'?ws_plugin__s2member_js_w_globals='.urlencode($md5).'&qcABC=1', array('jquery'), c_ws_plugin__s2member_utilities::ver_checksum(), TRUE); | |
| 157 | + $dependency = array('jquery'); | |
| 158 | + foreach($static['assets'] as $id => $asset) | |
| 159 | + { | |
| 160 | + $handle = ($id === 's2member-pro.js') ? 'ws-plugin--s2member-pro' : 'ws-plugin--s2member'; | |
| 161 | + wp_enqueue_script($handle, $asset['url'], $dependency, NULL, TRUE); | |
| 162 | + if($handle === 'ws-plugin--s2member') | |
| 163 | + wp_add_inline_script($handle, c_ws_plugin__s2member_css_js_in::current_user_js_globals(TRUE).(($static_inline_js !== '') ? "\n".$static_inline_js : ''), 'before'); | |
| 164 | + c_ws_plugin__s2member_utils_assets::register_page_asset_expectations($id, 'js', $asset['url'], 'static', $asset['build']); | |
| 165 | + $dependency = array($handle); | |
| 166 | + } | |
| 125 | 167 | } |
| 126 | - else // Else if they are not logged in, we distinguish the JavaScript file by NOT including $md5. | |
| 127 | - { // This essentially creates 2 versions of the script. One while logged in & another when not. | |
| 128 | - wp_enqueue_script('ws-plugin--s2member', $s2o.'?ws_plugin__s2member_js_w_globals=1&qcABC=1', array('jquery'), c_ws_plugin__s2member_utilities::ver_checksum(), TRUE); | |
| 168 | + else | |
| 169 | + { | |
| 170 | + //260906.0738 A static-JS compatibility fallback uses full WordPress so runtime gettext/plugin customizations remain available; static-disabled sites retain their selected dynamic loader. | |
| 171 | + $dynamic_asset_url = c_ws_plugin__s2member_utils_assets::dynamic_asset_url(!empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['static_js'])); | |
| 172 | + $dynamic_js_value = (is_user_logged_in()) ? WS_PLUGIN__S2MEMBER_API_CONSTANTS_MD5 : '1'; | |
| 173 | + $dynamic_js_url = $dynamic_asset_url.'?ws_plugin__s2member_js_w_globals='.urlencode($dynamic_js_value).'&qcABC=1'; | |
| 174 | + $dynamic_js_delivery = (strpos($dynamic_js_url, $GLOBALS['WS_PLUGIN__']['s2member']['c']['s2o_url'].'?') === 0) ? 'dynamic-s2member-o' : 'dynamic-wordpress'; //260910.0709 Runtime diagnostics name the physical route; the saved loader preference intentionally remains the legacy `s2o` value. | |
| 175 | + $static_js_failed_id = ''; | |
| 176 | + if(!empty($static['assets']) && is_array($static['assets'])) | |
| 177 | + foreach($static['assets'] as $_static_js_id => $_static_js_asset) | |
| 178 | + if(empty($_static_js_asset['ok'])) | |
| 179 | + { | |
| 180 | + $static_js_failed_id = (string)$_static_js_id; | |
| 181 | + break; | |
| 182 | + } | |
| 183 | + wp_enqueue_script('ws-plugin--s2member', $dynamic_js_url, array('jquery'), c_ws_plugin__s2member_utilities::ver_checksum(), TRUE); | |
| 184 | + //260913.2001 Preserve static-route context server-side; compatibility-required Dynamic delivery stays Healthy, while real fallback retains its specific Last issue cause. | |
| 185 | + c_ws_plugin__s2member_utils_assets::register_page_asset_expectations($static_js_failed_id, 'js', $dynamic_js_url, $dynamic_js_delivery, 0, (!empty($static['error'])) ? (string)$static['error'] : '', !empty($static['dynamic_required'])); | |
| 129 | 186 | } |
| 187 | + | |
| 130 | 188 | do_action('ws_plugin__s2member_during_add_js_w_globals', get_defined_vars()); |
| 131 | 189 | } |
| 132 | 190 | do_action('ws_plugin__s2member_after_add_js_w_globals', get_defined_vars()); |
| 133 | 191 | } |
| @@ -146,9 +204,9 @@ | ||
| 146 | 204 | * @return string Possibly altered script tag. |
| 147 | 205 | */ |
| 148 | 206 | public static function script_loader_tag($tag = '', $handle = '') |
| 149 | 207 | { |
| 150 | - if ($handle === 'ws-plugin--s2member') { | |
| 208 | + if (in_array($handle, array('ws-plugin--s2member', 'ws-plugin--s2member-pro'), TRUE)) { | |
| 151 | 209 | $tag = str_replace(' src=', ' data-cfasync="false" src=', $tag); |
| 152 | 210 | } |
| 153 | 211 | return $tag; // Prevent RocketLoader from loading async. |
| 154 | 212 | // See: <https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-my-script-s-in-Automatic-Mode-> |