PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 260917
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v260917
260917 260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 All 189 releases
s2member / src / includes / classes / css-js-themes.inc.php

css-js-themes.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 260917, at src/includes/classes/css-js-themes.inc.php

216 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // @codingStandardsIgnoreFile
3 /**
4 * CSS/JS integrations with theme.
5 *
6 * Copyright: © 2009-2011
7 * {@link http://websharks-inc.com/ WebSharks, Inc.}
8 * (coded in the USA)
9 *
10 * Released under the terms of the GNU General Public License.
11 * You should have received a copy of the GNU General Public License,
12 * along with this software. In the main directory, see: /licensing/
13 * If not, see: {@link http://www.gnu.org/licenses/}.
14 *
15 * @package s2Member\CSS_JS
16 * @since 3.5
17 */
18 if(!defined('WPINC')) // MUST have WordPress.
19 exit ('Do not access this file directly.');
20
21 if(!class_exists('c_ws_plugin__s2member_css_js_themes'))
22 {
23 /**
24 * CSS/JS integrations with theme.
25 *
26 * @package s2Member\CSS_JS
27 * @since 3.5
28 */
29 class c_ws_plugin__s2member_css_js_themes
30 {
31 /**
32 * Lazy load CSS/JS files?
33 *
34 * @package s2Member\CSS_JS
35 * @since 131028
36 *
37 * @return boolean TRUE if we should load; else FALSE.
38 */
39 public static function lazy_load_css_js()
40 {
41 static $load; // Static cache var.
42
43 if(isset($load)) return $load;
44
45 $null = NULL; // Needed below in earlier versions of WP.
46
47 if(!$GLOBALS['WS_PLUGIN__']['s2member']['o']['lazy_load_css_js'])
48 $load = TRUE;
49
50 else if(c_ws_plugin__s2member_systematics::is_s2_systematic_use_page())
51 $load = TRUE;
52
53 else if(!empty($_GET[apply_filters('ws_plugin__s2member_check_force_ssl_get_var_name', 's2-ssl', array())]))
54 $load = TRUE;
55
56 else if(c_ws_plugin__s2member_utils_conds::bp_is_installed()
57 && (bp_is_register_page() || bp_is_activation_page() || bp_is_user_profile())
58 ) $load = TRUE;
59
60 else if(is_singular() && ($post = get_post($null))
61 && (stripos($post->post_content, 's2member') !== FALSE || stripos($post->post_content, '[s2') !== FALSE)
62 ) $load = TRUE;
63
64 else if(preg_match('/\/wp\-signup\.php|\/wp\-login\.php|\/wp\-admin\/(?:user\/)?profile\.php|[?&]s2member/', $_SERVER['REQUEST_URI']))
65 $load = TRUE;
66
67 if(!isset($load)) $load = FALSE; // Make sure it's set; always.
68
69 return ($load = apply_filters('ws_plugin__s2member_lazy_load_css_js', $load));
70 }
71
72 /**
73 * Enqueues CSS file for theme integration.
74 *
75 * @package s2Member\CSS_JS
76 * @since 3.5
77 *
78 * @attaches-to ``add_action('wp_print_styles');``
79 *
80 * @return null After enqueuing CSS for theme integration.
81 */
82 public static function add_css()
83 {
84 do_action('ws_plugin__s2member_before_add_css', get_defined_vars());
85
86 if(!is_admin() && c_ws_plugin__s2member_css_js_themes::lazy_load_css_js())
87 {
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;
91
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 }
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.
122 do_action('ws_plugin__s2member_during_add_css', get_defined_vars());
123 }
124 do_action('ws_plugin__s2member_after_add_css', get_defined_vars());
125 }
126
127 /**
128 * Enqueues JS file for theme integration.
129 *
130 * Current-user inline globals tolerate unusually early script printing before s2Member's normal API Constants setup.
131 *
132 * @package s2Member\CSS_JS
133 * @since 3.5
134 *
135 * @attaches-to ``add_action('wp_print_scripts');``
136 *
137 * @return null After enqueuing JS for theme integration.
138 */
139 public static function add_js_w_globals()
140 {
141 global $pagenow; // Need this for comparisons.
142
143 do_action('ws_plugin__s2member_before_add_js_w_globals', get_defined_vars());
144
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')))
146 {
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;
154
155 if($static_js)
156 {
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 }
167 }
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']));
186 }
187
188 do_action('ws_plugin__s2member_during_add_js_w_globals', get_defined_vars());
189 }
190 do_action('ws_plugin__s2member_after_add_js_w_globals', get_defined_vars());
191 }
192
193 /**
194 * Disallow async loading.
195 *
196 * @package s2Member\CSS_JS
197 * @since 170221 Enhancing CloudFlare compat.
198 *
199 * @attaches-to ``add_filter('script_loader_tag');``
200 *
201 * @param string $tag The script tag.
202 * @param string $handle The script handle.
203 *
204 * @return string Possibly altered script tag.
205 */
206 public static function script_loader_tag($tag = '', $handle = '')
207 {
208 if (in_array($handle, array('ws-plugin--s2member', 'ws-plugin--s2member-pro'), TRUE)) {
209 $tag = str_replace(' src=', ' data-cfasync="false" src=', $tag);
210 }
211 return $tag; // Prevent RocketLoader from loading async.
212 // See: <https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-my-script-s-in-Automatic-Mode->
213 }
214 }
215 }
216