| 1 |
<?php |
| 2 |
/** |
| 3 |
* TablePress Class |
| 4 |
* |
| 5 |
* @package TablePress |
| 6 |
* @author Tobias Bäthge |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
// Prohibit direct script loading. |
| 11 |
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| 12 |
|
| 13 |
/** |
| 14 |
* TablePress class |
| 15 |
* |
| 16 |
* @package TablePress |
| 17 |
* @author Tobias Bäthge |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
abstract class TablePress { |
| 21 |
|
| 22 |
/** |
| 23 |
* TablePress version. |
| 24 |
* |
| 25 |
* Increases whenever a new plugin version is released. |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
* @const string |
| 29 |
*/ |
| 30 |
public const version = '2.3'; // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
| 31 |
|
| 32 |
/** |
| 33 |
* TablePress internal plugin version ("options scheme" version). |
| 34 |
* |
| 35 |
* Increases whenever the scheme for the plugin options changes, or on a plugin update. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
* @const int |
| 39 |
*/ |
| 40 |
public const db_version = 75; // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
| 41 |
|
| 42 |
/** |
| 43 |
* TablePress "table scheme" (data format structure) version. |
| 44 |
* |
| 45 |
* Increases whenever the scheme for a $table changes, |
| 46 |
* used to be able to update plugin options and table scheme independently. |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* @const int |
| 50 |
*/ |
| 51 |
public const table_scheme_version = 3; // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
| 52 |
|
| 53 |
/** |
| 54 |
* Instance of the Options Model. |
| 55 |
* |
| 56 |
* @since 1.3.0 |
| 57 |
* @var TablePress_Options_Model |
| 58 |
*/ |
| 59 |
public static $model_options; |
| 60 |
|
| 61 |
/** |
| 62 |
* Instance of the Table Model. |
| 63 |
* |
| 64 |
* @since 1.3.0 |
| 65 |
* @var TablePress_Table_Model |
| 66 |
*/ |
| 67 |
public static $model_table; |
| 68 |
|
| 69 |
/** |
| 70 |
* Instance of the controller. |
| 71 |
* |
| 72 |
* @since 1.0.0 |
| 73 |
* @var TablePress_Frontend_Controller |
| 74 |
*/ |
| 75 |
public static $controller; |
| 76 |
|
| 77 |
/** |
| 78 |
* Name of the Shortcode to show a TablePress table. |
| 79 |
* |
| 80 |
* Should only be modified through the filter hook 'tablepress_table_shortcode'. |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
* @var string |
| 84 |
*/ |
| 85 |
public static $shortcode = 'table'; |
| 86 |
|
| 87 |
/** |
| 88 |
* Name of the Shortcode to show extra information of a TablePress table. |
| 89 |
* |
| 90 |
* Should only be modified through the filter hook 'tablepress_table_info_shortcode'. |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* @var string |
| 94 |
*/ |
| 95 |
public static $shortcode_info = 'table-info'; |
| 96 |
|
| 97 |
/** |
| 98 |
* List of TablePress premium modules. |
| 99 |
* |
| 100 |
* @since 2.1.0 |
| 101 |
* @var array<string, array{name: string, description: string, category: string, class: string, incompatible_classes: string[], minimum_plan: string, default_active: bool}> |
| 102 |
*/ |
| 103 |
public static $modules = array(); |
| 104 |
|
| 105 |
/** |
| 106 |
* Start-up TablePress (run on WordPress "init") and load the controller for the current state. |
| 107 |
* |
| 108 |
* @since 1.0.0 |
| 109 |
*/ |
| 110 |
public static function run(): void { |
| 111 |
/** |
| 112 |
* Fires before TablePress is loaded. |
| 113 |
* |
| 114 |
* The `tablepress_loaded` action hook might be a better choice in most situations, as TablePress options will then be available. |
| 115 |
* |
| 116 |
* @since 1.0.0 |
| 117 |
*/ |
| 118 |
do_action( 'tablepress_run' ); |
| 119 |
|
| 120 |
/** |
| 121 |
* Filters the string that is used as the [table] Shortcode. |
| 122 |
* |
| 123 |
* @since 1.0.0 |
| 124 |
* |
| 125 |
* @param string $shortcode The [table] Shortcode string. |
| 126 |
*/ |
| 127 |
self::$shortcode = apply_filters( 'tablepress_table_shortcode', self::$shortcode ); |
| 128 |
/** |
| 129 |
* Filters the string that is used as the [table-info] Shortcode. |
| 130 |
* |
| 131 |
* @since 1.0.0 |
| 132 |
* |
| 133 |
* @param string $shortcode_info The [table-info] Shortcode string. |
| 134 |
*/ |
| 135 |
self::$shortcode_info = apply_filters( 'tablepress_table_info_shortcode', self::$shortcode_info ); |
| 136 |
|
| 137 |
// Load modals for table and options, to be accessible from everywhere via `TablePress::$model_options` and `TablePress::$model_table`. |
| 138 |
self::$model_options = self::load_model( 'options' ); |
| 139 |
self::$model_table = self::load_model( 'table' ); |
| 140 |
|
| 141 |
// Exit early, i.e. before a controller is loaded, if TablePress functionality is likely not needed. |
| 142 |
$exit_early = false; |
| 143 |
if ( ( isset( $_SERVER['SCRIPT_FILENAME'] ) && 'wp-login.php' === basename( $_SERVER['SCRIPT_FILENAME'] ) ) // Detect the WordPress Login screen. |
| 144 |
|| ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
| 145 |
|| wp_doing_cron() ) { |
| 146 |
$exit_early = true; |
| 147 |
} |
| 148 |
/** |
| 149 |
* Filters whether TablePress should exit early, e.g. during wp-login.php, XML-RPC, and WP-Cron requests. |
| 150 |
* |
| 151 |
* @since 2.0.0 |
| 152 |
* |
| 153 |
* @param bool $exit_early Whether TablePress should exit early. |
| 154 |
*/ |
| 155 |
if ( apply_filters( 'tablepress_exit_early', $exit_early ) ) { |
| 156 |
return; |
| 157 |
} |
| 158 |
|
| 159 |
if ( is_admin() ) { |
| 160 |
$controller = 'admin'; |
| 161 |
if ( wp_doing_ajax() ) { |
| 162 |
$controller = 'admin_ajax'; |
| 163 |
} |
| 164 |
self::load_controller( $controller ); |
| 165 |
} |
| 166 |
// Load the frontend controller in all scenarios, so that Shortcode render functions are always available. |
| 167 |
self::$controller = self::load_controller( 'frontend' ); |
| 168 |
|
| 169 |
/** |
| 170 |
* Fires after TablePress is loaded. |
| 171 |
* |
| 172 |
* The `tablepress_run` action hook can be used if code has to run before TablePress is loaded. |
| 173 |
* |
| 174 |
* @since 2.0.0 |
| 175 |
*/ |
| 176 |
do_action( 'tablepress_loaded' ); |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Load a file with require_once(), after running it through a filter. |
| 181 |
* |
| 182 |
* @since 1.0.0 |
| 183 |
* |
| 184 |
* @param string $file Name of the PHP file. |
| 185 |
* @param string $folder Name of the folder with the file. |
| 186 |
*/ |
| 187 |
public static function load_file( string $file, string $folder ): void { |
| 188 |
$full_path = TABLEPRESS_ABSPATH . $folder . '/' . $file; |
| 189 |
/** |
| 190 |
* Filters the full path of a file that shall be loaded. |
| 191 |
* |
| 192 |
* @since 1.0.0 |
| 193 |
* |
| 194 |
* @param string $full_path Full path of the file that shall be loaded. |
| 195 |
* @param string $file File name of the file that shall be loaded. |
| 196 |
* @param string $folder Folder name of the file that shall be loaded. |
| 197 |
*/ |
| 198 |
$full_path = apply_filters( 'tablepress_load_file_full_path', $full_path, $file, $folder ); |
| 199 |
if ( $full_path ) { |
| 200 |
require_once $full_path; |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Create a new instance of the $class_name, which is stored in $file in the $folder subfolder |
| 206 |
* of the plugin's directory. |
| 207 |
* |
| 208 |
* @since 1.0.0 |
| 209 |
* |
| 210 |
* @param string $class_name Name of the class. |
| 211 |
* @param string $file Name of the PHP file with the class. |
| 212 |
* @param string $folder Name of the folder with $class_name's $file. |
| 213 |
* @param mixed[]|string|null $params Optional. Parameters that are passed to the constructor of $class_name. |
| 214 |
* @return object Initialized instance of the class. |
| 215 |
*/ |
| 216 |
public static function load_class( string $class_name, string $file, string $folder, /* ?array|string */ $params = null ): object { |
| 217 |
/** |
| 218 |
* Filters name of the class that shall be loaded. |
| 219 |
* |
| 220 |
* @since 1.0.0 |
| 221 |
* |
| 222 |
* @param string $class_name Name of the class that shall be loaded. |
| 223 |
*/ |
| 224 |
$class_name = apply_filters( 'tablepress_load_class_name', $class_name ); |
| 225 |
if ( ! class_exists( $class_name, false ) ) { |
| 226 |
self::load_file( $file, $folder ); |
| 227 |
} |
| 228 |
$the_class = new $class_name( $params ); |
| 229 |
return $the_class; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Create a new instance of the $model, which is stored in the "models" subfolder. |
| 234 |
* |
| 235 |
* @since 1.0.0 |
| 236 |
* |
| 237 |
* @param string $model Name of the model. |
| 238 |
* @return object Instance of the initialized model. |
| 239 |
*/ |
| 240 |
public static function load_model( string $model ): object { |
| 241 |
// Model Base Class. |
| 242 |
self::load_file( 'class-model.php', 'classes' ); |
| 243 |
// Make first letter uppercase for a better looking naming pattern. |
| 244 |
$ucmodel = ucfirst( $model ); |
| 245 |
$the_model = self::load_class( "TablePress_{$ucmodel}_Model", "model-{$model}.php", 'models' ); |
| 246 |
return $the_model; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Create a new instance of the $view, which is stored in the "views" subfolder, and set it up with $data. |
| 251 |
* |
| 252 |
* @since 1.0.0 |
| 253 |
* |
| 254 |
* @param string $view Name of the view to load. |
| 255 |
* @param array<string, mixed> $data Optional. Parameters/PHP variables that shall be available to the view. |
| 256 |
* @return object Instance of the initialized view, already set up, just needs to be rendered. |
| 257 |
*/ |
| 258 |
public static function load_view( string $view, array $data = array() ): object { |
| 259 |
// View Base Class. |
| 260 |
self::load_file( 'class-view.php', 'classes' ); |
| 261 |
// Make first letter uppercase for a better looking naming pattern. |
| 262 |
$ucview = ucfirst( $view ); |
| 263 |
$the_view = self::load_class( "TablePress_{$ucview}_View", "view-{$view}.php", 'views' ); |
| 264 |
$the_view->setup( $view, $data ); |
| 265 |
return $the_view; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Create a new instance of the $controller, which is stored in the "controllers" subfolder. |
| 270 |
* |
| 271 |
* @since 1.0.0 |
| 272 |
* |
| 273 |
* @param string $controller Name of the controller. |
| 274 |
* @return object Instance of the initialized controller. |
| 275 |
*/ |
| 276 |
public static function load_controller( string $controller ): object { |
| 277 |
// Controller Base Class. |
| 278 |
self::load_file( 'class-controller.php', 'classes' ); |
| 279 |
// Make first letter uppercase for a better looking naming pattern. |
| 280 |
$uccontroller = ucfirst( $controller ); |
| 281 |
$the_controller = self::load_class( "TablePress_{$uccontroller}_Controller", "controller-{$controller}.php", 'controllers' ); |
| 282 |
return $the_controller; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Generate the complete nonce string, from the nonce base, the action and an item, e.g. tablepress_delete_table_3. |
| 287 |
* |
| 288 |
* @since 1.0.0 |
| 289 |
* |
| 290 |
* @param string $action Action for which the nonce is needed. |
| 291 |
* @param string|false $item Optional. Item for which the action will be performed, like "table". false if no item should be used in the nonce. |
| 292 |
* @return string The resulting nonce string. |
| 293 |
*/ |
| 294 |
public static function nonce( string $action, /* string|false */ $item = false ): string { |
| 295 |
$nonce = "tablepress_{$action}"; |
| 296 |
if ( $item ) { |
| 297 |
$nonce .= "_{$item}"; |
| 298 |
} |
| 299 |
return $nonce; |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* Check whether a nonce string is valid. |
| 304 |
* |
| 305 |
* @since 1.0.0 |
| 306 |
* |
| 307 |
* @param string $action Action for which the nonce should be checked. |
| 308 |
* @param string|false $item Optional. Item for which the action should be performed, like "table". false if no item should be used in the nonce. |
| 309 |
* @param string $query_arg Optional. Name of the nonce query string argument in $_POST. |
| 310 |
* @param bool $ajax Whether the nonce comes from an AJAX request. |
| 311 |
*/ |
| 312 |
public static function check_nonce( string $action, /* string|false */ $item = false, string $query_arg = '_wpnonce', bool $ajax = false ): void { |
| 313 |
$nonce_action = self::nonce( $action, $item ); |
| 314 |
if ( $ajax ) { |
| 315 |
check_ajax_referer( $nonce_action, $query_arg ); |
| 316 |
} else { |
| 317 |
check_admin_referer( $nonce_action, $query_arg ); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Calculate the column index (number) of a column header string (example: A is 1, AA is 27, ...). |
| 323 |
* |
| 324 |
* For the opposite, @see number_to_letter(). |
| 325 |
* |
| 326 |
* @since 1.0.0 |
| 327 |
* |
| 328 |
* @param string $column Column string. |
| 329 |
* @return int Column number, 1-based. |
| 330 |
*/ |
| 331 |
public static function letter_to_number( string $column ): int { |
| 332 |
$column = strtoupper( $column ); |
| 333 |
$count = strlen( $column ); |
| 334 |
$number = 0; |
| 335 |
for ( $i = 0; $i < $count; $i++ ) { |
| 336 |
$number += ( ord( $column[ $count - 1 - $i ] ) - 64 ) * pow( 26, $i ); |
| 337 |
} |
| 338 |
return $number; |
| 339 |
} |
| 340 |
|
| 341 |
/** |
| 342 |
* "Calculate" the column header string of a column index (example: 2 is B, AB is 28, ...). |
| 343 |
* |
| 344 |
* For the opposite, @see letter_to_number(). |
| 345 |
* |
| 346 |
* @since 1.0.0 |
| 347 |
* |
| 348 |
* @param int $number Column number, 1-based. |
| 349 |
* @return string Column string. |
| 350 |
*/ |
| 351 |
public static function number_to_letter( int $number ): string { |
| 352 |
$column = ''; |
| 353 |
while ( $number > 0 ) { |
| 354 |
$column = chr( 65 + ( ( $number - 1 ) % 26 ) ) . $column; |
| 355 |
$number = intdiv( $number - 1, 26 ); |
| 356 |
} |
| 357 |
return $column; |
| 358 |
} |
| 359 |
|
| 360 |
/** |
| 361 |
* Get a nice looking date and time string from the mySQL format of datetime strings for output. |
| 362 |
* |
| 363 |
* @since 1.0.0 |
| 364 |
* |
| 365 |
* @param string $datetime_string DateTime string, often in mySQL format.. |
| 366 |
* @param string $separator_or_format Optional. Separator between date and time, or format string. |
| 367 |
* @return string Nice looking string with the date and time. |
| 368 |
*/ |
| 369 |
public static function format_datetime( string $datetime_string, string $separator_or_format = ' ' ): string { |
| 370 |
$timezone = wp_timezone(); |
| 371 |
$datetime = date_create( $datetime_string, $timezone ); |
| 372 |
$timestamp = $datetime->getTimestamp(); // @phpstan-ignore-line |
| 373 |
|
| 374 |
switch ( $separator_or_format ) { |
| 375 |
case ' ': |
| 376 |
case '<br />': |
| 377 |
$date = wp_date( get_option( 'date_format' ), $timestamp, $timezone ); |
| 378 |
$time = wp_date( get_option( 'time_format' ), $timestamp, $timezone ); |
| 379 |
$output = "{$date}{$separator_or_format}{$time}"; |
| 380 |
break; |
| 381 |
default: |
| 382 |
$output = (string) wp_date( $separator_or_format, $timestamp, $timezone ); |
| 383 |
break; |
| 384 |
} |
| 385 |
|
| 386 |
return $output; |
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Get the name from a WP user ID (used to store information on last editor of a table). |
| 391 |
* |
| 392 |
* @since 1.0.0 |
| 393 |
* |
| 394 |
* @param int $user_id WP user ID. |
| 395 |
* @return string Nickname of the WP user with the $user_id. |
| 396 |
*/ |
| 397 |
public static function get_user_display_name( int $user_id ): string { |
| 398 |
$user = get_userdata( $user_id ); |
| 399 |
return ( isset( $user->display_name ) ) ? $user->display_name : sprintf( '<em>%s</em>', __( 'unknown', 'tablepress' ) ); |
| 400 |
} |
| 401 |
|
| 402 |
/** |
| 403 |
* Sanitizes a CSS class to ensure it only contains valid characters. |
| 404 |
* |
| 405 |
* Strips the string down to A-Z, a-z, 0-9, :, _, -. |
| 406 |
* This is an extension to WP's `sanitize_html_class()`, to also allow `:` which are used in some CSS frameworks. |
| 407 |
* |
| 408 |
* @since 1.11.0 |
| 409 |
* |
| 410 |
* @param string $css_class The CSS class name to be sanitized. |
| 411 |
* @return string The sanitized CSS class. |
| 412 |
*/ |
| 413 |
public static function sanitize_css_class( string $css_class ): string { |
| 414 |
// Strip out any %-encoded octets. |
| 415 |
$sanitized_css_class = (string) preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $css_class ); |
| 416 |
// Limit to A-Z, a-z, 0-9, ':', '_', and '-'. |
| 417 |
$sanitized_css_class = (string) preg_replace( '/[^A-Za-z0-9:_-]/', '', $sanitized_css_class ); |
| 418 |
return $sanitized_css_class; |
| 419 |
} |
| 420 |
|
| 421 |
/** |
| 422 |
* Retrieves all information of a WP_Error object as a string. |
| 423 |
* |
| 424 |
* @since 1.4.0 |
| 425 |
* |
| 426 |
* @param WP_Error $wp_error A WP_Error object. |
| 427 |
* @return string All error codes, messages, and data of the WP_Error. |
| 428 |
*/ |
| 429 |
public static function get_wp_error_string( WP_Error $wp_error ): string { |
| 430 |
$error_strings = array(); |
| 431 |
$error_codes = $wp_error->get_error_codes(); |
| 432 |
// Reverse order to get latest errors first. |
| 433 |
$error_codes = array_reverse( $error_codes ); |
| 434 |
foreach ( $error_codes as $error_code ) { |
| 435 |
$error_strings[ $error_code ] = $error_code; |
| 436 |
$error_messages = $wp_error->get_error_messages( $error_code ); |
| 437 |
$error_messages = implode( ', ', $error_messages ); |
| 438 |
if ( ! empty( $error_messages ) ) { |
| 439 |
$error_strings[ $error_code ] .= " ({$error_messages})"; |
| 440 |
} |
| 441 |
$error_data = $wp_error->get_error_data( $error_code ); |
| 442 |
if ( is_string( $error_data ) ) { |
| 443 |
$error_strings[ $error_code ] .= " [{$error_data}]"; |
| 444 |
} elseif ( is_array( $error_data ) ) { |
| 445 |
foreach ( $error_data as $key => $value ) { |
| 446 |
$error_data[ $key ] = "{$key}: {$value}"; |
| 447 |
} |
| 448 |
$error_data = implode( ', ', $error_data ); |
| 449 |
$error_strings[ $error_code ] .= " [{$error_data}]"; |
| 450 |
} |
| 451 |
} |
| 452 |
return implode( ";\n", $error_strings ); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Generate the action URL, to be used as a link within the plugin (e.g. in the submenu navigation or List of Tables). |
| 457 |
* |
| 458 |
* @since 1.0.0 |
| 459 |
* |
| 460 |
* @param array<string, mixed> $params Optional. Parameters to form the query string of the URL. |
| 461 |
* @param bool $add_nonce Optional. Whether the URL shall be nonced by WordPress. |
| 462 |
* @param string $target Optional. Target File, e.g. "admin-post.php" for POST requests. |
| 463 |
* @return string The URL for the given parameters (already run through esc_url() with $add_nonce === true!). |
| 464 |
*/ |
| 465 |
public static function url( array $params = array(), bool $add_nonce = false, string $target = '' ): string { |
| 466 |
// Default action is "list", if no action given. |
| 467 |
if ( ! isset( $params['action'] ) ) { |
| 468 |
$params['action'] = 'list'; |
| 469 |
} |
| 470 |
$nonce_action = $params['action']; |
| 471 |
|
| 472 |
if ( '' !== $target ) { |
| 473 |
$params['action'] = "tablepress_{$params['action']}"; |
| 474 |
} else { |
| 475 |
$params['page'] = 'tablepress'; |
| 476 |
// Top-level parent page needs special treatment for better action strings. |
| 477 |
if ( self::$controller->is_top_level_page ) { |
| 478 |
$target = 'admin.php'; |
| 479 |
if ( ! in_array( $params['action'], array( 'list', 'edit' ), true ) ) { |
| 480 |
$params['page'] = "tablepress_{$params['action']}"; |
| 481 |
} |
| 482 |
if ( ! in_array( $params['action'], array( 'edit' ), true ) ) { |
| 483 |
$params['action'] = false; |
| 484 |
} |
| 485 |
} else { |
| 486 |
$target = self::$controller->parent_page; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
// $default_params also determines the order of the values in the query string. |
| 491 |
$default_params = array( |
| 492 |
'page' => false, |
| 493 |
'action' => false, |
| 494 |
'item' => false, |
| 495 |
); |
| 496 |
$params = array_merge( $default_params, $params ); |
| 497 |
|
| 498 |
$url = add_query_arg( $params, admin_url( $target ) ); |
| 499 |
if ( $add_nonce ) { |
| 500 |
$url = wp_nonce_url( $url, self::nonce( $nonce_action, $params['item'] ) ); // wp_nonce_url() does esc_html(). |
| 501 |
} |
| 502 |
return $url; |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* Create a redirect URL from the $target_parameters and redirect the user. |
| 507 |
* |
| 508 |
* @since 1.0.0 |
| 509 |
* |
| 510 |
* @param array<string, mixed> $params Optional. Parameters from which the target URL is constructed. |
| 511 |
* @param bool $add_nonce Optional. Whether the URL shall be nonced by WordPress. |
| 512 |
*/ |
| 513 |
public static function redirect( array $params = array(), bool $add_nonce = false ): void { |
| 514 |
$redirect = self::url( $params ); |
| 515 |
if ( $add_nonce ) { |
| 516 |
if ( ! isset( $params['item'] ) ) { |
| 517 |
$params['item'] = false; |
| 518 |
} |
| 519 |
// Don't use wp_nonce_url(), as that uses esc_html(). |
| 520 |
$redirect = add_query_arg( '_wpnonce', wp_create_nonce( self::nonce( $params['action'], $params['item'] ) ), $redirect ); |
| 521 |
} |
| 522 |
wp_redirect( $redirect ); |
| 523 |
exit; |
| 524 |
} |
| 525 |
|
| 526 |
/** |
| 527 |
* Determines whether the site uses the block editor, so that certain text and input fields referring to Shortcodes can be displayed or not. |
| 528 |
* |
| 529 |
* @since 2.0.1 |
| 530 |
* |
| 531 |
* @return bool True if the site uses the block editor, false otherwise. |
| 532 |
*/ |
| 533 |
public static function site_uses_block_editor(): bool { |
| 534 |
$site_uses_block_editor = use_block_editor_for_post_type( 'post' ) |
| 535 |
&& ! is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) |
| 536 |
&& ! is_plugin_active( 'classic-editor/classic-editor.php' ) |
| 537 |
&& ! is_plugin_active( 'classic-editor-addon/classic-editor-addon.php' ) |
| 538 |
&& ! is_plugin_active( 'elementor/elementor.php' ) |
| 539 |
&& ! is_plugin_active( 'siteorigin-panels/siteorigin-panels.php' ); |
| 540 |
|
| 541 |
/** |
| 542 |
* Filters the outcome of the check whether the site uses the block editor. |
| 543 |
* |
| 544 |
* This can be used when certain conditions (e.g. new site builders) are not (yet) accounted for. |
| 545 |
* |
| 546 |
* @since 2.0.1 |
| 547 |
* |
| 548 |
* @param bool $site_uses_block_editor True if the site uses the block editor, false otherwise. |
| 549 |
*/ |
| 550 |
$site_uses_block_editor = (bool) apply_filters( 'tablepress_site_uses_block_editor', $site_uses_block_editor ); |
| 551 |
|
| 552 |
return $site_uses_block_editor; |
| 553 |
} |
| 554 |
|
| 555 |
/** |
| 556 |
* Initializes the list of TablePress premium modules. |
| 557 |
* |
| 558 |
* @since 2.1.0 |
| 559 |
*/ |
| 560 |
public static function init_modules(): void { |
| 561 |
self::$modules = array( |
| 562 |
'advanced-access-rights' => array( |
| 563 |
'name' => __( 'Advanced Access Rights', 'tablepress' ), |
| 564 |
'description' => __( 'Restrict access to individual tables for individual users.', 'tablepress' ), |
| 565 |
'category' => 'backend', |
| 566 |
'class' => 'TablePress_Module_Advanced_Access_Rights', |
| 567 |
'incompatible_classes' => array( 'TablePress_Advanced_Access_Rights_Controller' ), |
| 568 |
'minimum_plan' => 'max', |
| 569 |
'default_active' => false, |
| 570 |
), |
| 571 |
'automatic-periodic-table-import' => array( |
| 572 |
'name' => __( 'Automatic Periodic Table Import', 'tablepress' ), |
| 573 |
'description' => __( 'Periodically update tables from a configured import source.', 'tablepress' ), |
| 574 |
'category' => 'backend', |
| 575 |
'class' => 'TablePress_Module_Automatic_Periodic_Table_Import', |
| 576 |
'incompatible_classes' => array( 'TablePress_Table_Auto_Update' ), |
| 577 |
'minimum_plan' => 'max', |
| 578 |
'default_active' => true, |
| 579 |
), |
| 580 |
'automatic-table-export' => array( |
| 581 |
'name' => __( 'Automatic Table Export', 'tablepress' ), |
| 582 |
'description' => __( 'Export and save tables to files on the server after they were modified.', 'tablepress' ), |
| 583 |
'category' => 'backend', |
| 584 |
'class' => 'TablePress_Module_Automatic_Table_Export', |
| 585 |
'incompatible_classes' => array(), |
| 586 |
'minimum_plan' => 'pro', |
| 587 |
'default_active' => false, |
| 588 |
), |
| 589 |
'cell-highlighting' => array( |
| 590 |
'name' => __( 'Cell Highlighting', 'tablepress' ), |
| 591 |
'description' => __( 'Add CSS classes to cells for highlighting based on their content.', 'tablepress' ), |
| 592 |
'category' => 'frontend', |
| 593 |
'class' => 'TablePress_Module_Cell_Highlighting', |
| 594 |
'incompatible_classes' => array( 'TablePress_Cell_Highlighting' ), |
| 595 |
'minimum_plan' => 'pro', |
| 596 |
'default_active' => false, |
| 597 |
), |
| 598 |
'column-order' => array( |
| 599 |
'name' => __( 'Column Order', 'tablepress' ), |
| 600 |
'description' => __( 'Order the columns in different ways when a table is shown.', 'tablepress' ), |
| 601 |
'category' => 'data-management', |
| 602 |
'class' => 'TablePress_Module_Column_Order', |
| 603 |
'incompatible_classes' => array( 'TablePress_Column_Order' ), |
| 604 |
'minimum_plan' => 'pro', |
| 605 |
'default_active' => false, |
| 606 |
), |
| 607 |
'datatables-advanced-loading' => array( |
| 608 |
'name' => __( 'Advanced Loading', 'tablepress' ), |
| 609 |
'description' => __( 'Load the table data from a JSON array for faster loading.', 'tablepress' ), |
| 610 |
'category' => 'backend', |
| 611 |
'class' => 'TablePress_Module_DataTables_Advanced_Loading', |
| 612 |
'incompatible_classes' => array( 'TablePress_DataTables_Advanced_Loading' ), |
| 613 |
'minimum_plan' => 'max', |
| 614 |
'default_active' => false, |
| 615 |
), |
| 616 |
'datatables-alphabetsearch' => array( |
| 617 |
'name' => __( 'Alphabet Search', 'tablepress' ), |
| 618 |
'description' => __( 'Show Alphabet buttons above the table to filter rows by their first letter.', 'tablepress' ), |
| 619 |
'category' => 'search-filter', |
| 620 |
'class' => 'TablePress_Module_DataTables_Alphabetsearch', |
| 621 |
'incompatible_classes' => array(), |
| 622 |
'minimum_plan' => 'pro', |
| 623 |
'default_active' => false, |
| 624 |
), |
| 625 |
'datatables-auto-filter' => array( |
| 626 |
'name' => __( 'Automatic Filter', 'tablepress' ), |
| 627 |
'description' => __( 'Pre-filter a table when it is shown.', 'tablepress' ), |
| 628 |
'category' => 'search-filter', |
| 629 |
'class' => 'TablePress_Module_DataTables_Auto_Filter', |
| 630 |
'incompatible_classes' => array( 'TablePress_DataTables_Auto_Filter' ), |
| 631 |
'minimum_plan' => 'pro', |
| 632 |
'default_active' => false, |
| 633 |
), |
| 634 |
'datatables-buttons' => array( |
| 635 |
'name' => __( 'Buttons', 'tablepress' ), |
| 636 |
'description' => __( 'Add buttons for downloading, copying, printing, and changing column visibility of tables.', 'tablepress' ), |
| 637 |
'category' => 'frontend', |
| 638 |
'class' => 'TablePress_Module_DataTables_Buttons', |
| 639 |
'incompatible_classes' => array( 'TablePress_DataTables_Buttons' ), |
| 640 |
'minimum_plan' => 'pro', |
| 641 |
'default_active' => true, |
| 642 |
), |
| 643 |
'datatables-columnfilterwidgets' => array( |
| 644 |
'name' => __( 'Column Filter Dropdowns', 'tablepress' ), |
| 645 |
'description' => __( 'Add a search dropdown for each column above the table.', 'tablepress' ), |
| 646 |
'category' => 'search-filter', |
| 647 |
'class' => 'TablePress_Module_DataTables_ColumnFilterWidgets', |
| 648 |
'incompatible_classes' => array(), |
| 649 |
'minimum_plan' => 'pro', |
| 650 |
'default_active' => true, |
| 651 |
), |
| 652 |
'datatables-column-filter' => array( |
| 653 |
'name' => __( 'Individual Column Filtering', 'tablepress' ), |
| 654 |
'description' => __( 'Add a search field for each column to the table head or foot row.', 'tablepress' ), |
| 655 |
'category' => 'search-filter', |
| 656 |
'class' => 'TablePress_Module_DataTables_Column_Filter', |
| 657 |
'incompatible_classes' => array(), |
| 658 |
'minimum_plan' => 'pro', |
| 659 |
'default_active' => false, |
| 660 |
), |
| 661 |
'datatables-counter-column' => array( |
| 662 |
'name' => __( 'Counter Column', 'tablepress' ), |
| 663 |
'description' => __( 'Make the first column an index or counter column with the row position.', 'tablepress' ), |
| 664 |
'category' => 'frontend', |
| 665 |
'class' => 'TablePress_Module_DataTables_Counter_Column', |
| 666 |
'incompatible_classes' => array(), |
| 667 |
'minimum_plan' => 'pro', |
| 668 |
'default_active' => false, |
| 669 |
), |
| 670 |
'datatables-fixedheader-fixedcolumns' => array( |
| 671 |
'name' => __( 'Fixed Rows and Columns', 'tablepress' ), |
| 672 |
'description' => __( 'Fix the header and footer row and the first and last column when scrolling the table.', 'tablepress' ), |
| 673 |
'category' => 'frontend', |
| 674 |
'class' => 'TablePress_Module_DataTables_FixedHeader_FixedColumns', |
| 675 |
'incompatible_classes' => array( |
| 676 |
'TablePress_DataTables_FixedHeader', |
| 677 |
'TablePress_DataTables_FixedColumns', |
| 678 |
), |
| 679 |
'minimum_plan' => 'pro', |
| 680 |
'default_active' => true, |
| 681 |
), |
| 682 |
'datatables-rowgroup' => array( |
| 683 |
'name' => __( 'Row Grouping', 'tablepress' ), |
| 684 |
'description' => __( 'Group table rows by a common keyword, category, or title.', 'tablepress' ), |
| 685 |
'category' => 'frontend', |
| 686 |
'class' => 'TablePress_Module_DataTables_RowGroup', |
| 687 |
'incompatible_classes' => array( 'TablePress_DataTables_RowGroup' ), |
| 688 |
'minimum_plan' => 'pro', |
| 689 |
'default_active' => false, |
| 690 |
), |
| 691 |
'datatables-searchbuilder' => array( |
| 692 |
'name' => __( 'Custom Search Builder', 'tablepress' ), |
| 693 |
'description' => __( 'Show a search builder interface for filtering from groups and using conditions.', 'tablepress' ), |
| 694 |
'category' => 'search-filter', |
| 695 |
'class' => 'TablePress_Module_DataTables_SearchBuilder', |
| 696 |
'incompatible_classes' => array(), |
| 697 |
'minimum_plan' => 'max', |
| 698 |
'default_active' => false, |
| 699 |
), |
| 700 |
'datatables-searchhighlight' => array( |
| 701 |
'name' => __( 'Search Highlighting', 'tablepress' ), |
| 702 |
'description' => __( 'Highlight found search terms in the table.', 'tablepress' ), |
| 703 |
'category' => 'search-filter', |
| 704 |
'class' => 'TablePress_Module_DataTables_SearchHighlight', |
| 705 |
'incompatible_classes' => array(), |
| 706 |
'minimum_plan' => 'pro', |
| 707 |
'default_active' => false, |
| 708 |
), |
| 709 |
'datatables-searchpanes' => array( |
| 710 |
'name' => __( 'Search Panes', 'tablepress' ), |
| 711 |
'description' => __( 'Show panes for filtering the columns.', 'tablepress' ), |
| 712 |
'category' => 'search-filter', |
| 713 |
'class' => 'TablePress_Module_DataTables_SearchPanes', |
| 714 |
'incompatible_classes' => array(), |
| 715 |
'minimum_plan' => 'pro', |
| 716 |
'default_active' => false, |
| 717 |
), |
| 718 |
'datatables-serverside-processing' => array( |
| 719 |
'name' => __( 'Server-side Processing', 'tablepress' ), |
| 720 |
'description' => __( 'Process sorting, filtering, and pagination on the server for faster loading of large tables.', 'tablepress' ), |
| 721 |
'category' => 'backend', |
| 722 |
'class' => 'TablePress_Module_DataTables_ServerSide_Processing', |
| 723 |
'incompatible_classes' => array(), |
| 724 |
'minimum_plan' => 'max', |
| 725 |
'default_active' => true, |
| 726 |
), |
| 727 |
'default-style-customizer' => array( |
| 728 |
'name' => __( 'Default Style Customizer', 'tablepress' ), |
| 729 |
'description' => __( 'Change the default styling of your tables in the visual style customizer.', 'tablepress' ), |
| 730 |
'category' => 'frontend', |
| 731 |
'class' => 'TablePress_Module_Default_Style_Customizer', |
| 732 |
'incompatible_classes' => array(), |
| 733 |
'minimum_plan' => 'pro', |
| 734 |
'default_active' => true, |
| 735 |
), |
| 736 |
'responsive-tables' => array( |
| 737 |
'name' => __( 'Responsive Tables', 'tablepress' ), |
| 738 |
'description' => __( 'Make your tables look good on different screen sizes.', 'tablepress' ), |
| 739 |
'category' => 'frontend', |
| 740 |
'class' => 'TablePress_Module_Responsive_Tables', |
| 741 |
'incompatible_classes' => array( 'TablePress_Responsive_Tables' ), |
| 742 |
'minimum_plan' => 'pro', |
| 743 |
'default_active' => true, |
| 744 |
), |
| 745 |
'rest-api' => array( |
| 746 |
'name' => __( 'REST API', 'tablepress' ), |
| 747 |
'description' => __( 'Read table data via the WordPress REST API, e.g. in external apps.', 'tablepress' ), |
| 748 |
'category' => 'backend', |
| 749 |
'class' => 'TablePress_Module_REST_API', |
| 750 |
'incompatible_classes' => array( 'TablePress_REST_API_Controller' ), |
| 751 |
'minimum_plan' => 'max', |
| 752 |
'default_active' => false, |
| 753 |
), |
| 754 |
'row-filtering' => array( |
| 755 |
'name' => __( 'Row Filtering', 'tablepress' ), |
| 756 |
'description' => __( 'Show only table rows that contain defined keywords.', 'tablepress' ), |
| 757 |
'category' => 'data-management', |
| 758 |
'class' => 'TablePress_Module_Row_Filtering', |
| 759 |
'incompatible_classes' => array( 'TablePress_Row_Filter' ), |
| 760 |
'minimum_plan' => 'pro', |
| 761 |
'default_active' => true, |
| 762 |
), |
| 763 |
'row-highlighting' => array( |
| 764 |
'name' => __( 'Row Highlighting', 'tablepress' ), |
| 765 |
'description' => __( 'Add CSS classes to rows for highlighting based on their content.', 'tablepress' ), |
| 766 |
'category' => 'frontend', |
| 767 |
'class' => 'TablePress_Module_Row_Highlighting', |
| 768 |
'incompatible_classes' => array( 'TablePress_Row_Highlighting' ), |
| 769 |
'minimum_plan' => 'pro', |
| 770 |
'default_active' => false, |
| 771 |
), |
| 772 |
'row-order' => array( |
| 773 |
'name' => __( 'Row Order', 'tablepress' ), |
| 774 |
'description' => __( 'Order the rows in different ways when a table is shown.', 'tablepress' ), |
| 775 |
'category' => 'data-management', |
| 776 |
'class' => 'TablePress_Module_Row_Order', |
| 777 |
'incompatible_classes' => array( 'TablePress_Row_Order' ), |
| 778 |
'minimum_plan' => 'pro', |
| 779 |
'default_active' => false, |
| 780 |
), |
| 781 |
); |
| 782 |
} |
| 783 |
|
| 784 |
} // class TablePress |
| 785 |
|