PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / trunk
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions vtrunk
260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 120301 All 187 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 trunk, at src/includes/classes/css-js-themes.inc.php

198 lines 8.2 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-lightweight' : 'dynamic-wordpress';
108 wp_enqueue_style('ws-plugin--s2member', $dynamic_css_url, array(), c_ws_plugin__s2member_utilities::ver_checksum(), 'all');
109 c_ws_plugin__s2member_utils_assets::register_page_asset_expectations('', 'css', $dynamic_css_url, $dynamic_css_delivery);
110 }
111
112 //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.
113 do_action('ws_plugin__s2member_during_add_css', get_defined_vars());
114 }
115 do_action('ws_plugin__s2member_after_add_css', get_defined_vars());
116 }
117
118 /**
119 * Enqueues JS file for theme integration.
120 *
121 * Be sure s2Member's API Constants are already defined before firing this.
122 *
123 * @package s2Member\CSS_JS
124 * @since 3.5
125 *
126 * @attaches-to ``add_action('wp_print_scripts');``
127 *
128 * @return null After enqueuing JS for theme integration.
129 */
130 public static function add_js_w_globals()
131 {
132 global $pagenow; // Need this for comparisons.
133
134 do_action('ws_plugin__s2member_before_add_js_w_globals', get_defined_vars());
135
136 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')))
137 {
138 $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();
139 $static_js = !empty($static['ok']) && !empty($static['assets']);
140 $page_text = c_ws_plugin__s2member_utils_assets::static_js_text_delivery() === 'page';
141 $static_inline_js = ($static_js && $page_text) ? c_ws_plugin__s2member_utils_assets::static_js_inline_data($static['assets']) : '';
142 if($static_js && $page_text && $static_inline_js === '')
143 $static_js = FALSE; //260906.2049 Page-loaded JavaScript text requires the matching shipped data map before slot-based static JavaScript can be used.
144 $dynamic_js = !$static_js;
145
146 if($static_js)
147 {
148 $dependency = array('jquery');
149 foreach($static['assets'] as $id => $asset)
150 {
151 $handle = ($id === 's2member-pro.js') ? 'ws-plugin--s2member-pro' : 'ws-plugin--s2member';
152 wp_enqueue_script($handle, $asset['url'], $dependency, NULL, TRUE);
153 if($handle === 'ws-plugin--s2member')
154 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');
155 c_ws_plugin__s2member_utils_assets::register_page_asset_expectations($id, 'js', $asset['url'], 'static', $asset['build']);
156 $dependency = array($handle);
157 }
158 }
159 else
160 {
161 //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.
162 $dynamic_asset_url = c_ws_plugin__s2member_utils_assets::dynamic_asset_url(!empty($GLOBALS['WS_PLUGIN__']['s2member']['o']['static_js']));
163 $dynamic_js_value = (is_user_logged_in()) ? WS_PLUGIN__S2MEMBER_API_CONSTANTS_MD5 : '1';
164 $dynamic_js_url = $dynamic_asset_url.'?ws_plugin__s2member_js_w_globals='.urlencode($dynamic_js_value).'&qcABC=1';
165 $dynamic_js_delivery = (strpos($dynamic_js_url, $GLOBALS['WS_PLUGIN__']['s2member']['c']['s2o_url'].'?') === 0) ? 'dynamic-lightweight' : 'dynamic-wordpress';
166 wp_enqueue_script('ws-plugin--s2member', $dynamic_js_url, array('jquery'), c_ws_plugin__s2member_utilities::ver_checksum(), TRUE);
167 c_ws_plugin__s2member_utils_assets::register_page_asset_expectations('', 'js', $dynamic_js_url, $dynamic_js_delivery);
168 }
169
170 do_action('ws_plugin__s2member_during_add_js_w_globals', get_defined_vars());
171 }
172 do_action('ws_plugin__s2member_after_add_js_w_globals', get_defined_vars());
173 }
174
175 /**
176 * Disallow async loading.
177 *
178 * @package s2Member\CSS_JS
179 * @since 170221 Enhancing CloudFlare compat.
180 *
181 * @attaches-to ``add_filter('script_loader_tag');``
182 *
183 * @param string $tag The script tag.
184 * @param string $handle The script handle.
185 *
186 * @return string Possibly altered script tag.
187 */
188 public static function script_loader_tag($tag = '', $handle = '')
189 {
190 if (in_array($handle, array('ws-plugin--s2member', 'ws-plugin--s2member-pro'), TRUE)) {
191 $tag = str_replace(' src=', ' data-cfasync="false" src=', $tag);
192 }
193 return $tag; // Prevent RocketLoader from loading async.
194 // See: <https://support.cloudflare.com/hc/en-us/articles/200169436-How-can-I-have-Rocket-Loader-ignore-my-script-s-in-Automatic-Mode->
195 }
196 }
197 }
198