PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
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-view.php +56 -163 trunk3.0 View file →
@@ -43,8 +43,15 @@
43 43 */
44 44 protected string $action = '';
45 45
46 46 /**
47 + * Instance of the Admin Page Helper Class, with necessary functions.
48 + *
49 + * @since 1.0.0
50 + */
51 + protected \TablePress_Admin_Page $admin_page;
52 +
53 + /**
47 54 * List of text boxes (similar to post boxes, but just with text and without extra functionality).
48 55 *
49 56 * @since 1.0.0
50 57 * @var array<string, array<string, array<string, mixed>>>
@@ -75,9 +82,9 @@
75 82 */
76 83 protected array $wp_pointers = array();
77 84
78 85 /**
79 - * Initializes the View class, by setting the correct screen columns and adding help texts.
86 + * Initialize the View class, by setting the correct screen columns and adding help texts.
80 87 *
81 88 * @since 1.0.0
82 89 */
83 90 public function __construct() {
@@ -87,18 +94,14 @@
87 94 }
88 95 // Enable two column layout.
89 96 add_filter( "get_user_option_screen_layout_{$screen->id}", array( $this, 'set_current_screen_layout_columns' ) ); // @phpstan-ignore property.nonObject
90 97
91 - /* translators: %1$s: URL to TablePress website, %2$s: URL to WordPress Plugin Directory */
92 98 $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>';
93 - /* translators: %s: URL to Documentation page */
94 - $common_content .= '<p>' . sprintf( __( 'For technical information, please see the <a href="%s">Documentation</a>.', 'tablepress' ), 'https://tablepress.org/documentation/' ) . ' ';
95 - /* translators: %s: URL to FAQ page */
96 - $common_content .= sprintf( __( 'Common questions are answered in the <a href="%s">FAQ</a>.', 'tablepress' ), 'https://tablepress.org/faq/' ) . '</p>';
99 + $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>';
97 100
98 101 if ( tb_tp_fs()->is_free_plan() ) {
99 102 $common_content .= '<p>'
100 - . 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/support/plugin/tablepress' )
103 + . 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' )
101 104 . ' '
102 105 . sprintf( __( 'Before asking for support, please carefully read the <a href="%s">Frequently Asked Questions</a>, where you will find answers to the most common questions, and search through the forums.', 'tablepress' ), 'https://tablepress.org/faq/' )
103 106 . '</p>';
104 107 $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>';
@@ -119,9 +122,9 @@
119 122 );
120 123 }
121 124
122 125 /**
123 - * Changes the value of the user option "screen_layout_{$screen->id}" through a filter.
126 + * Change the value of the user option "screen_layout_{$screen->id}" through a filter.
124 127 *
125 128 * @since 1.0.0
126 129 *
127 130 * @param int|false $result Current value of the user option.
@@ -138,9 +141,9 @@
138 141 return $result;
139 142 }
140 143
141 144 /**
142 - * Sets up the view with data and do things that are necessary for all views.
145 + * Set up the view with data and do things that are necessary for all views.
143 146 *
144 147 * @since 1.0.0
145 148 *
146 149 * @param string $action Action for this view.
@@ -154,16 +157,19 @@
154 157
155 158 // Set page title.
156 159 $GLOBALS['title'] = sprintf( __( '%1$s &lsaquo; %2$s', 'tablepress' ), $this->data['view_actions'][ $this->action ]['page_title'], 'TablePress' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
157 160
158 - add_filter( 'admin_footer_text', array( $this, 'add_admin_footer_text' ) );
159 -
160 - TablePress::enqueue_style( 'common', array( 'wp-components' ) );
161 + // Admin page helpers, like script/style loading, could be moved to view.
162 + $this->admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' );
163 + $this->admin_page->enqueue_style( 'common', array( 'wp-components' ) );
161 164 // RTL styles for the admin interface.
162 165 if ( is_rtl() ) {
163 - TablePress::enqueue_style( 'common-rtl', array( 'tablepress-common' ) );
166 + $this->admin_page->enqueue_style( 'common-rtl', array( 'tablepress-common' ) );
164 167 }
168 + $this->admin_page->enqueue_script( 'common', array( 'jquery-core', 'postbox' ) );
165 169
170 + $this->admin_page->add_admin_footer_text();
171 +
166 172 // Initialize WP feature pointers for TablePress.
167 173 $this->_init_wp_pointers();
168 174
169 175 // Necessary fields for all views.
@@ -172,9 +178,9 @@
172 178 $this->add_text_box( 'action_field', array( $this, 'action_field' ), 'header', false );
173 179 }
174 180
175 181 /**
176 - * Registers a header message for the view.
182 + * Register a header message for the view.
177 183 *
178 184 * @since 1.0.0
179 185 *
180 186 * @param string $text Text for the header message.
@@ -180,9 +186,9 @@
180 186 * @param string $text Text for the header message.
181 187 * @param string $css_class Optional. Additional CSS class for the header message.
182 188 * @param string $title Optional. Text for the header title.
183 189 */
184 - protected function add_header_message( string $text, string $css_class = 'is-success', string $title = '' ): void {
190 + protected function add_header_message( string $text, string $css_class = 'notice-success', string $title = '' ): void {
185 191 if ( ! str_contains( $css_class, 'not-dismissible' ) ) {
186 192 $css_class .= ' is-dismissible';
187 193 }
188 194 if ( '' !== $title ) {
@@ -191,13 +197,13 @@
191 197 // Wrap the message text in HTML <p> tags if it does not already start with one (potentially with attributes), indicating custom message HTML.
192 198 if ( '' !== $text && ! str_starts_with( $text, '<p' ) ) {
193 199 $text = "<p>{$text}</p>";
194 200 }
195 - $this->header_messages[] = "<div class=\"notice components-notice {$css_class}\"><div class=\"components-notice__content\">{$title}{$text}</div></div>\n";
201 + $this->header_messages[] = "<div class=\"notice {$css_class}\">{$title}{$text}</div>\n";
196 202 }
197 203
198 204 /**
199 - * Processes header action messages, i.e. check if a message should be added to the page.
205 + * Process header action messages, i.e. check if a message should be added to the page.
200 206 *
201 207 * @since 1.0.0
202 208 *
203 209 * @param array<string, string> $action_messages Action messages for the screen.
@@ -203,9 +209,9 @@
203 209 * @param array<string, string> $action_messages Action messages for the screen.
204 210 */
205 211 protected function process_action_messages( array $action_messages ): void {
206 212 if ( $this->data['message'] && isset( $action_messages[ $this->data['message'] ] ) ) {
207 - $class = ( str_starts_with( $this->data['message'], 'error' ) ) ? 'is-error' : 'is-success';
213 + $class = ( str_starts_with( $this->data['message'], 'error' ) ) ? 'notice-error' : 'notice-success';
208 214
209 215 if ( '' !== $this->data['error_details'] ) {
210 216 $this->data['error_details'] = '</p><p>' . sprintf( __( 'Error code: %s', 'tablepress' ), '<code>' . esc_html( $this->data['error_details'] ) . '</code>' );
211 217 }
@@ -214,9 +220,9 @@
214 220 }
215 221 }
216 222
217 223 /**
218 - * Registers a text box for the view.
224 + * Register a text box for the view.
219 225 *
220 226 * @since 1.0.0
221 227 *
222 228 * @param string $id Unique HTML ID for the text box container (only visible with $wrap = true).
@@ -238,9 +244,9 @@
238 244 );
239 245 }
240 246
241 247 /**
242 - * Registers a post meta box for the view, that is drag/droppable with WordPress functionality.
248 + * Register a post meta box for the view, that is drag/droppable with WordPress functionality.
243 249 *
244 250 * @since 1.0.0
245 251 *
246 252 * @param string $id Unique ID for the meta box.
@@ -255,9 +261,9 @@
255 261 add_meta_box( "tablepress_{$this->action}-{$id}", $title, $callback, null, $context, $priority, $callback_args );
256 262 }
257 263
258 264 /**
259 - * Renders all text boxes for the given context.
265 + * Render all text boxes for the given context.
260 266 *
261 267 * @since 1.0.0
262 268 *
263 269 * @param string $context Context (normal, side, additional, header, submit) for which registered text boxes shall be rendered.
@@ -278,9 +284,9 @@
278 284 }
279 285 }
280 286
281 287 /**
282 - * Renders all post meta boxes for the given context, if there are post meta boxes.
288 + * Render all post meta boxes for the given context, if there are post meta boxes.
283 289 *
284 290 * @since 1.0.0
285 291 *
286 292 * @param string $context Context (normal, side, additional) for which registered post meta boxes shall be rendered.
@@ -291,9 +297,9 @@
291 297 }
292 298 }
293 299
294 300 /**
295 - * Prints hidden fields with nonces for post meta box AJAX handling, if there are post meta boxes on the screen.
301 + * Print hidden fields with nonces for post meta box AJAX handling, if there are post meta boxes on the screen.
296 302 *
297 303 * The check is possible as this function is executed after post meta boxes have to be registered.
298 304 *
299 305 * @since 1.0.0
@@ -311,9 +317,9 @@
311 317 echo "\n";
312 318 }
313 319
314 320 /**
315 - * Prints hidden field with a nonce for the screen's action, to be transmitted in HTTP requests.
321 + * Print hidden field with a nonce for the screen's action, to be transmitted in HTTP requests.
316 322 *
317 323 * @since 1.0.0
318 324 *
319 325 * @param array<string, mixed> $data Data for this screen.
@@ -324,9 +330,9 @@
324 330 echo "\n";
325 331 }
326 332
327 333 /**
328 - * Prints hidden field with the screen action.
334 + * Print hidden field with the screen action.
329 335 *
330 336 * @since 1.0.0
331 337 *
332 338 * @param array<string, mixed> $data Data for this screen.
@@ -336,9 +342,9 @@
336 342 echo "<input type=\"hidden\" name=\"action\" value=\"tablepress_{$this->action}\">\n";
337 343 }
338 344
339 345 /**
340 - * Renders the current view.
346 + * Render the current view.
341 347 *
342 348 * @since 1.0.0
343 349 */
344 350 public function render(): void {
@@ -392,9 +398,9 @@
392 398 <?php
393 399 }
394 400
395 401 /**
396 - * Renders the navigation menu with links to the possible actions, highlighting the current one.
402 + * Render the navigation menu with links to the possible actions, highlighting the current one.
397 403 *
398 404 * @since 1.0.0
399 405 */
400 406 protected function print_nav_tab_menu(): void {
@@ -407,12 +413,22 @@
407 413 <span class="screen-reader-text"><?php echo $name; ?></span>
408 414 </h1>
409 415 <?php if ( ! TABLEPRESS_IS_PLAYGROUND_PREVIEW && tb_tp_fs()->is_free_plan() ) : ?>
410 416 <div class="buttons">
417 + <?php
418 + $timestamp_today = strtotime( 'today' );
419 + if ( strtotime( '2024-11-24' ) < $timestamp_today && $timestamp_today < strtotime( '2024-12-03' ) ) :
420 + ?>
421 + <a href="https://tablepress.org/premium/?utm_campaign=black-week-2024&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;">
422 + <span>Premium: 20% off during Black Week 2024!</span>
423 + <span class="dashicons dashicons-arrow-right-alt" />
424 + </a>
425 + <?php else : ?>
411 426 <a href="<?php echo esc_url( tb_tp_fs()->pricing_url( WP_FS__PERIOD_ANNUALLY, false ) ); ?>" class="tablepress-button">
412 427 <span><?php _e( 'Upgrade to Premium', 'tablepress' ); ?></span>
413 428 <span class="dashicons dashicons-arrow-right-alt"></span>
414 429 </a>
430 + <?php endif; ?>
415 431 </div>
416 432 <?php endif; ?>
417 433 </div>
418 434 <nav id="tablepress-nav">
@@ -446,21 +462,19 @@
446 462 * @param array<string, mixed> $box Information about the text box.
447 463 */
448 464 public function textbox_no_javascript( array $data, array $box ): void {
449 465 ?>
450 - <div class="notice components-notice is-error hide-if-js">
451 - <div class="components-notice__content">
452 - <h3><em>
453 - <?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?>
454 - </em></h3>
455 - <p style="font-size:14px">
456 - <strong><?php _e( 'This screen requires JavaScript. Please enable JavaScript in your browser settings.', 'tablepress' ); ?></strong><br>
457 - <?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' ); ?>
458 - </p>
459 - <p>
460 - <?php echo '<a href="' . esc_url( TablePress::url( array( 'action' => 'list' ) ) ) . '">' . __( 'Back to the List of Tables', 'tablepress' ) . '</a>'; ?>
461 - </p>
462 - </div>
466 + <div class="notice notice-error notice-alt notice-large hide-if-js">
467 + <h3><em>
468 + <?php _e( 'Attention: Unfortunately, there is a problem!', 'tablepress' ); ?>
469 + </em></h3>
470 + <p style="font-size:14px">
471 + <strong><?php _e( 'This screen requires JavaScript. Please enable JavaScript in your browser settings.', 'tablepress' ); ?></strong><br>
472 + <?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' ); ?>
473 + </p>
474 + <p>
475 + <?php echo '<a href="' . esc_url( TablePress::url( array( 'action' => 'list' ) ) ) . '">' . __( 'Back to the List of Tables', 'tablepress' ) . '</a>'; ?>
476 + </p>
463 477 </div>
464 478 <?php
465 479 }
466 480
@@ -480,49 +494,10 @@
480 494 <?php
481 495 }
482 496
483 497 /**
484 - * Returns a safe JSON representation of a variable for printing inside of JavaScript code.
498 + * Return the content for the help tab for this screen.
485 499 *
486 - * @since 2.0.0
487 - *
488 - * @param mixed $data Variable to convert to JSON.
489 - * @return string Safe JSON representation of a variable for printing inside of JavaScript code.
490 - */
491 - public function convert_to_json_parse_output( /* string|array|bool|int|float|null */ $data ): string {
492 - $json = wp_json_encode( $data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES );
493 - if ( false === $json ) {
494 - // JSON encoding failed, return an error object. Use a prefixed "_error" key to avoid conflicts with intentionally added "error" keys.
495 - $json = '{ "_error": "The data could not be encoded to JSON!" }';
496 - }
497 - // Print the JSON data inside a `JSON.parse()` call in JS for speed gains, with necessary escaping of `\` and `'`.
498 - $json = str_replace( array( '\\', "'" ), array( '\\\\', "\'" ), $json );
499 - return "JSON.parse( '{$json}' )";
500 - }
501 -
502 - /**
503 - * Prints JavaScript variables for the screen.
504 - *
505 - * @since 3.1.0
506 - *
507 - * @param string $variable Name of the JavaScript variable.
508 - * @param array<string, mixed> $data Information about the text box.
509 - */
510 - protected function print_script_data_json( string $variable, array $data ): void {
511 - echo "<script>\n";
512 - echo "window.tp = window.tp || {};\n";
513 - echo "tp.{$variable} = {\n";
514 - foreach ( $data as $key => $value ) {
515 - $value = $this->convert_to_json_parse_output( $value );
516 - echo "\t{$key}: {$value},\n";
517 - }
518 - echo "};\n";
519 - echo "</script>\n";
520 - }
521 -
522 - /**
523 - * Returns the content for the help tab for this screen.
524 - *
525 500 * Has to be implemented for every view that is visible in the WP Dashboard!
526 501 *
527 502 * @since 1.0.0
528 503 *
@@ -533,38 +508,12 @@
533 508 return '';
534 509 }
535 510
536 511 /**
537 - * Adds a TablePress "Thank You" message to the admin footer content.
512 + * Initialize the WP feature pointers for TablePress.
538 513 *
539 514 * @since 1.0.0
540 - * @since 3.3.0 This method was moved from the now-removed `TablePress_Admin_Page` class.
541 - *
542 - * @param string $content Current admin footer content.
543 - * @return string New admin footer content.
544 515 */
545 - public function add_admin_footer_text( /* string */ $content ): string {
546 - // Don't use a type hint in the method declaration as many WordPress plugins use the `admin_footer_text` filter without returning a string.
547 -
548 - // Protect against other plugins not returning a string in their filter callbacks.
549 - if ( ! is_string( $content ) ) { // @phpstan-ignore function.alreadyNarrowedType (The `is_string()` check is needed as the input is coming from a filter hook.)
550 - $content = '';
551 - }
552 -
553 - /* translators: %s: URL to TablePress website */
554 - $content .= ' &bull; ' . sprintf( __( 'Thank you for using <a href="%s">TablePress</a>.', 'tablepress' ), 'https://tablepress.org/' );
555 - if ( tb_tp_fs()->is_free_plan() ) {
556 - /* translators: %s: URL to TablePress premium features */
557 - $content .= ' ' . sprintf( __( 'Take a look at the <a href="%s">Premium features</a>!', 'tablepress' ), 'https://tablepress.org/premium/?utm_source=plugin&utm_medium=textlink&utm_content=admin-footer' );
558 - }
559 - return $content;
560 - }
561 -
562 - /**
563 - * Initializes the WP feature pointers for TablePress.
564 - *
565 - * @since 1.0.0
566 - */
567 516 protected function _init_wp_pointers(): void {
568 517 // Check if there are WP pointers for this view.
569 518 if ( empty( $this->wp_pointers ) ) {
570 519 return;
@@ -583,63 +532,7 @@
583 532 if ( $pointers_on_page ) {
584 533 wp_enqueue_style( 'wp-pointer' );
585 534 wp_enqueue_script( 'wp-pointer' );
586 535 }
587 - }
588 -
589 - /**
590 - * Prints the JavaScript code for a WP feature pointer.
591 - *
592 - * @since 1.0.0
593 - * @since 3.3.0 This method was moved from the now-removed `TablePress_Admin_Page` class.
594 - *
595 - * @param string $pointer_id The pointer ID.
596 - * @param string $selector The HTML elements, on which the pointer should be attached.
597 - * @param array<string, mixed> $args Arguments to be passed to the pointer JS (see wp-pointer.js).
598 - */
599 - public function print_wp_pointer_js( string $pointer_id, string $selector, array $args ): void {
600 - if ( empty( $pointer_id ) || empty( $selector ) || empty( $args['content'] ) ) {
601 - return;
602 - }
603 -
604 - $keyboard_shortcut = '';
605 - if ( 'tp33_edit_quick_navigation' === $pointer_id ) {
606 - $keyboard_shortcut = <<<JS
607 - content: options.content.replace( /%metaKey%/g, window?.navigator?.platform?.includes( 'Mac' ) ? wp.i18n._x( '⌘', 'keyboard shortcut modifier key on a Mac keyboard', 'tablepress' ) : wp.i18n._x( 'Ctrl+', 'keyboard shortcut modifier key on a non-Mac keyboard', 'tablepress' ) ),\n
608 - JS;
609 - }
610 -
611 - /*
612 - * Print JS code for the feature pointers, extended with event handling for opened/closed "Screen Options", so that pointers can
613 - * be repositioned. 210 ms is slightly slower than jQuery's "fast" value, to allow all elements to reach their original position.
614 - */
615 - ?>
616 -<script>
617 -( ( $ ) => {
618 - let options = <?php echo wp_json_encode( $args, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;
619 - if ( ! options ) {
620 - return;
621 - }
622 -
623 - options = {
624 - ...options,
625 - <?php echo $keyboard_shortcut; ?>
626 - close() {
627 - $.post( ajaxurl, {
628 - pointer: '<?php echo $pointer_id; ?>',
629 - action: 'dismiss-wp-pointer'
630 - } );
631 - $( this ).pointer( { 'disabled': true } );
632 - },
633 - };
634 -
635 - $( () => $( '<?php echo $selector; ?>' ).pointer( options ).pointer( 'open' ) );
636 -
637 - $( document ).on( 'screen:options:open screen:options:close', () => {
638 - setTimeout( () => $( '<?php echo $selector; ?>' ).pointer( 'reposition' ), 210 );
639 - } );
640 -} )( jQuery );
641 -</script>
642 - <?php
643 536 }
644 537
645 538 } // class TablePress_View