| 1 |
<?php |
| 2 |
/** |
| 3 |
* TablePress environment compatibility check. |
| 4 |
* |
| 5 |
* Note: This file must not contain PHP code that does not run on PHP < 7.4! |
| 6 |
* |
| 7 |
* @package TablePress |
| 8 |
* @author Tobias Bäthge |
| 9 |
* @since 2.2.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Prohibit direct script loading. |
| 13 |
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 14 |
|
| 15 |
/** |
| 16 |
* Check if the site is using WordPress 6.2 or newer. |
| 17 |
*/ |
| 18 |
// Include an unmodified $wp_version. |
| 19 |
require ABSPATH . WPINC . '/version.php'; // @phpstan-ignore require.fileNotFound (This is a WordPress core file that always exists.) |
| 20 |
if ( version_compare( str_replace( '-src', '', $wp_version ), '6.2', '<' ) ) { // @phpstan-ignore variable.undefined ($wp_version is a global variable, defined in the included file.) |
| 21 |
/** |
| 22 |
* Show an error notice to admins, if the installed version of WordPress is not supported. |
| 23 |
* |
| 24 |
* @since 2.2.0 |
| 25 |
* |
| 26 |
* @phpstan-ignore missingType.return |
| 27 |
*/ |
| 28 |
function tablepress_admin_error_notice_minimum_version_wp() /* No return type declaration, due to required PHP compatibility! */ { |
| 29 |
?> |
| 30 |
<div class="notice notice-error notice-alt notice-large"> |
| 31 |
<h3><em> |
| 32 |
<span aria-hidden="true" class="dashicons dashicons-warning" style="color:#d63638;vertical-align:bottom"></span> |
| 33 |
<?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?> |
| 34 |
</em></h3> |
| 35 |
<p style="font-size:14px"> |
| 36 |
<?php _e( 'The installed version of WordPress is too old for the TablePress plugin! TablePress requires an up-to-date version!', 'tablepress' ); ?> |
| 37 |
</p> |
| 38 |
<p style="font-size:14px"> |
| 39 |
<strong> |
| 40 |
<?php |
| 41 |
if ( current_user_can( 'update_core' ) ) { |
| 42 |
printf( __( 'Please <a href="%1$s">update your WordPress installation</a> to at least version %2$s!', 'tablepress' ), esc_url( self_admin_url( 'update-core.php' ) ), '6.2' ); |
| 43 |
} else { |
| 44 |
printf( __( 'Please ask your site’s administrator to update WordPress to at least version %1$s!', 'tablepress' ), '6.2' ); |
| 45 |
} |
| 46 |
?> |
| 47 |
</strong> |
| 48 |
</p> |
| 49 |
</div> |
| 50 |
<?php |
| 51 |
} |
| 52 |
add_action( 'admin_notices', 'tablepress_admin_error_notice_minimum_version_wp' ); |
| 53 |
|
| 54 |
// Exit TablePress early. |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Check if the server is running PHP 7.4 or newer. |
| 60 |
*/ |
| 61 |
if ( PHP_VERSION_ID < 70400 ) { // @phpstan-ignore smaller.alwaysFalse (PHPStan thinks that the Composer minimum version will always be fulfilled.) |
| 62 |
/** |
| 63 |
* Show an error notice to admins, if the installed version of PHP is not supported. |
| 64 |
* |
| 65 |
* @since 2.2.0 |
| 66 |
* |
| 67 |
* @phpstan-ignore missingType.return |
| 68 |
*/ |
| 69 |
function tablepress_admin_error_notice_minimum_version_php() /* No return type declaration, due to required PHP compatibility! */ { |
| 70 |
?> |
| 71 |
<div class="notice notice-error notice-alt notice-large"> |
| 72 |
<h3><em> |
| 73 |
<span aria-hidden="true" class="dashicons dashicons-warning" style="color:#d63638;vertical-align:bottom"></span> |
| 74 |
<?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?> |
| 75 |
</em></h3> |
| 76 |
<p style="font-size:14px"> |
| 77 |
<?php printf( __( 'Your server is running a version of PHP that is too old for the TablePress plugin to work. TablePress requires PHP %s or newer, where newer versions are recommended.', 'tablepress' ), '7.4' ); ?> |
| 78 |
</p> |
| 79 |
<p style="font-size:14px"> |
| 80 |
<strong><?php printf( __( '<a href="%s">Learn more about updating PHP</a> or contact your server administrator.', 'tablepress' ), esc_url( wp_get_update_php_url() ) ); ?></strong> |
| 81 |
</p> |
| 82 |
</div> |
| 83 |
<?php |
| 84 |
} |
| 85 |
add_action( 'admin_notices', 'tablepress_admin_error_notice_minimum_version_php' ); |
| 86 |
|
| 87 |
// Exit TablePress early. |
| 88 |
return false; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Turns off Elementor's element caching if used as the callback for the `pre_option_elementor_experiment-e_element_cache` filter hook. |
| 93 |
* |
| 94 |
* @since 3.0.0 |
| 95 |
* |
| 96 |
* @param string $value The value to return for the option. |
| 97 |
* @param string $option The option name. |
| 98 |
* @param string $default_value The default value for the option. |
| 99 |
* @return string The value to return for the option. |
| 100 |
*/ |
| 101 |
function tablepress_turn_off_elementor_element_caching( $value, /* string */ $option, $default_value ) /* No return type declaration, due to required PHP compatibility! */ { |
| 102 |
// Don't use type hints in the function declaration, due to required PHP compatibility of this file! |
| 103 |
return 'inactive'; |
| 104 |
} |
| 105 |
|
| 106 |
// Turn off Elementor's Element Caching as it breaks the loading of CSS and JS files. |
| 107 |
add_filter( 'pre_option_elementor_experiment-e_element_cache', 'tablepress_turn_off_elementor_element_caching', 10, 3 ); |
| 108 |
|
| 109 |
// All environment checks passed. |
| 110 |
return true; |
| 111 |
|