screen_columns ) { $screen->add_option( 'layout_columns', array( 'max' => $this->screen_columns ) ); } // Enable two column layout. add_filter( "get_user_option_screen_layout_{$screen->id}", array( $this, 'set_current_screen_layout_columns' ) ); $screen->add_help_tab( array( 'id' => 'tablepress-help', // This should be unique for the screen. 'title' => __( 'TablePress Help', 'tablepress' ), 'content' => '

' . $this->help_tab_content() . '

' . '

' . sprintf( __( 'More information about TablePress can be found on the plugin’s website or on its page in the WordPress Plugin Directory.', 'tablepress' ), 'https://tablepress.org/', 'https://wordpress.org/plugins/tablepress/' ) . ' ' . sprintf( __( 'For technical information, please see the documentation.', 'tablepress' ), 'https://tablepress.org/documentation/' ) . ' ' . sprintf( __( 'Support is provided through the WordPress Support Forums.', 'tablepress' ), 'https://tablepress.org/support/', 'https://wordpress.org/tags/tablepress' ) . ' ' . sprintf( __( 'Before asking for support, please carefully read the Frequently Asked Questions, where you will find answers to the most common questions, and search through the forums.', 'tablepress' ), 'https://tablepress.org/faq/' ) . '
' . sprintf( __( 'If you like the plugin, a donation is recommended.', 'tablepress' ), 'https://tablepress.org/donate/' ) . '

', ) ); // "sidebar" in the help tab. $screen->set_help_sidebar( '

' . __( 'For more information:', 'tablepress' ) . '

TablePress Website

TablePress FAQ

TablePress Documentation

TablePress Support

' ); } /** * Change the value of the user option "screen_layout_{$screen->id}" through a filter. * * @since 1.0.0 * * @param int|bool Current value of the user option. * @return int New value for the user option. */ public function set_current_screen_layout_columns( $result ) { if ( false === $result ) { // The user option does not yet exist. $result = $this->screen_columns; } elseif ( $result > $this->screen_columns ) { // The value of the user option is bigger than what is possible on this screen (e.g. because the number of columns was reduced in an update). $result = $this->screen_columns; } return $result; } /** * Set up the view with data and do things that are necessary for all views. * * @since 1.0.0 * * @param string $action Action for this view. * @param array $data Data for this view. */ public function setup( $action, array $data ) { $this->action = $action; $this->data = $data; // Set page title. $GLOBALS['title'] = sprintf( __( '%1$s ‹ %2$s', 'tablepress' ), $this->data['view_actions'][ $this->action ]['page_title'], 'TablePress' ); // Admin page helpers, like script/style loading, could be moved to view. $this->admin_page = TablePress::load_class( 'TablePress_Admin_Page', 'class-admin-page-helper.php', 'classes' ); $this->admin_page->enqueue_style( 'common' ); // RTL styles for the admin interface. if ( is_rtl() ) { $this->admin_page->enqueue_style( 'common-rtl', array( 'tablepress-common' ) ); } $this->admin_page->enqueue_script( 'common', array( 'jquery', 'postbox' ), array( 'common' => array( 'ays_delete_single_table' => _n( 'Do you really want to delete this table?', 'Do you really want to delete these tables?', 1, 'tablepress' ), 'ays_delete_multiple_tables' => _n( 'Do you really want to delete this table?', 'Do you really want to delete these tables?', 2, 'tablepress' ), ) ) ); $this->admin_page->add_admin_footer_text(); // Initialize WP feature pointers for TablePress. $this->_init_wp_pointers(); // Necessary fields for all views. $this->add_text_box( 'default_nonce_fields', array( $this, 'default_nonce_fields' ), 'header', false ); $this->add_text_box( 'action_nonce_field', array( $this, 'action_nonce_field' ), 'header', false ); $this->add_text_box( 'action_field', array( $this, 'action_field' ), 'header', false ); } /** * Register a header message for the view. * * @since 1.0.0 * * @param string $text Text for the header message. * @param string $class Optional. Additional CSS class for the header message. */ protected function add_header_message( $text, $class = 'notice-success' ) { if ( ! stripos( $class, 'not-dismissible' ) ) { $class .= ' is-dismissible'; } $this->header_messages[] = "

{$text}

\n"; } /** * Process header action messages, i.e. check if a message should be added to the page. * * @since 1.0.0 * * @param array $action_messages Action messages for the screen. */ protected function process_action_messages( array $action_messages ) { if ( $this->data['message'] && isset( $action_messages[ $this->data['message'] ] ) ) { $class = ( 'error' === substr( $this->data['message'], 0, 5 ) ) ? 'notice-error' : 'notice-success'; $this->add_header_message( "{$action_messages[ $this->data['message'] ]}", $class ); } } /** * Register a text box for the view. * * @since 1.0.0 * * @param string $id Unique HTML ID for the text box container (only visible with $wrap = true). * @param callback $callback Callback that prints the contents of the text box. * @param string $context Optional. Context/position of the text box (normal, side, additional, header, submit). * @param bool $ wrap Whether the content of the text box shall be wrapped in a
container. */ protected function add_text_box( $id, $callback, $context = 'normal', $wrap = false ) { if ( ! isset( $this->textboxes[ $context ] ) ) { $this->textboxes[ $context ] = array(); } $long_id = "tablepress_{$this->action}-{$id}"; $this->textboxes[ $context ][ $id ] = array( 'id' => $long_id, 'callback' => $callback, 'context' => $context, 'wrap' => $wrap, ); } /** * Register a post meta box for the view, that is drag/droppable with WordPress functionality. * * @since 1.0.0 * * @param string $id Unique ID for the meta box. * @param string $title Title for the meta box. * @param callback $callback Callback that prints the contents of the post meta box. * @param string $context Optional. Context/position of the post meta box (normal, side, additional). * @param string $priority Optional. Order of the post meta box for the $context position (high, default, low). * @param bool $callback_args Optional. Additional data for the callback function (e.g. useful when in different class). */ protected function add_meta_box( $id, $title, $callback, $context = 'normal', $priority = 'default', $callback_args = null ) { $this->has_meta_boxes = true; add_meta_box( "tablepress_{$this->action}-{$id}", $title, $callback, null, $context, $priority, $callback_args ); } /** * Render all text boxes for the given context. * * @since 1.0.0 * * @param string $context Context (normal, side, additional, header, submit) for which registered text boxes shall be rendered. */ protected function do_text_boxes( $context ) { if ( empty( $this->textboxes[ $context ] ) ) { return; } foreach ( $this->textboxes[ $context ] as $box ) { if ( $box['wrap'] ) { echo "
\n"; } call_user_func( $box['callback'], $this->data, $box ); if ( $box['wrap'] ) { echo "
\n"; } } } /** * Render all post meta boxes for the given context, if there are post meta boxes. * * @since 1.0.0 * * @param string $context Context (normal, side, additional) for which registered post meta boxes shall be rendered. */ protected function do_meta_boxes( $context ) { if ( ! $this->has_meta_boxes ) { return; } do_meta_boxes( null, $context, $this->data ); } /** * Print hidden fields with nonces for post meta box AJAX handling, if there are post meta boxes on the screen. * * The check is possible as this function is executed after post meta boxes have to be registered. * * @since 1.0.0 * * @param array $data Data for this screen. * @param array $box Information about the text box. */ protected function default_nonce_fields( array $data, array $box ) { if ( ! $this->has_meta_boxes ) { return; } wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); echo "\n"; wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); echo "\n"; } /** * Print hidden field with a nonce for the screen's action, to be transmitted in HTTP requests. * * @since 1.0.0 * * @param array $data Data for this screen. * @param array $box Information about the text box. */ protected function action_nonce_field( array $data, array $box ) { wp_nonce_field( TablePress::nonce( $this->action ) ); echo "\n"; } /** * Print hidden field with the screen action. * * @since 1.0.0 * * @param array $data Data for this screen. * @param array $box Information about the text box. */ protected function action_field( array $data, array $box ) { echo "action}\" />\n"; } /** * Render the current view. * * @since 1.0.0 */ public function render() { ?>
print_nav_tab_menu(); // Print all header messages. foreach ( $this->header_messages as $message ) { echo $message; } // "Import" screen has file upload. $enctype = ( 'import' === $this->action ) ? ' enctype="multipart/form-data"' : ''; ?>
> do_text_boxes( 'header' ); ?>
do_text_boxes( 'normal' ); $this->do_meta_boxes( 'normal' ); $this->do_text_boxes( 'additional' ); $this->do_meta_boxes( 'additional' ); // Print all submit buttons. $this->do_text_boxes( 'submit' ); ?>
do_text_boxes( 'side' ); $this->do_meta_boxes( 'side' ); ?>

wp_pointers ) ) { return; } // Get dismissed pointers. $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); $got_pointers = false; foreach ( array_diff( $this->wp_pointers, $dismissed ) as $pointer ) { // Bind pointer print function. add_action( "admin_footer-{$GLOBALS['hook_suffix']}", array( $this, 'wp_pointer_' . $pointer ) ); $got_pointers = true; } if ( ! $got_pointers ) { return; } // Add pointers script and style to queue. wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); } } // class TablePress_View