PluginProbe
TablePress – Tables in WordPress made easy / 3.0.4
TablePress – Tables in WordPress made easy v3.0.4
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | classes/class-css.php +27 -33 2.0.43.0.4 View file →
@@ -28,15 +28,13 @@
28 28 *
29 29 * @param string $css CSS code.
30 30 * @return string Sanitized and tidied CSS code.
31 31 */
32 - public function sanitize_css( $css ) {
32 + public function sanitize_css( string $css ): string {
33 33 $csstidy = TablePress::load_class( 'TablePress_CSSTidy', 'class.csstidy.php', 'libraries/csstidy' );
34 34
35 35 // Sanitization and not just tidying for users without enough privileges.
36 36 if ( ! current_user_can( 'unfiltered_html' ) ) {
37 - $csstidy->optimise = new TablePress_CSSTidy_optimise( $csstidy );
38 -
39 37 // Let "arrows" survive, otherwise this might be recognized as the beginning of an HTML tag and removed with other stuff behind it.
40 38 $css = str_replace( '<=', '&lt;=', $css );
41 39 // Remove all HTML tags.
42 40 $css = wp_kses( $css, 'strip' );
@@ -74,11 +72,10 @@
74 72 *
75 73 * @param string $css CSS code.
76 74 * @return string Minified CSS code.
77 75 */
78 - public function minify_css( $css ) {
76 + public function minify_css( string $css ): string {
79 77 $csstidy = TablePress::load_class( 'TablePress_CSSTidy', 'class.csstidy.php', 'libraries/csstidy' );
80 - $csstidy->optimise = new TablePress_CSSTidy_optimise( $csstidy );
81 78 $csstidy->set_cfg( 'remove_bslash', false );
82 79 $csstidy->set_cfg( 'compress_colors', true );
83 80 $csstidy->set_cfg( 'compress_font-weight', true );
84 81 $csstidy->set_cfg( 'lowercase_s', false );
@@ -95,9 +92,12 @@
95 92 $csstidy->set_cfg( 'timestamp', false );
96 93 $csstidy->set_cfg( 'template', 'highest' );
97 94
98 95 $csstidy->parse( $css );
99 - return $csstidy->print->plain();
96 + $css = $csstidy->print->plain();
97 +
98 + // Remove all CSS comments from the minified CSS code, as CSSTidy does not remove those inside a CSS selector.
99 + return preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/\n?!', '', $css );
100 100 }
101 101
102 102 /**
103 103 * Get the location (file path or URL) of the "Custom CSS" file, depending on whether it's a Multisite install or not.
@@ -107,9 +107,9 @@
107 107 * @param string $type "normal" version, "minified" version, or "combined" (with TablePress Default CSS) version.
108 108 * @param string $location "path" or "url", for file path or URL.
109 109 * @return string Full file path or full URL for the "Custom CSS" file.
110 110 */
111 - public function get_custom_css_location( $type, $location ) {
111 + public function get_custom_css_location( string $type, string $location ): string {
112 112 switch ( $type ) {
113 113 case 'combined':
114 114 $file = 'tablepress-combined.min.css';
115 115 break;
@@ -176,18 +176,18 @@
176 176 *
177 177 * @param string $type Optional. Whether to load "normal" version or "minified" version. Default "normal".
178 178 * @return string|false Custom CSS on success, false on error.
179 179 */
180 - public function load_custom_css_from_file( $type = 'normal' ) {
180 + public function load_custom_css_from_file( string $type = 'normal' ) /* : string|false */ {
181 181 $filename = $this->get_custom_css_location( $type, 'path' );
182 182 // Check if file name is valid (0 means yes).
183 183 if ( 0 !== validate_file( $filename ) ) {
184 184 return false;
185 185 }
186 - if ( ! @is_file( $filename ) ) {
186 + if ( ! @is_file( $filename ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
187 187 return false;
188 188 }
189 - if ( ! @is_readable( $filename ) ) {
189 + if ( ! @is_readable( $filename ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
190 190 return false;
191 191 }
192 192 return file_get_contents( $filename );
193 193 }
@@ -201,9 +201,9 @@
201 201 *
202 202 * @param bool $load_rtl Optional. Whether to load LTR or RTL version. Default LTR.
203 203 * @return string|false TablePress Default CSS on success, false on error.
204 204 */
205 - public function load_default_css_from_file( $load_rtl = false ) {
205 + public function load_default_css_from_file( bool $load_rtl = false ) /* : string|false */ {
206 206 $rtl = $load_rtl ? '-rtl' : '';
207 207 $filename = TABLEPRESS_ABSPATH . "css/build/default{$rtl}.css";
208 208 // Check if file name is valid (0 means yes).
209 209 if ( 0 !== validate_file( $filename ) ) {
@@ -208,12 +208,12 @@
208 208 // Check if file name is valid (0 means yes).
209 209 if ( 0 !== validate_file( $filename ) ) {
210 210 return false;
211 211 }
212 - if ( ! @is_file( $filename ) ) {
212 + if ( ! @is_file( $filename ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
213 213 return false;
214 214 }
215 - if ( ! @is_readable( $filename ) ) {
215 + if ( ! @is_readable( $filename ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
216 216 return false;
217 217 }
218 218 return file_get_contents( $filename );
219 219 }
@@ -226,9 +226,9 @@
226 226 * @param string $custom_css_normal Custom CSS code to be saved.
227 227 * @param string $custom_css_minified Minified CSS code to be saved.
228 228 * @return bool True on success, false on failure.
229 229 */
230 - public function save_custom_css_to_file( $custom_css_normal, $custom_css_minified ) {
230 + public function save_custom_css_to_file( string $custom_css_normal, string $custom_css_minified ): bool {
231 231 /**
232 232 * Filters whether the "Custom CSS" code shall be saved to a file on the server.
233 233 *
234 234 * @since 1.1.0
@@ -246,9 +246,9 @@
246 246 /*
247 247 * Do we have credentials already? (Otherwise the form will have been rendered, which is not supported here.)
248 248 * Or, if we have credentials, are they valid?
249 249 */
250 - if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
250 + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { // @phpstan-ignore argument.type
251 251 ob_end_clean();
252 252 return false;
253 253 }
254 254
@@ -266,9 +266,9 @@
266 266 * @param string $custom_css_normal Custom CSS code to be saved. If empty, files will be deleted.
267 267 * @param string $custom_css_minified Minified CSS code to be saved.
268 268 * @return bool|string True on success, false on failure, or string of HTML for the credentials form for the WP_Filesystem API, if necessary.
269 269 */
270 - public function save_custom_css_to_file_plugin_options( $custom_css_normal, $custom_css_minified ) {
270 + public function save_custom_css_to_file_plugin_options( string $custom_css_normal, string $custom_css_minified ) /* : bool|string */ {
271 271 /** This filter is documented in classes/class-css.php */
272 272 if ( ! apply_filters( 'tablepress_save_custom_css_to_file', true ) ) {
273 273 return false;
274 274 }
@@ -278,18 +278,18 @@
278 278 $credentials = request_filesystem_credentials( '', '', false, '', null, false );
279 279 // Do we have credentials already? Otherwise the form will have been rendered already.
280 280 if ( false === $credentials ) {
281 281 $form_data = ob_get_clean();
282 - $form_data = str_replace( 'name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="button button-primary button-large"', $form_data );
282 + $form_data = str_replace( 'name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="components-button is-primary"', $form_data ); // @phpstan-ignore argument.type
283 283 return $form_data;
284 284 }
285 285
286 286 // We have received credentials, but don't know if they are valid yet.
287 - if ( ! WP_Filesystem( $credentials ) ) {
287 + if ( ! WP_Filesystem( $credentials ) ) { // @phpstan-ignore argument.type
288 288 // Credentials failed, so ask again (with $error flag true).
289 289 request_filesystem_credentials( '', '', true, '', null, false );
290 290 $form_data = ob_get_clean();
291 - $form_data = str_replace( 'name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="button button-primary button-large"', $form_data );
291 + $form_data = str_replace( 'name="upgrade" id="upgrade" class="button"', 'name="upgrade" id="upgrade" class="components-button is-primary"', $form_data ); // @phpstan-ignore argument.type
292 292 return $form_data;
293 293 }
294 294
295 295 // We have valid access to the filesystem now -> try to save the files, or delete them if the "Custom CSS" is empty.
@@ -314,9 +314,9 @@
314 314 * @param string $custom_css_normal Custom CSS code to be saved.
315 315 * @param string $custom_css_minified Minified CSS code to be saved.
316 316 * @return bool True on success, false on failure.
317 317 */
318 - protected function _custom_css_save_helper( $custom_css_normal, $custom_css_minified ) {
318 + protected function _custom_css_save_helper( string $custom_css_normal, string $custom_css_minified ): bool {
319 319 global $wp_filesystem;
320 320
321 321 /*
322 322 * WP_CONTENT_DIR and (FTP-)Content-Dir can be different (e.g. if FTP working dir is /).
@@ -328,14 +328,8 @@
328 328
329 329 $default_css_minified = $this->load_default_css_from_file( false );
330 330 if ( false === $default_css_minified ) {
331 331 $default_css_minified = '';
332 - } else {
333 - // Change relative URLs to web font files to absolute URLs, as combining the CSS files and saving to another directory breaks the relative URLs.
334 - $absolute_path = plugins_url( 'css/build/tablepress.', TABLEPRESS__FILE__ );
335 - // Make the absolute URL protocol-relative to prevent mixed content warnings.
336 - $absolute_path = str_replace( array( 'http:', 'https:' ), '', $absolute_path );
337 - $default_css_minified = str_replace( 'url(tablepress.', 'url(' . $absolute_path, $default_css_minified );
338 332 }
339 333 $file_content = array(
340 334 'normal' => $custom_css_normal,
341 335 'minified' => $custom_css_minified,
@@ -368,9 +362,9 @@
368 362 * @since 1.0.0
369 363 *
370 364 * @return bool True on success, false on failure.
371 365 */
372 - public function delete_custom_css_files() {
366 + public function delete_custom_css_files(): bool {
373 367 // Start capturing the output, to later prevent it.
374 368 ob_start();
375 369 $credentials = request_filesystem_credentials( '', '', false, '', null, false );
376 370
@@ -377,9 +371,9 @@
377 371 /*
378 372 * Do we have credentials already? (Otherwise the form will have been rendered, which is not supported here.)
379 373 * Or, if we have credentials, are they valid?
380 374 */
381 - if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
375 + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { // @phpstan-ignore argument.type
382 376 ob_end_clean();
383 377 return false;
384 378 }
385 379
@@ -399,9 +393,9 @@
399 393 * @see save_custom_css_to_file_plugin_options()
400 394 *
401 395 * @return bool True on success, false on failure.
402 396 */
403 - protected function _custom_css_delete_helper() {
397 + protected function _custom_css_delete_helper(): bool {
404 398 global $wp_filesystem;
405 399
406 400 /*
407 401 * WP_CONTENT_DIR and (FTP-)Content-Dir can be different (e.g. if FTP working dir is /).
@@ -433,13 +427,13 @@
433 427 return $total_result;
434 428 }
435 429
436 430 /**
437 - * Flush the CSS minification cache of W3 Total Cache.
431 + * Flush the CSS minification caches of common caching plugins.
438 432 *
439 433 * @since 1.4.0
440 434 */
441 - protected function _flush_caching_plugins_css_minify_caches() {
435 + protected function _flush_caching_plugins_css_minify_caches(): void {
442 436 /** This filter is documented in models/model-table.php */
443 437 if ( ! apply_filters( 'tablepress_flush_caching_plugins_caches', true ) ) {
444 438 return;
445 439 }
@@ -448,10 +442,10 @@
448 442 if ( function_exists( 'w3tc_minify_flush' ) ) {
449 443 w3tc_minify_flush();
450 444 }
451 445 // WP Fastest Cache.
452 - if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) {
453 - $GLOBALS['wp_fastest_cache']->deleteCache( true );
446 + if ( isset( $GLOBALS['wp_fastest_cache'] ) && is_callable( array( $GLOBALS['wp_fastest_cache'], 'deleteCache' ) ) ) {
447 + $GLOBALS['wp_fastest_cache']->deleteCache( true ); // @phpstan-ignore method.nonObject
454 448 }
455 449 }
456 450
457 451 } // class TablePress_CSS