| @@ -26,33 +26,30 @@ | ||
| 26 | 26 | * |
| 27 | 27 | * @since 1.0.0 |
| 28 | 28 | * @var array<string, mixed> |
| 29 | 29 | */ |
| 30 | - protected $data = array(); | |
| 30 | + protected array $data = array(); | |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Number of screen columns for post boxes. |
| 34 | 34 | * |
| 35 | 35 | * @since 1.0.0 |
| 36 | - * @var int | |
| 37 | 36 | */ |
| 38 | - protected $screen_columns = 0; | |
| 37 | + protected int $screen_columns = 0; | |
| 39 | 38 | |
| 40 | 39 | /** |
| 41 | 40 | * User action for this screen. |
| 42 | 41 | * |
| 43 | 42 | * @since 1.0.0 |
| 44 | - * @var string | |
| 45 | 43 | */ |
| 46 | - protected $action = ''; | |
| 44 | + protected string $action = ''; | |
| 47 | 45 | |
| 48 | 46 | /** |
| 49 | 47 | * Instance of the Admin Page Helper Class, with necessary functions. |
| 50 | 48 | * |
| 51 | 49 | * @since 1.0.0 |
| 52 | - * @var TablePress_Admin_Page | |
| 53 | 50 | */ |
| 54 | - protected $admin_page; | |
| 51 | + protected \TablePress_Admin_Page $admin_page; | |
| 55 | 52 | |
| 56 | 53 | /** |
| 57 | 54 | * List of text boxes (similar to post boxes, but just with text and without extra functionality). |
| 58 | 55 | * |
| @@ -58,9 +55,9 @@ | ||
| 58 | 55 | * |
| 59 | 56 | * @since 1.0.0 |
| 60 | 57 | * @var array<string, array<string, array<string, mixed>>> |
| 61 | 58 | */ |
| 62 | - protected $textboxes = array(); | |
| 59 | + protected array $textboxes = array(); | |
| 63 | 60 | |
| 64 | 61 | /** |
| 65 | 62 | * List of messages that are to be displayed as boxes below the page title. |
| 66 | 63 | * |
| @@ -66,9 +63,9 @@ | ||
| 66 | 63 | * |
| 67 | 64 | * @since 1.0.0 |
| 68 | 65 | * @var string[] |
| 69 | 66 | */ |
| 70 | - protected $header_messages = array(); | |
| 67 | + protected array $header_messages = array(); | |
| 71 | 68 | |
| 72 | 69 | /** |
| 73 | 70 | * Whether there are post boxes registered for this screen, |
| 74 | 71 | * is automatically set to true, when a meta box is added. |
| @@ -73,11 +70,10 @@ | ||
| 73 | 70 | * Whether there are post boxes registered for this screen, |
| 74 | 71 | * is automatically set to true, when a meta box is added. |
| 75 | 72 | * |
| 76 | 73 | * @since 1.0.0 |
| 77 | - * @var bool | |
| 78 | 74 | */ |
| 79 | - protected $has_meta_boxes = false; | |
| 75 | + protected bool $has_meta_boxes = false; | |
| 80 | 76 | |
| 81 | 77 | /** |
| 82 | 78 | * List of WP feature pointers for this view. |
| 83 | 79 | * |
| @@ -83,12 +79,12 @@ | ||
| 83 | 79 | * |
| 84 | 80 | * @since 1.0.0 |
| 85 | 81 | * @var string[] |
| 86 | 82 | */ |
| 87 | - protected $wp_pointers = array(); | |
| 83 | + protected array $wp_pointers = array(); | |
| 88 | 84 | |
| 89 | 85 | /** |
| 90 | - * Initialize the View class, by setting the correct screen columns and adding help texts. | |
| 86 | + * Initializes the View class, by setting the correct screen columns and adding help texts. | |
| 91 | 87 | * |
| 92 | 88 | * @since 1.0.0 |
| 93 | 89 | */ |
| 94 | 90 | public function __construct() { |
| @@ -93,15 +89,19 @@ | ||
| 93 | 89 | */ |
| 94 | 90 | public function __construct() { |
| 95 | 91 | $screen = get_current_screen(); |
| 96 | 92 | if ( 0 !== $this->screen_columns ) { |
| 97 | - $screen->add_option( 'layout_columns', array( 'max' => $this->screen_columns ) ); | |
| 93 | + $screen->add_option( 'layout_columns', array( 'max' => $this->screen_columns ) ); // @phpstan-ignore method.nonObject | |
| 98 | 94 | } |
| 99 | 95 | // Enable two column layout. |
| 100 | - add_filter( "get_user_option_screen_layout_{$screen->id}", array( $this, 'set_current_screen_layout_columns' ) ); | |
| 96 | + add_filter( "get_user_option_screen_layout_{$screen->id}", array( $this, 'set_current_screen_layout_columns' ) ); // @phpstan-ignore property.nonObject | |
| 101 | 97 | |
| 98 | + /* translators: %1$s: URL to TablePress website, %2$s: URL to WordPress Plugin Directory */ | |
| 102 | 99 | $common_content = '<p>' . sprintf( __( 'More information about TablePress can be found on the <a href="%1$s">plugin website</a> or on its page in the <a href="%2$s">WordPress Plugin Directory</a>.', 'tablepress' ), 'https://tablepress.org/', 'https://wordpress.org/plugins/tablepress/' ) . '</p>'; |
| 103 | - $common_content .= '<p>' . sprintf( __( 'For technical information, please see the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' ) . ' ' . sprintf( __( 'Common questions are answered in the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' ) . '</p>'; | |
| 100 | + /* translators: %s: URL to Documentation page */ | |
| 101 | + $common_content .= '<p>' . sprintf( __( 'For technical information, please see the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' ) . ' '; | |
| 102 | + /* translators: %s: URL to FAQ page */ | |
| 103 | + $common_content .= sprintf( __( 'Common questions are answered in the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' ) . '</p>'; | |
| 104 | 104 | |
| 105 | 105 | if ( tb_tp_fs()->is_free_plan() ) { |
| 106 | 106 | $common_content .= '<p>' |
| 107 | 107 | . sprintf( __( '<a href="%1$s">Support</a> is provided through the <a href="%2$s">WordPress Support Forums</a>.', 'tablepress' ), 'https://tablepress.org/support/', 'https://wordpress.org/tags/tablepress' ) |
| @@ -110,15 +110,15 @@ | ||
| 110 | 110 | . '</p>'; |
| 111 | 111 | $common_content .= '<p><strong>' . sprintf( __( 'More great features for you and your site’s visitors and priority email support are available with a Premium license plan of TablePress. <a href="%s">Go check them out!</a>', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=help-tab' ) . '</strong></p>'; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $screen->add_help_tab( array( | |
| 114 | + $screen->add_help_tab( array( // @phpstan-ignore method.nonObject | |
| 115 | 115 | 'id' => 'tablepress-help', // This should be unique for the screen. |
| 116 | 116 | 'title' => __( 'TablePress Help', 'tablepress' ), |
| 117 | 117 | 'content' => '<p>' . $this->help_tab_content() . '</p>' . $common_content, |
| 118 | 118 | ) ); |
| 119 | 119 | // "Sidebar" in the help tab. |
| 120 | - $screen->set_help_sidebar( | |
| 120 | + $screen->set_help_sidebar( // @phpstan-ignore method.nonObject | |
| 121 | 121 | '<p><strong>' . __( 'For more information:', 'tablepress' ) . '</strong></p>' |
| 122 | 122 | . '<p><a href="https://tablepress.org/">TablePress Website</a></p>' |
| 123 | 123 | . '<p><a href="https://tablepress.org/faq/">TablePress FAQ</a></p>' |
| 124 | 124 | . '<p><a href="https://tablepress.org/documentation/">TablePress Documentation</a></p>' |
| @@ -126,9 +126,9 @@ | ||
| 126 | 126 | ); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | - * Change the value of the user option "screen_layout_{$screen->id}" through a filter. | |
| 130 | + * Changes the value of the user option "screen_layout_{$screen->id}" through a filter. | |
| 131 | 131 | * |
| 132 | 132 | * @since 1.0.0 |
| 133 | 133 | * |
| 134 | 134 | * @param int|false $result Current value of the user option. |
| @@ -145,9 +145,9 @@ | ||
| 145 | 145 | return $result; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
| 149 | - * Set up the view with data and do things that are necessary for all views. | |
| 149 | + * Sets up the view with data and do things that are necessary for all views. | |
| 150 | 150 | * |
| 151 | 151 | * @since 1.0.0 |
| 152 | 152 | * |
| 153 | 153 | * @param string $action Action for this view. |
| @@ -163,9 +163,9 @@ | ||
| 163 | 163 | $GLOBALS['title'] = sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $this->data['view_actions'][ $this->action ]['page_title'], 'TablePress' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 164 | 164 | |
| 165 | 165 | // Admin page helpers, like script/style loading, could be moved to view. |
| 166 | 166 | $this->admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' ); |
| 167 | - $this->admin_page->enqueue_style( 'common' ); | |
| 167 | + $this->admin_page->enqueue_style( 'common', array( 'wp-components' ) ); | |
| 168 | 168 | // RTL styles for the admin interface. |
| 169 | 169 | if ( is_rtl() ) { |
| 170 | 170 | $this->admin_page->enqueue_style( 'common-rtl', array( 'tablepress-common' ) ); |
| 171 | 171 | } |
| @@ -182,9 +182,9 @@ | ||
| 182 | 182 | $this->add_text_box( 'action_field', array( $this, 'action_field' ), 'header', false ); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Register a header message for the view. | |
| 186 | + * Registers a header message for the view. | |
| 187 | 187 | * |
| 188 | 188 | * @since 1.0.0 |
| 189 | 189 | * |
| 190 | 190 | * @param string $text Text for the header message. |
| @@ -190,9 +190,9 @@ | ||
| 190 | 190 | * @param string $text Text for the header message. |
| 191 | 191 | * @param string $css_class Optional. Additional CSS class for the header message. |
| 192 | 192 | * @param string $title Optional. Text for the header title. |
| 193 | 193 | */ |
| 194 | - protected function add_header_message( string $text, string $css_class = 'notice-success', string $title = '' ): void { | |
| 194 | + protected function add_header_message( string $text, string $css_class = 'is-success', string $title = '' ): void { | |
| 195 | 195 | if ( ! str_contains( $css_class, 'not-dismissible' ) ) { |
| 196 | 196 | $css_class .= ' is-dismissible'; |
| 197 | 197 | } |
| 198 | 198 | if ( '' !== $title ) { |
| @@ -201,13 +201,13 @@ | ||
| 201 | 201 | // Wrap the message text in HTML <p> tags if it does not already start with one (potentially with attributes), indicating custom message HTML. |
| 202 | 202 | if ( '' !== $text && ! str_starts_with( $text, '<p' ) ) { |
| 203 | 203 | $text = "<p>{$text}</p>"; |
| 204 | 204 | } |
| 205 | - $this->header_messages[] = "<div class=\"notice {$css_class}\">{$title}{$text}</div>\n"; | |
| 205 | + $this->header_messages[] = "<div class=\"notice components-notice {$css_class}\"><div class=\"components-notice__content\">{$title}{$text}</div></div>\n"; | |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
| 209 | - * Process header action messages, i.e. check if a message should be added to the page. | |
| 209 | + * Processes header action messages, i.e. check if a message should be added to the page. | |
| 210 | 210 | * |
| 211 | 211 | * @since 1.0.0 |
| 212 | 212 | * |
| 213 | 213 | * @param array<string, string> $action_messages Action messages for the screen. |
| @@ -213,9 +213,9 @@ | ||
| 213 | 213 | * @param array<string, string> $action_messages Action messages for the screen. |
| 214 | 214 | */ |
| 215 | 215 | protected function process_action_messages( array $action_messages ): void { |
| 216 | 216 | if ( $this->data['message'] && isset( $action_messages[ $this->data['message'] ] ) ) { |
| 217 | - $class = ( str_starts_with( $this->data['message'], 'error' ) ) ? 'notice-error' : 'notice-success'; | |
| 217 | + $class = ( str_starts_with( $this->data['message'], 'error' ) ) ? 'is-error' : 'is-success'; | |
| 218 | 218 | |
| 219 | 219 | if ( '' !== $this->data['error_details'] ) { |
| 220 | 220 | $this->data['error_details'] = '</p><p>' . sprintf( __( 'Error code: %s', 'tablepress' ), '<code>' . esc_html( $this->data['error_details'] ) . '</code>' ); |
| 221 | 221 | } |
| @@ -224,9 +224,9 @@ | ||
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
| 228 | - * Register a text box for the view. | |
| 228 | + * Registers a text box for the view. | |
| 229 | 229 | * |
| 230 | 230 | * @since 1.0.0 |
| 231 | 231 | * |
| 232 | 232 | * @param string $id Unique HTML ID for the text box container (only visible with $wrap = true). |
| @@ -248,9 +248,9 @@ | ||
| 248 | 248 | ); |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
| 252 | - * Register a post meta box for the view, that is drag/droppable with WordPress functionality. | |
| 252 | + * Registers a post meta box for the view, that is drag/droppable with WordPress functionality. | |
| 253 | 253 | * |
| 254 | 254 | * @since 1.0.0 |
| 255 | 255 | * |
| 256 | 256 | * @param string $id Unique ID for the meta box. |
| @@ -265,9 +265,9 @@ | ||
| 265 | 265 | add_meta_box( "tablepress_{$this->action}-{$id}", $title, $callback, null, $context, $priority, $callback_args ); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
| 269 | - * Render all text boxes for the given context. | |
| 269 | + * Renders all text boxes for the given context. | |
| 270 | 270 | * |
| 271 | 271 | * @since 1.0.0 |
| 272 | 272 | * |
| 273 | 273 | * @param string $context Context (normal, side, additional, header, submit) for which registered text boxes shall be rendered. |
| @@ -288,9 +288,9 @@ | ||
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | - * Render all post meta boxes for the given context, if there are post meta boxes. | |
| 292 | + * Renders all post meta boxes for the given context, if there are post meta boxes. | |
| 293 | 293 | * |
| 294 | 294 | * @since 1.0.0 |
| 295 | 295 | * |
| 296 | 296 | * @param string $context Context (normal, side, additional) for which registered post meta boxes shall be rendered. |
| @@ -296,14 +296,14 @@ | ||
| 296 | 296 | * @param string $context Context (normal, side, additional) for which registered post meta boxes shall be rendered. |
| 297 | 297 | */ |
| 298 | 298 | protected function do_meta_boxes( string $context ): void { |
| 299 | 299 | if ( $this->has_meta_boxes ) { |
| 300 | - do_meta_boxes( get_current_screen(), $context, $this->data ); // @phpstan-ignore-line | |
| 300 | + do_meta_boxes( get_current_screen(), $context, $this->data ); // @phpstan-ignore argument.type | |
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | - * Print hidden fields with nonces for post meta box AJAX handling, if there are post meta boxes on the screen. | |
| 305 | + * Prints hidden fields with nonces for post meta box AJAX handling, if there are post meta boxes on the screen. | |
| 306 | 306 | * |
| 307 | 307 | * The check is possible as this function is executed after post meta boxes have to be registered. |
| 308 | 308 | * |
| 309 | 309 | * @since 1.0.0 |
| @@ -321,9 +321,9 @@ | ||
| 321 | 321 | echo "\n"; |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * Print hidden field with a nonce for the screen's action, to be transmitted in HTTP requests. | |
| 325 | + * Prints hidden field with a nonce for the screen's action, to be transmitted in HTTP requests. | |
| 326 | 326 | * |
| 327 | 327 | * @since 1.0.0 |
| 328 | 328 | * |
| 329 | 329 | * @param array<string, mixed> $data Data for this screen. |
| @@ -334,9 +334,9 @@ | ||
| 334 | 334 | echo "\n"; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
| 338 | - * Print hidden field with the screen action. | |
| 338 | + * Prints hidden field with the screen action. | |
| 339 | 339 | * |
| 340 | 340 | * @since 1.0.0 |
| 341 | 341 | * |
| 342 | 342 | * @param array<string, mixed> $data Data for this screen. |
| @@ -342,13 +342,13 @@ | ||
| 342 | 342 | * @param array<string, mixed> $data Data for this screen. |
| 343 | 343 | * @param array<string, mixed> $box Information about the text box. |
| 344 | 344 | */ |
| 345 | 345 | protected function action_field( array $data, array $box ): void { |
| 346 | - echo "<input type=\"hidden\" name=\"action\" value=\"tablepress_{$this->action}\" />\n"; | |
| 346 | + echo "<input type=\"hidden\" name=\"action\" value=\"tablepress_{$this->action}\">\n"; | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
| 350 | - * Render the current view. | |
| 350 | + * Renders the current view. | |
| 351 | 351 | * |
| 352 | 352 | * @since 1.0.0 |
| 353 | 353 | */ |
| 354 | 354 | public function render(): void { |
| @@ -357,9 +357,9 @@ | ||
| 357 | 357 | <?php |
| 358 | 358 | $this->print_nav_tab_menu(); |
| 359 | 359 | ?> |
| 360 | 360 | <div id="tablepress-body"> |
| 361 | - <hr class="wp-header-end" /> | |
| 361 | + <hr class="wp-header-end"> | |
| 362 | 362 | <?php |
| 363 | 363 | // Print all header messages. |
| 364 | 364 | foreach ( $this->header_messages as $message ) { |
| 365 | 365 | echo $message; |
| @@ -366,9 +366,9 @@ | ||
| 366 | 366 | } |
| 367 | 367 | // "Import" screen has file upload. |
| 368 | 368 | $enctype = ( 'import' === $this->action ) ? ' enctype="multipart/form-data"' : ''; |
| 369 | 369 | ?> |
| 370 | - <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"<?php echo $enctype; ?>> | |
| 370 | + <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"<?php echo $enctype; ?> id="tablepress-page-form"> | |
| 371 | 371 | <?php |
| 372 | 372 | $this->do_text_boxes( 'header' ); |
| 373 | 373 | $hide_if_no_js = ( in_array( $this->action, array( 'export', 'import' ), true ) ) ? ' class="hide-if-no-js"' : ''; |
| 374 | 374 | ?> |
| @@ -393,9 +393,9 @@ | ||
| 393 | 393 | $this->do_meta_boxes( 'side' ); |
| 394 | 394 | ?> |
| 395 | 395 | </div> |
| 396 | 396 | </div> |
| 397 | - <br class="clear" /> | |
| 397 | + <br class="clear"> | |
| 398 | 398 | </div> |
| 399 | 399 | </form> |
| 400 | 400 | </div> |
| 401 | 401 | </div> |
| @@ -402,32 +402,27 @@ | ||
| 402 | 402 | <?php |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
| 406 | - * Render the navigation menu with links to the possible actions, highlighting the current one. | |
| 406 | + * Renders the navigation menu with links to the possible actions, highlighting the current one. | |
| 407 | 407 | * |
| 408 | 408 | * @since 1.0.0 |
| 409 | 409 | */ |
| 410 | 410 | protected function print_nav_tab_menu(): void { |
| 411 | + $name = __( 'TablePress', 'tablepress' ); | |
| 412 | + $filename = 'admin/img/tablepress.svg'; | |
| 411 | 413 | ?> |
| 412 | 414 | <div id="tablepress-header" class="header"> |
| 413 | - <h1 class="name"><img src="<?php echo plugins_url( 'admin/img/tablepress-icon.png', TABLEPRESS__FILE__ ); ?>" class="tablepress-icon" alt="<?php esc_attr_e( 'TablePress plugin logo', 'tablepress' ); ?>" /><?php _e( 'TablePress', 'tablepress' ); ?></h1> | |
| 414 | - <?php if ( tb_tp_fs()->is_free_plan() ) : ?> | |
| 415 | + <h1 class="name"> | |
| 416 | + <img src="<?php echo plugins_url( $filename, TABLEPRESS__FILE__ ); ?>" alt="<?php esc_attr_e( 'TablePress plugin logo', 'tablepress' ); ?>"> | |
| 417 | + <span class="screen-reader-text"><?php echo $name; ?></span> | |
| 418 | + </h1> | |
| 419 | + <?php if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) : ?> | |
| 415 | 420 | <div class="buttons"> |
| 416 | - <?php | |
| 417 | - $timestamp_today = strtotime( 'today' ); | |
| 418 | - if ( strtotime( '2023-11-19' ) < $timestamp_today && $timestamp_today < strtotime( '2023-11-28' ) ) : | |
| 419 | - ?> | |
| 420 | - <a href="https://tablepress.org/premium/?utm_campaign=black-week-2023&utm_source=plugin&utm_medium=button&utm_content=upgrade-button" class="tablepress-button" style="background:linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%);border-color:#ffffff;font-weight:bold;font-size:20px;border-radius:6px;"> | |
| 421 | - <span>Premium: 20% off during Black Week 2023!</span> | |
| 422 | - <span class="dashicons dashicons-arrow-right-alt" /> | |
| 423 | - </a> | |
| 424 | - <?php else : ?> | |
| 425 | - <a href="https://tablepress.org/premium/?utm_source=plugin&utm_medium=button&utm_content=upgrade-button" class="tablepress-button"> | |
| 421 | + <a href="<?php echo esc_url( tb_tp_fs()->pricing_url( WP_FS__PERIOD_ANNUALLY, false ) ); ?>" class="tablepress-button"> | |
| 426 | 422 | <span><?php _e( 'Upgrade to Premium', 'tablepress' ); ?></span> |
| 427 | - <span class="dashicons dashicons-arrow-right-alt" /> | |
| 423 | + <span class="dashicons dashicons-arrow-right-alt"></span> | |
| 428 | 424 | </a> |
| 429 | - <?php endif;?> | |
| 430 | 425 | </div> |
| 431 | 426 | <?php endif; ?> |
| 432 | 427 | </div> |
| 433 | 428 | <nav id="tablepress-nav"> |
| @@ -461,26 +456,30 @@ | ||
| 461 | 456 | * @param array<string, mixed> $box Information about the text box. |
| 462 | 457 | */ |
| 463 | 458 | public function textbox_no_javascript( array $data, array $box ): void { |
| 464 | 459 | ?> |
| 465 | - <div class="notice notice-error notice-alt notice-large hide-if-js"> | |
| 466 | - <h3><em> | |
| 467 | - <?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?> | |
| 468 | - </em></h3> | |
| 469 | - <p style="font-size:14px"> | |
| 470 | - <strong><?php _e( 'This screen requires JavaScript. Please enable JavaScript in your browser settings.', 'tablepress' ); ?></strong><br /> | |
| 471 | - <?php _e( 'For help, please follow <a href="https://www.enable-javascript.com/">the instructions on how to enable JavaScript in your browser</a>.', 'tablepress' ); ?> | |
| 472 | - </p> | |
| 473 | - <p> | |
| 474 | - <?php echo '<a href="' . TablePress::url( array( 'action' => 'list' ) ) . '">' . __( 'Back to the List of Tables', 'tablepress' ) . '</a>'; ?> | |
| 475 | - </p> | |
| 460 | + <div class="notice components-notice is-error hide-if-js"> | |
| 461 | + <div class="components-notice__content"> | |
| 462 | + <h3><em> | |
| 463 | + <?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?> | |
| 464 | + </em></h3> | |
| 465 | + <p style="font-size:14px"> | |
| 466 | + <strong><?php _e( 'This screen requires JavaScript. Please enable JavaScript in your browser settings.', 'tablepress' ); ?></strong><br> | |
| 467 | + <?php _e( 'For help, please follow <a href="https://www.enable-javascript.com/">the instructions on how to enable JavaScript in your browser</a>.', 'tablepress' ); ?> | |
| 468 | + </p> | |
| 469 | + <p> | |
| 470 | + <?php echo '<a href="' . esc_url( TablePress::url( array( 'action' => 'list' ) ) ) . '">' . __( 'Back to the List of Tables', 'tablepress' ) . '</a>'; ?> | |
| 471 | + </p> | |
| 472 | + </div> | |
| 476 | 473 | </div> |
| 477 | 474 | <?php |
| 478 | 475 | } |
| 479 | 476 | |
| 480 | 477 | /** |
| 481 | - * Print a submit button (only done when function is used as a callback for a text box). | |
| 478 | + * Prints a submit button (only done when function is used as a callback for a text box). | |
| 482 | 479 | * |
| 480 | + * This method is soft-deprecated. It's no longer used in TablePress, but e.g. in the "TablePress Debug Extension". | |
| 481 | + * | |
| 483 | 482 | * @since 1.0.0 |
| 484 | 483 | * |
| 485 | 484 | * @param array<string, mixed> $data Data for this screen. |
| 486 | 485 | * @param array<string, mixed> $box Information about the text box. |
| @@ -485,17 +484,55 @@ | ||
| 485 | 484 | * @param array<string, mixed> $data Data for this screen. |
| 486 | 485 | * @param array<string, mixed> $box Information about the text box. |
| 487 | 486 | */ |
| 488 | 487 | protected function textbox_submit_button( array $data, array $box ): void { |
| 489 | - $caption = $data['submit_button_caption'] ?? __( 'Save Changes', 'tablepress' ); | |
| 490 | 488 | ?> |
| 491 | - <p class="submit"><input type="submit" value="<?php echo esc_attr( $caption ); ?>" class="button button-primary button-large" /></p> | |
| 489 | + <p class="submit"><input type="submit" class="components-button is-primary button-save-changes" value="<?php esc_attr_e( 'Save Changes', 'tablepress' ); ?>"></p> | |
| 492 | 490 | <?php |
| 493 | 491 | } |
| 494 | 492 | |
| 495 | 493 | /** |
| 496 | - * Return the content for the help tab for this screen. | |
| 494 | + * Returns a safe JSON representation of a variable for printing inside of JavaScript code. | |
| 497 | 495 | * |
| 496 | + * @since 2.0.0 | |
| 497 | + * | |
| 498 | + * @param mixed $data Variable to convert to JSON. | |
| 499 | + * @return string Safe JSON representation of a variable for printing inside of JavaScript code. | |
| 500 | + */ | |
| 501 | + public function convert_to_json_parse_output( /* string|array|bool|int|float|null */ $data ): string { | |
| 502 | + $json = wp_json_encode( $data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); | |
| 503 | + if ( false === $json ) { | |
| 504 | + // JSON encoding failed, return an error object. Use a prefixed "_error" key to avoid conflicts with intentionally added "error" keys. | |
| 505 | + $json = '{ "_error": "The data could not be encoded to JSON!" }'; | |
| 506 | + } | |
| 507 | + // Print the JSON data inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `\` and `'`. | |
| 508 | + $json = str_replace( array( '\\', "'" ), array( '\\\\', "\'" ), $json ); | |
| 509 | + return "JSON.parse( '{$json}' )"; | |
| 510 | + } | |
| 511 | + | |
| 512 | + /** | |
| 513 | + * Prints JavaScript variables for the screen. | |
| 514 | + * | |
| 515 | + * @since 3.1.0 | |
| 516 | + * | |
| 517 | + * @param string $variable Name of the JavaScript variable. | |
| 518 | + * @param array<string, mixed> $data Information about the text box. | |
| 519 | + */ | |
| 520 | + protected function print_script_data_json( string $variable, array $data ): void { | |
| 521 | + echo "<script>\n"; | |
| 522 | + echo "window.tp = window.tp || {};\n"; | |
| 523 | + echo "tp.{$variable} = {\n"; | |
| 524 | + foreach ( $data as $key => $value ) { | |
| 525 | + $value = $this->convert_to_json_parse_output( $value ); | |
| 526 | + echo "\t{$key}: {$value},\n"; | |
| 527 | + } | |
| 528 | + echo "};\n"; | |
| 529 | + echo "</script>\n"; | |
| 530 | + } | |
| 531 | + | |
| 532 | + /** | |
| 533 | + * Returns the content for the help tab for this screen. | |
| 534 | + * | |
| 498 | 535 | * Has to be implemented for every view that is visible in the WP Dashboard! |
| 499 | 536 | * |
| 500 | 537 | * @since 1.0.0 |
| 501 | 538 | * |
| @@ -506,9 +543,9 @@ | ||
| 506 | 543 | return ''; |
| 507 | 544 | } |
| 508 | 545 | |
| 509 | 546 | /** |
| 510 | - * Initialize the WP feature pointers for TablePress. | |
| 547 | + * Initializes the WP feature pointers for TablePress. | |
| 511 | 548 | * |
| 512 | 549 | * @since 1.0.0 |
| 513 | 550 | */ |
| 514 | 551 | protected function _init_wp_pointers(): void { |
| @@ -522,9 +559,9 @@ | ||
| 522 | 559 | |
| 523 | 560 | $pointers_on_page = false; |
| 524 | 561 | foreach ( array_diff( $this->wp_pointers, $dismissed ) as $pointer ) { |
| 525 | 562 | // Bind pointer print function. |
| 526 | - add_action( "admin_footer-{$GLOBALS['hook_suffix']}", array( $this, 'wp_pointer_' . $pointer ) ); // @phpstan-ignore-line | |
| 563 | + add_action( "admin_footer-{$GLOBALS['hook_suffix']}", array( $this, 'wp_pointer_' . $pointer ) ); // @phpstan-ignore argument.type | |
| 527 | 564 | $pointers_on_page = true; |
| 528 | 565 | } |
| 529 | 566 | |
| 530 | 567 | if ( $pointers_on_page ) { |